Class: Cryptoprocessing::CLI
- Inherits:
-
Thor
- Object
- Thor
- Cryptoprocessing::CLI
- Defined in:
- lib/cryptoprocessing/cli.rb
Instance Method Summary collapse
- #account(account_id, currency = nil) ⇒ Object
- #address(account_id, address) ⇒ Object
- #addresses(account_id) ⇒ Object
- #callbacks(account_id) ⇒ Object
- #create_account(currency, name) ⇒ Object
- #create_address(account_id, name = nil) ⇒ Object
- #create_callback(account_id, address) ⇒ Object
- #create_tracker(account_id, address) ⇒ Object
- #create_transaction(account_id, from_address, to_address, amount, description = nil, idem = nil) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #login(email, password) ⇒ Object
- #register(email, password) ⇒ Object
- #send_raw_transaction(raw_transaction_id, description = nil) ⇒ Object
- #trackers(account_id) ⇒ Object
- #transactions(account_id) ⇒ Object
- #transactions_by_address(account_id, address) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 |
# File 'lib/cryptoprocessing/cli.rb', line 12 def initialize(*args) super config = {} config[:api_endpoint] = [:api_endpoint] if [:api_endpoint] config[:api_namespace] = [:api_namespace] if [:api_namespace] config[:access_token] = [:access_token] if [:access_token] @client = Cryptoprocessing::Client.new(config) end |
Instance Method Details
#account(account_id, currency = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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) ⇒ Object
165 166 167 168 169 170 171 |
# 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) ⇒ Object
44 45 46 47 48 49 50 |
# 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) ⇒ Object
65 66 67 68 69 70 71 |
# 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) ⇒ Object
175 176 177 178 179 180 181 |
# 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) ⇒ Object
195 196 197 198 199 200 201 |
# 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) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# 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) ⇒ Object
34 35 36 37 38 39 40 |
# 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) ⇒ Object
24 25 26 27 28 29 30 |
# 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) ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# 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) ⇒ Object
185 186 187 188 189 190 191 |
# 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) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# 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) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 |