cryptoprocessing 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +35 -0
- data/.coveralls.yml +1 -0
- data/.document +5 -0
- data/.editorconfig +12 -0
- data/.gemtest +0 -0
- data/.gitattributes +1 -0
- data/.gitignore +129 -0
- data/.hound.yml +5 -0
- data/.rspec +3 -0
- data/.rubocop.yml +65 -0
- data/.rubocop_todo.yml +0 -0
- data/.ruby-version +1 -0
- data/.simplecov +8 -0
- data/.travis.yml +11 -0
- data/.yardopts +10 -0
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +94 -0
- data/LICENSE.txt +21 -0
- data/NOTICE.txt +2 -0
- data/README.md +86 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cryptoprocessing.gemspec +39 -0
- data/exe/cryptoprocessing +5 -0
- data/lib/cryptoprocessing.rb +37 -0
- data/lib/cryptoprocessing/adapters/em_http.rb +71 -0
- data/lib/cryptoprocessing/adapters/net_http.rb +6 -0
- data/lib/cryptoprocessing/authentication.rb +67 -0
- data/lib/cryptoprocessing/authentication/storages/file_token_store.rb +0 -0
- data/lib/cryptoprocessing/authentication/storages/redis_token_store.rb +0 -0
- data/lib/cryptoprocessing/authentication/token_store.rb +57 -0
- data/lib/cryptoprocessing/cli.rb +203 -0
- data/lib/cryptoprocessing/client.rb +108 -0
- data/lib/cryptoprocessing/client/accounts.rb +43 -0
- data/lib/cryptoprocessing/client/addresses.rb +56 -0
- data/lib/cryptoprocessing/client/api_errors.rb +7 -0
- data/lib/cryptoprocessing/client/api_response.rb +39 -0
- data/lib/cryptoprocessing/client/callbacks.rb +39 -0
- data/lib/cryptoprocessing/client/coinbase_wallet.rb +45 -0
- data/lib/cryptoprocessing/client/net_response.rb +100 -0
- data/lib/cryptoprocessing/client/trackers.rb +37 -0
- data/lib/cryptoprocessing/client/transactions.rb +90 -0
- data/lib/cryptoprocessing/configurable.rb +73 -0
- data/lib/cryptoprocessing/connection.rb +140 -0
- data/lib/cryptoprocessing/default.rb +78 -0
- data/lib/cryptoprocessing/error.rb +3 -0
- data/lib/cryptoprocessing/models/account.rb +39 -0
- data/lib/cryptoprocessing/models/address.rb +17 -0
- data/lib/cryptoprocessing/models/api_object.rb +14 -0
- data/lib/cryptoprocessing/models/callback.rb +4 -0
- data/lib/cryptoprocessing/models/tracker.rb +4 -0
- data/lib/cryptoprocessing/models/transaction.rb +6 -0
- data/lib/cryptoprocessing/models/user.rb +6 -0
- data/lib/cryptoprocessing/rails.rb +13 -0
- data/lib/cryptoprocessing/version.rb +17 -0
- data/script/bootstrap +5 -0
- data/script/cibuild +5 -0
- data/script/console +11 -0
- data/script/package +7 -0
- data/script/release +16 -0
- data/script/test +17 -0
- metadata +236 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'cryptoprocessing'
|
2
|
+
require 'thor'
|
3
|
+
require 'json/ext'
|
4
|
+
|
5
|
+
module Cryptoprocessing
|
6
|
+
class CLI < Thor
|
7
|
+
class_option :verbose, :type => :boolean
|
8
|
+
class_option :api_endpoint
|
9
|
+
class_option :api_namespace
|
10
|
+
class_option :access_token
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
config = {}
|
15
|
+
config[:api_endpoint] = options[:api_endpoint] if options[:api_endpoint]
|
16
|
+
config[:api_namespace] = options[:api_namespace] if options[:api_namespace]
|
17
|
+
config[:access_token] = options[:access_token] if options[:access_token]
|
18
|
+
|
19
|
+
@client = Cryptoprocessing::Client.new(config)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "register EMAIL PASSWORD", "Register user at Cryptoprocessing with EMAIL and PASSWORD"
|
23
|
+
|
24
|
+
def register(email, password)
|
25
|
+
output = []
|
26
|
+
response = @client.register({:email => email, :password => password})
|
27
|
+
output << response['message']
|
28
|
+
output = output.join("\n")
|
29
|
+
puts output
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "login EMAIL PASSWORD", "Login user to Cryptoprocessing using EMAIL and PASSWORD"
|
33
|
+
|
34
|
+
def login(email, password)
|
35
|
+
output = []
|
36
|
+
response = @client.login({:email => email, :password => password})
|
37
|
+
output << response['message']
|
38
|
+
output = output.join("\n")
|
39
|
+
puts output
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "create_account CURRENCY NAME", "Create account for user with NAME"
|
43
|
+
|
44
|
+
def create_account(currency, name)
|
45
|
+
output = []
|
46
|
+
response = @client.create_account({:currency => currency, :name => name})
|
47
|
+
output << "Account with ID #{response['account_id']} created."
|
48
|
+
output = output.join("\n")
|
49
|
+
puts output
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "account ACCOUNT_ID", "Get account info by ACCOUNT_ID"
|
53
|
+
|
54
|
+
def account(account_id, currency = nil)
|
55
|
+
output = []
|
56
|
+
response = @client.account(account_id,{:currency => currency})
|
57
|
+
output << "Account #{account_id} info:"
|
58
|
+
output << JSON.pretty_generate(response['data'])
|
59
|
+
output = output.join("\n")
|
60
|
+
puts output
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "create_address NAME", "Add address to NAME"
|
64
|
+
|
65
|
+
def create_address(account_id, name = nil)
|
66
|
+
output = []
|
67
|
+
response = @client.create_address(account_id, {:name => name})
|
68
|
+
output << "Address with ID #{response['id']} created."
|
69
|
+
output = output.join("\n")
|
70
|
+
puts output
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "addresses ACCOUNT_ID", "Addresses for ACCOUNT_ID"
|
74
|
+
|
75
|
+
def addresses(account_id)
|
76
|
+
output = []
|
77
|
+
response = @client.addresses(account_id)
|
78
|
+
if response.kind_of?(Array) and response.length == 0
|
79
|
+
output << "No addresses for account #{account_id}."
|
80
|
+
elsif response['addresses'].kind_of?(Array) && response['transactions'].length > 0
|
81
|
+
output << "Addresses for account #{account_id}:"
|
82
|
+
output << JSON.pretty_generate(response)
|
83
|
+
else
|
84
|
+
output << "No addresses for account #{account_id}."
|
85
|
+
end
|
86
|
+
output = output.join("\n")
|
87
|
+
puts output
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "address ACCOUNT_ID ADDRESS", "Show address info for ACCOUNT_ID and ADDRESS"
|
91
|
+
|
92
|
+
def address(account_id, address)
|
93
|
+
output = []
|
94
|
+
response = @client.address(account_id, address)
|
95
|
+
output << "Address #{address} for account #{account_id} info:"
|
96
|
+
output << JSON.pretty_generate(response)
|
97
|
+
output = output.join("\n")
|
98
|
+
puts output
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "transactions ACCOUNT_ID", "List transactions by ACCOUNT_ID"
|
102
|
+
|
103
|
+
def transactions(account_id)
|
104
|
+
output = []
|
105
|
+
response = @client.transactions(account_id)
|
106
|
+
if response.kind_of?(Array) and response.length == 0
|
107
|
+
output << "No transactions for account #{account_id} and address #{account_id}."
|
108
|
+
elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
|
109
|
+
output << "Transactions for account #{account_id}:"
|
110
|
+
output << JSON.pretty_generate(response['transactions'])
|
111
|
+
else
|
112
|
+
output << "No transactions for account #{account_id}."
|
113
|
+
end
|
114
|
+
output = output.join("\n")
|
115
|
+
puts output
|
116
|
+
end
|
117
|
+
|
118
|
+
desc "transactions_by_address ACCOUNT_ID ADDRESS", "List transactions from ACCOUNT_ID with address ADDRESS"
|
119
|
+
|
120
|
+
def transactions_by_address(account_id, address)
|
121
|
+
output = []
|
122
|
+
response = @client.transactions_by_address(account_id, address)
|
123
|
+
if response.kind_of?(Array) and response.length == 0
|
124
|
+
output << "No transactions for account #{account_id} and address #{address}."
|
125
|
+
elsif response['transactions'].kind_of?(Array) && response['transactions'].length > 0
|
126
|
+
output << "Transactions for account #{account_id} and address #{address}:"
|
127
|
+
output << JSON.pretty_generate(response['transactions'])
|
128
|
+
else
|
129
|
+
output << "No transactions for account #{account_id} and address #{address}."
|
130
|
+
end
|
131
|
+
output = output.join("\n")
|
132
|
+
puts output
|
133
|
+
end
|
134
|
+
|
135
|
+
desc "send_raw_transaction RAW_TRANSACTION_ID DESCRIPTION", "Send RAW_TRANSACTION_ID with DESCRIPTION"
|
136
|
+
|
137
|
+
def send_raw_transaction(raw_transaction_id, description = nil)
|
138
|
+
output = []
|
139
|
+
response = @client.send_raw_transaction({
|
140
|
+
:raw_transactions_id => raw_transaction_id,
|
141
|
+
:description => description
|
142
|
+
})
|
143
|
+
output << response['message']
|
144
|
+
output = output.join("\n")
|
145
|
+
puts output
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "create_transaction ACCOUNT_ID FROM TO AMOUNT DESCRIPTION IDEM", "Create transaction record"
|
149
|
+
|
150
|
+
def create_transaction(account_id, from_address, to_address, amount, description = nil, idem = nil)
|
151
|
+
output = []
|
152
|
+
response = @client.create_transaction(account_id, {
|
153
|
+
:from => [from_address],
|
154
|
+
:to => [{:amount => amount, :address => to_address}],
|
155
|
+
:description => description,
|
156
|
+
:idem => idem
|
157
|
+
})
|
158
|
+
output << response['message']
|
159
|
+
output = output.join("\n")
|
160
|
+
puts output
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "callbacks ACCOUNT_ID ADDRESS", "List callbacks from ACCOUNT_ID with address ADDRESS"
|
164
|
+
|
165
|
+
def callbacks(account_id)
|
166
|
+
output = []
|
167
|
+
response = @client.callbacks(account_id)
|
168
|
+
output << response['message']
|
169
|
+
output = output.join("\n")
|
170
|
+
puts output
|
171
|
+
end
|
172
|
+
|
173
|
+
desc "create_callback ACCOUNT_ID ADDRESS", "Create callback for ACCOUNT_ID with address ADDRESS"
|
174
|
+
|
175
|
+
def create_callback(account_id, address)
|
176
|
+
output = []
|
177
|
+
response = @client.create_callback(account_id, address)
|
178
|
+
output << response['message']
|
179
|
+
output = output.join("\n")
|
180
|
+
puts output
|
181
|
+
end
|
182
|
+
|
183
|
+
desc "trackers ACCOUNT_ID ADDRESS", "List transactions from ACCOUNT_ID with address ADDRESS"
|
184
|
+
|
185
|
+
def trackers(account_id)
|
186
|
+
output = []
|
187
|
+
response = @client.trackers(account_id)
|
188
|
+
output << response['message']
|
189
|
+
output = output.join("\n")
|
190
|
+
puts output
|
191
|
+
end
|
192
|
+
|
193
|
+
desc "create_tracker ACCOUNT_ID ADDRESS", "List transactions from ACCOUNT_ID with address ADDRESS"
|
194
|
+
|
195
|
+
def create_tracker(account_id, address)
|
196
|
+
output = []
|
197
|
+
response = @client.create_tracker(account_id, address)
|
198
|
+
output << response['message']
|
199
|
+
output = output.join("\n")
|
200
|
+
puts output
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'cryptoprocessing/authentication'
|
2
|
+
require 'cryptoprocessing/configurable'
|
3
|
+
require 'cryptoprocessing/connection'
|
4
|
+
require 'cryptoprocessing/client/accounts'
|
5
|
+
require 'cryptoprocessing/client/addresses'
|
6
|
+
require 'cryptoprocessing/client/callbacks'
|
7
|
+
require 'cryptoprocessing/client/trackers'
|
8
|
+
require 'cryptoprocessing/client/transactions'
|
9
|
+
require 'cryptoprocessing/client/coinbase_wallet'
|
10
|
+
|
11
|
+
module Cryptoprocessing
|
12
|
+
|
13
|
+
# Cryptoprocessing API client masks default currency with BTC.
|
14
|
+
# But default currency can be simply overridden with blockchain_type property.
|
15
|
+
class Client
|
16
|
+
include Cryptoprocessing::Authentication
|
17
|
+
include Cryptoprocessing::Configurable
|
18
|
+
include Cryptoprocessing::Connection
|
19
|
+
include Cryptoprocessing::Client::Accounts
|
20
|
+
include Cryptoprocessing::Client::Callbacks
|
21
|
+
include Cryptoprocessing::Client::Addresses
|
22
|
+
include Cryptoprocessing::Client::Trackers
|
23
|
+
include Cryptoprocessing::Client::Transactions
|
24
|
+
|
25
|
+
include Cryptoprocessing::Client::CoinbaseWallet
|
26
|
+
|
27
|
+
attr_writer :logger
|
28
|
+
|
29
|
+
def initialize(options = {})
|
30
|
+
# Use options passed in, but fall back to module defaults
|
31
|
+
Cryptoprocessing::Configurable.keys.each do |key|
|
32
|
+
instance_variable_set(:"@#{key}", options[key] || Cryptoprocessing.instance_variable_get(:"@#{key}"))
|
33
|
+
end
|
34
|
+
|
35
|
+
# login_from_netrc unless user_authenticated? || application_authenticated?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Text representation of the client, masking tokens and passwords
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
def inspect
|
42
|
+
inspected = super
|
43
|
+
|
44
|
+
# mask password
|
45
|
+
inspected = inspected.gsub! @password, "*******" if @password
|
46
|
+
# Only show last 4 of token, secret
|
47
|
+
if @access_token
|
48
|
+
inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
|
49
|
+
end
|
50
|
+
|
51
|
+
inspected
|
52
|
+
end
|
53
|
+
|
54
|
+
# @!attribute [rw] logger
|
55
|
+
# @return [Logger] The logger.
|
56
|
+
def self.logger
|
57
|
+
@logger ||= rails_logger || default_logger
|
58
|
+
end
|
59
|
+
|
60
|
+
# Create and configure a logger
|
61
|
+
# @return [Logger]
|
62
|
+
def self.default_logger
|
63
|
+
logger = Logger.new($stdout)
|
64
|
+
logger.level = Logger::WARN
|
65
|
+
logger
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check to see if client is being used in a Rails environment and get the logger if present.
|
69
|
+
# Setting the ENV variable 'GOOGLE_API_USE_RAILS_LOGGER' to false will force the client
|
70
|
+
# to use its own logger.
|
71
|
+
#
|
72
|
+
# @return [Logger]
|
73
|
+
def self.rails_logger
|
74
|
+
if 'true' == ENV.fetch('CRYPTOPROCESSING_USE_RAILS_LOGGER', 'true') &&
|
75
|
+
defined?(::Rails) &&
|
76
|
+
::Rails.respond_to?(:logger) &&
|
77
|
+
!::Rails.logger.nil?
|
78
|
+
::Rails.logger
|
79
|
+
else
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Set username for authentication
|
85
|
+
#
|
86
|
+
# @param value [String] Cryptoprocessing username
|
87
|
+
def email=(value)
|
88
|
+
reset_agent
|
89
|
+
@email = value
|
90
|
+
end
|
91
|
+
|
92
|
+
# Set password for authentication
|
93
|
+
#
|
94
|
+
# @param value [String] Cryptoprocessing password
|
95
|
+
def password=(value)
|
96
|
+
reset_agent
|
97
|
+
@password = value
|
98
|
+
end
|
99
|
+
|
100
|
+
# Set access token for authentication
|
101
|
+
#
|
102
|
+
# @param value [String] 40 character Cryptoprocessing access token
|
103
|
+
def access_token=(value)
|
104
|
+
reset_agent
|
105
|
+
@access_token = value
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'cryptoprocessing/models/account'
|
2
|
+
|
3
|
+
module Cryptoprocessing
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Methods for the Commits API
|
7
|
+
#
|
8
|
+
# @see https://api.cryptoprocessing.io/#db40c5d3-078d-af2a-63e0-fd616f56e433
|
9
|
+
module Accounts
|
10
|
+
|
11
|
+
# Get account info
|
12
|
+
#
|
13
|
+
# @param [String] id
|
14
|
+
# @return [Array<Cryptoprocessing::Account>] A list of accounts
|
15
|
+
# @see https://api.cryptoprocessing.io/#4df50869-9044-21b6-bb27-a718f30e0040
|
16
|
+
def account(id, options = {})
|
17
|
+
currency = if options[:currency] then options[:currency] else blockchain_type end
|
18
|
+
out = nil
|
19
|
+
get("/v1/#{currency}/accounts/#{id}", options) do |resp|
|
20
|
+
out = Cryptoprocessing::Account.new(self, resp.data['data'])
|
21
|
+
yield(out, resp) if block_given?
|
22
|
+
end
|
23
|
+
out
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create account for given currency and with given name
|
27
|
+
#
|
28
|
+
# Создаем аккаунт
|
29
|
+
#
|
30
|
+
# @return [Cryptoprocessing::Account]
|
31
|
+
# @see https://api.cryptoprocessing.io/#7b3bacaf-aa8e-77ad-4d0d-f834b10ebc95
|
32
|
+
def create_account(options = {})
|
33
|
+
options[:currency] = blockchain_type unless options[:currency]
|
34
|
+
out = nil
|
35
|
+
post("/v1/accounts", options) do |resp|
|
36
|
+
out = Cryptoprocessing::Account.new(self, resp.data.merge(options))
|
37
|
+
yield(out, resp) if block_given?
|
38
|
+
end
|
39
|
+
out
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'cryptoprocessing/models/address'
|
2
|
+
|
3
|
+
module Cryptoprocessing
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Methods for addresses
|
7
|
+
#
|
8
|
+
# @return [Cryptoprocessing::Address]
|
9
|
+
# @see https://api.cryptoprocessing.io/#be1b38bb-7702-51c6-192f-91cf3a506ae8
|
10
|
+
module Addresses
|
11
|
+
|
12
|
+
# Get address info
|
13
|
+
#
|
14
|
+
# @param [String] account_id
|
15
|
+
# @param [String] address
|
16
|
+
# @return [Cryptoprocessing::Address]
|
17
|
+
# @see https://api.cryptoprocessing.io/#55759d22-b04b-1a63-ca8d-6b881b0212b2
|
18
|
+
def address(account_id, address, options = {})
|
19
|
+
out = nil
|
20
|
+
currency = if options[:currency] then options[:currency] else blockchain_type end
|
21
|
+
get("/v1/#{currency}/accounts/#{account_id}/addresses/#{address}", options) do |resp|
|
22
|
+
out = Cryptoprocessing::Address.new(self, resp.data)
|
23
|
+
end
|
24
|
+
out
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get addresses list
|
28
|
+
#
|
29
|
+
# @param [String] account_id
|
30
|
+
# @return [Array<Cryptoprocessing::Address>] A list of addresses
|
31
|
+
# @see https://api.cryptoprocessing.io/#b826594e-db0d-4efe-04e9-c1286e6f8948
|
32
|
+
def addresses(account_id, options = {})
|
33
|
+
out = nil
|
34
|
+
currency = if options[:currency] then options[:currency] else blockchain_type end
|
35
|
+
get("/v1/#{currency}/accounts/#{account_id}/addresses", options) do |resp|
|
36
|
+
out = resp.data['addresses'].map { |item| Cryptoprocessing::Address.new(self, item) }
|
37
|
+
end
|
38
|
+
out
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create address for account
|
42
|
+
#
|
43
|
+
# @param [String] account_id
|
44
|
+
# @return [Cryptoprocessing::Address]
|
45
|
+
# @see https://api.cryptoprocessing.io/#d6486a95-a5cb-4d4b-0369-0c7af040bc4d
|
46
|
+
def create_address(account_id, options = {})
|
47
|
+
out = nil
|
48
|
+
currency = if options[:currency] then options[:currency] else blockchain_type end
|
49
|
+
post("/v1/#{currency}/accounts/#{account_id}/addresses", options) do |resp|
|
50
|
+
out = Cryptoprocessing::Address.new(self, resp.data)
|
51
|
+
end
|
52
|
+
out
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Cryptoprocessing
|
2
|
+
class APIResponse
|
3
|
+
attr_reader :received_at
|
4
|
+
attr_accessor :client
|
5
|
+
attr_accessor :method
|
6
|
+
attr_accessor :params
|
7
|
+
|
8
|
+
def initialize(resp)
|
9
|
+
@received_at = Time.now
|
10
|
+
@response = resp
|
11
|
+
end
|
12
|
+
|
13
|
+
def raw
|
14
|
+
@response
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :data, :body
|
22
|
+
|
23
|
+
def body=(body)
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
def status
|
32
|
+
raise NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_more?
|
36
|
+
body.has_key?('pagination') && body['pagination']['next_uri'] != nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|