Class: Cryptoprocessing::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/cryptoprocessing/cli.rb

Instance Method Summary collapse

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] = 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

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 (, currency = nil)
  output = []
  response = @client.(,{:currency => currency})
  output << "Account #{} 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(, address)
  output = []
  response = @client.address(, address)
  output << "Address #{address} for account #{} 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()
  output = []
  response = @client.addresses()
  if response.kind_of?(Array) and response.length == 0
    output << "No addresses for account #{}."
  elsif response['addresses'].kind_of?(Array) && response['transactions'].length > 0
    output << "Addresses for account #{}:"
    output << JSON.pretty_generate(response)
  else
    output << "No addresses for account #{}."
  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()
  output = []
  response = @client.callbacks()
  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 (currency, name)
  output = []
  response = @client.({: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(, name = nil)
  output = []
  response = @client.create_address(, {: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(, address)
  output = []
  response = @client.create_callback(, 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(, address)
  output = []
  response = @client.create_tracker(, 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(, from_address, to_address, amount, description = nil, idem = nil)
  output = []
  response = @client.create_transaction(, {
      :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 (email, password)
  output = []
  response = @client.({: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()
  output = []
  response = @client.trackers()
  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()
  output = []
  response = @client.transactions()
  if response.kind_of?(Array) and response.length == 0
    output << "No transactions for account #{} and address #{}."
  elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
    output << "Transactions for account #{}:"
    output << JSON.pretty_generate(response['transactions'])
  else
    output << "No transactions for account #{}."
  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(, address)
  output = []
  response = @client.transactions_by_address(, address)
  if response.kind_of?(Array) and response.length == 0
    output << "No transactions for account #{} and address #{address}."
  elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
    output << "Transactions for account #{} and address #{address}:"
    output << JSON.pretty_generate(response['transactions'])
  else
    output << "No transactions for account #{} and address #{address}."
  end
  output = output.join("\n")
  puts output
end