class Cryptoprocessing::CLI

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/cryptoprocessing/cli.rb, line 12
def initialize(*args)
  super
  config = {}
  config[:api_endpoint] = options[:api_endpoint] if options[:api_endpoint]
  config[:api_namespace] = options[:api_namespace] if options[:api_namespace]
  config[:access_token] = options[:access_token] if options[:access_token]

  @client = Cryptoprocessing::Client.new(config)
end

Public Instance Methods

account(account_id, currency = nil) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 54
def account(account_id, currency = nil)
  output = []
  response = @client.account(account_id,{:currency => currency})
  output << "Account #{account_id} info:"
  output << JSON.pretty_generate(response['data'])
  output = output.join("\n")
  puts output
end
address(account_id, address) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 92
def address(account_id, address)
  output = []
  response = @client.address(account_id, address)
  output << "Address #{address} for account #{account_id} info:"
  output << JSON.pretty_generate(response)
  output = output.join("\n")
  puts output
end
addresses(account_id) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 75
def addresses(account_id)
  output = []
  response = @client.addresses(account_id)
  if response.kind_of?(Array) and response.length == 0
    output << "No addresses for account #{account_id}."
  elsif response['addresses'].kind_of?(Array) && response['transactions'].length > 0
    output << "Addresses for account #{account_id}:"
    output << JSON.pretty_generate(response)
  else
    output << "No addresses for account #{account_id}."
  end
  output = output.join("\n")
  puts output
end
callbacks(account_id) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 165
def callbacks(account_id)
  output = []
  response = @client.callbacks(account_id)
  output << response['message']
  output = output.join("\n")
  puts output
end
create_account(currency, name) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 44
def create_account(currency, name)
  output = []
  response = @client.create_account({:currency => currency, :name => name})
  output << "Account with ID #{response['account_id']} created."
  output = output.join("\n")
  puts output
end
create_address(account_id, name = nil) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 65
def create_address(account_id, name = nil)
  output = []
  response = @client.create_address(account_id, {:name => name})
  output << "Address with ID #{response['id']} created."
  output = output.join("\n")
  puts output
end
create_callback(account_id, address) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 175
def create_callback(account_id, address)
  output = []
  response = @client.create_callback(account_id, address)
  output << response['message']
  output = output.join("\n")
  puts output
end
create_tracker(account_id, address) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 195
def create_tracker(account_id, address)
  output = []
  response = @client.create_tracker(account_id, address)
  output << response['message']
  output = output.join("\n")
  puts output
end
create_transaction(account_id, from_address, to_address, amount, description = nil, idem = nil) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 150
def create_transaction(account_id, from_address, to_address, amount, description = nil, idem = nil)
  output = []
  response = @client.create_transaction(account_id, {
      :from => [from_address],
      :to => [{:amount => amount, :address => to_address}],
      :description => description,
      :idem => idem
  })
  output << response['message']
  output = output.join("\n")
  puts output
end
login(email, password) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 34
def login(email, password)
  output = []
  response = @client.login({:email => email, :password => password})
  output << response['message']
  output = output.join("\n")
  puts output
end
register(email, password) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 24
def register(email, password)
  output = []
  response = @client.register({:email => email, :password => password})
  output << response['message']
  output = output.join("\n")
  puts output
end
send_raw_transaction(raw_transaction_id, description = nil) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 137
def send_raw_transaction(raw_transaction_id, description = nil)
  output = []
  response = @client.send_raw_transaction({
                                              :raw_transactions_id => raw_transaction_id,
                                              :description => description
                                          })
  output << response['message']
  output = output.join("\n")
  puts output
end
trackers(account_id) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 185
def trackers(account_id)
  output = []
  response = @client.trackers(account_id)
  output << response['message']
  output = output.join("\n")
  puts output
end
transactions(account_id) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 103
def transactions(account_id)
  output = []
  response = @client.transactions(account_id)
  if response.kind_of?(Array) and response.length == 0
    output << "No transactions for account #{account_id} and address #{account_id}."
  elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
    output << "Transactions for account #{account_id}:"
    output << JSON.pretty_generate(response['transactions'])
  else
    output << "No transactions for account #{account_id}."
  end
  output = output.join("\n")
  puts output
end
transactions_by_address(account_id, address) click to toggle source
# File lib/cryptoprocessing/cli.rb, line 120
def transactions_by_address(account_id, address)
  output = []
  response = @client.transactions_by_address(account_id, address)
  if response.kind_of?(Array) and response.length == 0
    output << "No transactions for account #{account_id} and address #{address}."
  elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
    output << "Transactions for account #{account_id} and address #{address}:"
    output << JSON.pretty_generate(response['transactions'])
  else
    output << "No transactions for account #{account_id} and address #{address}."
  end
  output = output.join("\n")
  puts output
end