blockbee 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +9 -15
- data/lib/blockbee.rb +104 -121
- data/sig/blockbee.rbs +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 971520704d7a73596c7c0fcecff00c295a1b5c1e8fe445e05d15c9c89f58c86a
|
4
|
+
data.tar.gz: ecbd1c47aa90667afa5b0cc6f5401e87bf75022a528b2cf402f9324707d8e617
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca5ea223cd24d4b3a47bfaef5f59900c76b63d502f4bf298e8899a8936512801c1f53e0b2bd339b98d1ac1fe7c70d8ed2f46cc36f70fd68225658ef113d2ac2
|
7
|
+
data.tar.gz: 6b67a974bbcecb05c1902b81116edbbe0444667eea1c6e77f8d7ec51be6a45235a2ba036afadd443fb408f3f87719da022d0907e4bdc980145b641d18b511f52
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,15 +19,15 @@ Ruby >= 3
|
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
22
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
23
|
-
|
24
22
|
Install the gem and add to the application's Gemfile by executing:
|
25
23
|
|
26
|
-
$ bundle add
|
24
|
+
$ bundle add blockbee
|
27
25
|
|
28
26
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
29
27
|
|
30
|
-
$ gem install
|
28
|
+
$ gem install blockbee
|
29
|
+
|
30
|
+
[RubyGem Page](https://rubygems.org/gems/blockbee/versions/1.0.0)
|
31
31
|
|
32
32
|
## API and utils
|
33
33
|
|
@@ -42,17 +42,16 @@ require 'blockbee'
|
|
42
42
|
```ruby
|
43
43
|
require 'blockbee'
|
44
44
|
|
45
|
-
info = BlockBee::API.get_info(coin,
|
45
|
+
info = BlockBee::API.get_info(coin, prices)
|
46
46
|
|
47
47
|
# or if you wish to get full BlockBee service information
|
48
48
|
|
49
|
-
info = BlockBee::API.get_info(nil,
|
49
|
+
info = BlockBee::API.get_info(nil, prices)
|
50
50
|
|
51
51
|
```
|
52
52
|
|
53
53
|
### Where
|
54
54
|
* ``coin`` is the coin you wish to use, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...).
|
55
|
-
* ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
|
56
55
|
* ``prices`` by default `0`. If `1` will return the prices of the cryptocurrencies converted to all supported FIAT currencies.
|
57
56
|
|
58
57
|
### Generating a new Address
|
@@ -133,8 +132,7 @@ qrcode = blockbee_helper.get_qrcode(value, size)
|
|
133
132
|
#### Where:
|
134
133
|
|
135
134
|
* ``value`` is the value requested to the user in the coin to which the request was done. **Optional**, can be empty if you don't wish to add the value to the QR Code.
|
136
|
-
* ``size`` Size of the QR Code image in pixels. Optional, leave empty to use the default size of
|
137
|
-
* ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
|
135
|
+
* ``size`` Size of the QR Code image in pixels. Optional, leave empty to use the default size of 300.
|
138
136
|
|
139
137
|
> Response is an object with `qr_code` (base64 encoded image data) and `payment_uri` (the value encoded in the QR), see https://docs.blockbee.io/#operation/qrcode for more information.
|
140
138
|
|
@@ -157,14 +155,13 @@ qrcode = blockbee_helper.get_qrcode(value, size)
|
|
157
155
|
```ruby
|
158
156
|
require 'blockbee'
|
159
157
|
|
160
|
-
estimation = BlockBee::API.get_estimate(coin, addresses, priority
|
158
|
+
estimation = BlockBee::API.get_estimate(coin, addresses, priority)
|
161
159
|
```
|
162
160
|
|
163
161
|
#### Where:
|
164
162
|
* ``coin`` is the coin you wish to check, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...)
|
165
163
|
* ``addresses`` The number of addresses to forward the funds to. Optional, defaults to 1.
|
166
164
|
* ``priority`` Confirmation priority, (check [this](https://support.blockbee.io/article/how-the-priority-parameter-works) article to learn more about it). Optional, defaults to ``default``.
|
167
|
-
* ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
|
168
165
|
|
169
166
|
> Response is an object with ``estimated_cost`` and ``estimated_cost_usd``, see https://docs.blockbee.io/#operation/estimate for more information.
|
170
167
|
|
@@ -215,12 +212,9 @@ conversion = blockbee_helper.get_conversion(from_coin, value)
|
|
215
212
|
```ruby
|
216
213
|
require 'blockbee'
|
217
214
|
|
218
|
-
supported_coins = BlockBee::API.get_supported_coins
|
215
|
+
supported_coins = BlockBee::API.get_supported_coins
|
219
216
|
```
|
220
217
|
|
221
|
-
### Where:
|
222
|
-
* ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
|
223
|
-
|
224
218
|
> Response is an array with all supported coins.
|
225
219
|
|
226
220
|
#### Response sample:
|
data/lib/blockbee.rb
CHANGED
@@ -5,36 +5,60 @@ require 'uri'
|
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
module BlockBee
|
8
|
-
class
|
8
|
+
class APIError < StandardError
|
9
|
+
attr_reader :status_code
|
9
10
|
|
10
|
-
|
11
|
+
def initialize(message, status_code)
|
12
|
+
super(message)
|
13
|
+
@status_code = status_code
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_status_code(status_code, message)
|
17
|
+
case status_code
|
18
|
+
when 400
|
19
|
+
new("Bad Request: #{message}", 400)
|
20
|
+
when 401
|
21
|
+
new("Unauthorized: #{message}", 401)
|
22
|
+
when 403
|
23
|
+
new("Forbidden: #{message}", 403)
|
24
|
+
when 404
|
25
|
+
new("Not Found: #{message}", 404)
|
26
|
+
when 500
|
27
|
+
new("Internal Server Error", 500)
|
28
|
+
else
|
29
|
+
new("Unexpected Error: #{message}", status_code)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class MissingAPIKeyError < StandardError; end
|
35
|
+
|
36
|
+
class CallbackURLMissing < StandardError; end
|
37
|
+
|
38
|
+
VERSION = "1.0.1"
|
11
39
|
|
12
40
|
BLOCKBEE_URL = 'https://api.blockbee.io/'
|
13
41
|
BLOCKBEE_HOST = 'api.blockbee.io'
|
14
42
|
|
15
43
|
class API
|
16
|
-
def initialize(coin, own_address
|
17
|
-
raise 'API Key
|
44
|
+
def initialize(coin, callback_url, api_key, own_address: '', parameters: {}, bb_params: {})
|
45
|
+
raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil?
|
46
|
+
raise BlockBee::CallbackURLMissing, 'Provide your callback URL' if callback_url.nil?
|
18
47
|
|
19
|
-
|
48
|
+
_cb = URI::parse(callback_url)
|
49
|
+
|
50
|
+
@callback_url = URI::HTTPS.build(
|
51
|
+
host: _cb.host,
|
52
|
+
path: _cb.path,
|
53
|
+
query: URI.encode_www_form(parameters)
|
54
|
+
)
|
20
55
|
|
21
|
-
@callback_url = callback_url
|
22
56
|
@coin = coin
|
23
57
|
@own_address = own_address
|
24
|
-
@parameters = parameters
|
25
|
-
@bb_params = bb_params
|
58
|
+
@parameters = parameters
|
59
|
+
@bb_params = bb_params
|
26
60
|
@api_key = api_key
|
27
61
|
@payment_address = ''
|
28
|
-
|
29
|
-
if parameters
|
30
|
-
_cb = URI::parse(callback_url)
|
31
|
-
|
32
|
-
@callback_url = URI::HTTPS.build(
|
33
|
-
host: _cb.host,
|
34
|
-
path: _cb.path,
|
35
|
-
query: URI.encode_www_form(parameters)
|
36
|
-
)
|
37
|
-
end
|
38
62
|
end
|
39
63
|
|
40
64
|
def get_address
|
@@ -46,12 +70,10 @@ module BlockBee
|
|
46
70
|
}.merge(@bb_params)
|
47
71
|
|
48
72
|
if !@own_address.nil? && !@own_address.empty?
|
49
|
-
|
73
|
+
(_params['address'] = @own_address)
|
50
74
|
end
|
51
75
|
|
52
|
-
_address = BlockBee::process_request_get(@coin, 'create', _params)
|
53
|
-
|
54
|
-
return nil unless _address
|
76
|
+
_address = BlockBee::process_request_get(@coin, 'create', params: _params)
|
55
77
|
|
56
78
|
@payment_address = _address['address_in']
|
57
79
|
|
@@ -64,16 +86,12 @@ module BlockBee
|
|
64
86
|
'apikey' => @api_key
|
65
87
|
}
|
66
88
|
|
67
|
-
_logs = BlockBee::process_request_get(@coin, 'logs', _params)
|
68
|
-
|
69
|
-
return nil unless _logs
|
70
|
-
|
71
|
-
p _logs
|
89
|
+
_logs = BlockBee::process_request_get(@coin, 'logs', params: _params)
|
72
90
|
|
73
91
|
_logs
|
74
92
|
end
|
75
93
|
|
76
|
-
def get_qrcode(value
|
94
|
+
def get_qrcode(value: nil, size: 300)
|
77
95
|
return nil if @coin.nil?
|
78
96
|
|
79
97
|
address = @payment_address
|
@@ -82,15 +100,14 @@ module BlockBee
|
|
82
100
|
|
83
101
|
_params = {
|
84
102
|
'address' => address,
|
85
|
-
'size' => size
|
86
|
-
'apikey' => @api_key
|
103
|
+
'size' => size
|
87
104
|
}
|
88
105
|
|
89
|
-
|
90
|
-
|
91
|
-
|
106
|
+
if value.is_a? Numeric
|
107
|
+
_params['value'] = value
|
108
|
+
end
|
92
109
|
|
93
|
-
|
110
|
+
_qrcode = BlockBee::process_request_get(@coin, 'qrcode', params: _params)
|
94
111
|
|
95
112
|
_qrcode
|
96
113
|
end
|
@@ -99,35 +116,23 @@ module BlockBee
|
|
99
116
|
_params = {
|
100
117
|
'from' => from_coin,
|
101
118
|
'value' => value,
|
102
|
-
'apikey' => @api_key
|
103
119
|
}
|
104
120
|
|
105
|
-
_conversion = BlockBee::process_request_get(@coin, 'convert', _params)
|
106
|
-
|
107
|
-
return nil unless _conversion
|
121
|
+
_conversion = BlockBee::process_request_get(@coin, 'convert', params: _params)
|
108
122
|
|
109
123
|
_conversion
|
110
124
|
end
|
111
125
|
|
112
|
-
def self.get_info(coin,
|
113
|
-
raise 'API Key Missing' if api_key.nil?
|
114
|
-
|
126
|
+
def self.get_info(coin, prices: 0)
|
115
127
|
_params = {
|
116
128
|
'prices' => prices,
|
117
|
-
'apikey' => api_key
|
118
129
|
}
|
119
130
|
|
120
|
-
_info = BlockBee::process_request_get(coin, 'info', _params)
|
121
|
-
|
122
|
-
return nil unless _info
|
123
|
-
|
124
|
-
_info
|
131
|
+
_info = BlockBee::process_request_get(coin, 'info', params: _params)
|
125
132
|
end
|
126
133
|
|
127
|
-
def self.get_supported_coins(
|
128
|
-
|
129
|
-
|
130
|
-
_info = get_info(nil, api_key )
|
134
|
+
def self.get_supported_coins()
|
135
|
+
_info = get_info(nil)
|
131
136
|
|
132
137
|
_info.delete('fee_tiers')
|
133
138
|
|
@@ -146,67 +151,62 @@ module BlockBee
|
|
146
151
|
_coins
|
147
152
|
end
|
148
153
|
|
149
|
-
def self.get_estimate(coin, addresses
|
150
|
-
raise 'API Key
|
154
|
+
def self.get_estimate(coin, api_key, addresses: 1, priority: 'default')
|
155
|
+
raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil?
|
151
156
|
|
152
|
-
|
157
|
+
_params = {
|
153
158
|
'addresses' => addresses,
|
154
159
|
'priority' => priority,
|
155
|
-
'apikey' => api_key
|
156
160
|
}
|
157
161
|
|
158
|
-
_estimate = BlockBee::process_request_get(coin, 'estimate', params)
|
159
|
-
|
160
|
-
return nil unless _estimate
|
162
|
+
_estimate = BlockBee::process_request_get(coin, 'estimate', params: _params)
|
161
163
|
|
162
164
|
_estimate
|
163
165
|
end
|
164
166
|
|
165
|
-
def self.create_payout(coin, payout_requests, api_key, process
|
166
|
-
raise 'No requests provided' if payout_requests.nil? || payout_requests.empty?
|
167
|
-
|
167
|
+
def self.create_payout(coin, payout_requests, api_key, process: false)
|
168
168
|
body = { 'outputs' => payout_requests }
|
169
169
|
|
170
170
|
endpoint = 'payout/request/bulk'
|
171
171
|
|
172
172
|
endpoint += '/process' if process
|
173
173
|
|
174
|
-
_payout = BlockBee::process_request_post(coin, endpoint, api_key, body, true)
|
175
|
-
|
176
|
-
return nil unless _payout['status'] == 'success'
|
174
|
+
_payout = BlockBee::process_request_post(coin, endpoint, api_key, body: body, is_json: true)
|
177
175
|
|
178
176
|
_payout
|
179
177
|
end
|
180
178
|
|
181
|
-
def self.list_payouts(coin, status: 'all', page: 1,
|
182
|
-
return nil if api_key.nil?
|
183
|
-
|
179
|
+
def self.list_payouts(coin, api_key, status: 'all', page: 1, payout_request: false)
|
184
180
|
_params = {
|
185
181
|
'apikey' => api_key,
|
186
182
|
'status' => status,
|
187
|
-
'
|
183
|
+
'p' => page
|
188
184
|
}
|
189
185
|
|
190
186
|
endpoint = 'payout/list'
|
191
187
|
|
192
188
|
endpoint = 'payout/request/list' if payout_request
|
193
189
|
|
194
|
-
_payouts = BlockBee::process_request_get(coin, endpoint, _params)
|
195
|
-
|
196
|
-
return nil unless _payouts['status'] == 'success'
|
190
|
+
_payouts = BlockBee::process_request_get(coin, endpoint, params: _params)
|
197
191
|
|
198
192
|
_payouts
|
199
193
|
end
|
200
194
|
|
201
195
|
def self.get_payout_wallet(coin, api_key, balance = false)
|
202
|
-
wallet = BlockBee::process_request_get(coin, 'payout/address', 'apikey' => api_key)
|
196
|
+
wallet = BlockBee::process_request_get(coin, 'payout/address', params: { 'apikey' => api_key })
|
203
197
|
|
204
|
-
|
198
|
+
if wallet['status'] == 'error'
|
199
|
+
raise BlockBee::Error, wallet['error']
|
200
|
+
end
|
205
201
|
|
206
202
|
output = { 'address' => wallet['address'] }
|
207
203
|
|
208
204
|
if balance
|
209
|
-
wallet_balance = BlockBee::process_request_get(coin, 'payout/balance', 'apikey' => api_key)
|
205
|
+
wallet_balance = BlockBee::process_request_get(coin, 'payout/balance', params: { 'apikey' => api_key })
|
206
|
+
|
207
|
+
if wallet_balance['status'] == 'error'
|
208
|
+
raise BlockBee::Error, wallet_balance['error']
|
209
|
+
end
|
210
210
|
|
211
211
|
if wallet_balance['status'] == 'success'
|
212
212
|
output['balance'] = wallet_balance['balance']
|
@@ -217,31 +217,19 @@ module BlockBee
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def self.create_payout_by_ids(api_key, payout_ids)
|
220
|
-
|
221
|
-
|
222
|
-
_payout = BlockBee::process_request_post(nil, 'payout/create', api_key, { 'request_ids' => payout_ids.join(',') })
|
223
|
-
|
224
|
-
return nil unless _payout['status'] == 'success'
|
220
|
+
_payout = BlockBee::process_request_post(nil, 'payout/create', api_key, body: { 'request_ids' => payout_ids.join(',') })
|
225
221
|
|
226
222
|
_payout
|
227
223
|
end
|
228
224
|
|
229
225
|
def self.process_payout(api_key, payout_id)
|
230
|
-
|
231
|
-
|
232
|
-
_process = BlockBee::process_request_post(nil, 'payout/process', api_key, { 'payout_id' => payout_id })
|
233
|
-
|
234
|
-
return nil unless _process['status'] == 'success'
|
226
|
+
_process = BlockBee::process_request_post(nil, 'payout/process', api_key, body: { 'payout_id' => payout_id })
|
235
227
|
|
236
228
|
_process
|
237
229
|
end
|
238
230
|
|
239
231
|
def self.check_payout_status(api_key, payout_id)
|
240
|
-
|
241
|
-
|
242
|
-
_status = BlockBee::process_request_post(nil, 'payout/status', api_key, { 'payout_id' => payout_id })
|
243
|
-
|
244
|
-
return nil unless _status['status'] == 'success'
|
232
|
+
_status = BlockBee::process_request_post(nil, 'payout/status', api_key, body: { 'payout_id' => payout_id })
|
245
233
|
|
246
234
|
_status
|
247
235
|
end
|
@@ -249,7 +237,7 @@ module BlockBee
|
|
249
237
|
|
250
238
|
class Checkout
|
251
239
|
def initialize(parameters: {}, bb_params: {}, notify_url:, api_key:)
|
252
|
-
raise 'API Key
|
240
|
+
raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil?
|
253
241
|
|
254
242
|
@parameters = parameters
|
255
243
|
@bb_params = bb_params
|
@@ -268,9 +256,7 @@ module BlockBee
|
|
268
256
|
end
|
269
257
|
|
270
258
|
def payment_request(redirect_url, value)
|
271
|
-
raise '
|
272
|
-
|
273
|
-
raise 'Value must be a integer' unless value.is_a?(Integer)
|
259
|
+
raise ArgumentError, 'Provide a valid number' unless value.is_a?(Numeric)
|
274
260
|
|
275
261
|
_params = {
|
276
262
|
'redirect_url' => redirect_url,
|
@@ -279,7 +265,7 @@ module BlockBee
|
|
279
265
|
'apikey' => @api_key
|
280
266
|
}.merge(@bb_params)
|
281
267
|
|
282
|
-
_request = BlockBee::process_request_get(nil, 'checkout/request', _params)
|
268
|
+
_request = BlockBee::process_request_get(nil, 'checkout/request', params: _params)
|
283
269
|
|
284
270
|
return nil unless _request['status'] == 'success'
|
285
271
|
|
@@ -287,48 +273,34 @@ module BlockBee
|
|
287
273
|
end
|
288
274
|
|
289
275
|
def self.payment_logs(token, api_key)
|
290
|
-
raise 'API Key required' if api_key.nil? or api_key.empty?
|
291
|
-
|
292
|
-
raise 'Token required' if token.nil? or token.empty?
|
293
|
-
|
294
276
|
_params = {
|
295
277
|
'apikey' => api_key,
|
296
278
|
'token' => token
|
297
279
|
}
|
298
280
|
|
299
|
-
_logs = BlockBee::process_request_get(nil, 'checkout/logs', _params)
|
300
|
-
|
301
|
-
return nil unless _logs['status'] == 'success'
|
281
|
+
_logs = BlockBee::process_request_get(nil, 'checkout/logs', params: _params)
|
302
282
|
|
303
283
|
_logs
|
304
284
|
end
|
305
285
|
|
306
|
-
def deposit_request
|
286
|
+
def deposit_request
|
307
287
|
_params = {
|
308
288
|
'notify_url' => @notify_url,
|
309
289
|
'apikey' => @api_key
|
310
290
|
}.merge(@bb_params)
|
311
291
|
|
312
|
-
_request = BlockBee::process_request_get(nil, 'deposit/request', _params)
|
313
|
-
|
314
|
-
return nil unless _request['status'] == 'success'
|
292
|
+
_request = BlockBee::process_request_get(nil, 'deposit/request', params: _params)
|
315
293
|
|
316
294
|
_request
|
317
295
|
end
|
318
296
|
|
319
297
|
def self.deposit_logs(token, api_key)
|
320
|
-
raise 'API Key required' if api_key.nil? or api_key.empty?
|
321
|
-
|
322
|
-
raise 'Token required' if token.nil? or token.empty?
|
323
|
-
|
324
298
|
_params = {
|
325
299
|
'apikey' => api_key,
|
326
300
|
'token' => token
|
327
301
|
}
|
328
302
|
|
329
|
-
_logs = BlockBee::process_request_get(nil, 'deposit/logs', _params)
|
330
|
-
|
331
|
-
return nil unless _logs['status'] == 'success'
|
303
|
+
_logs = BlockBee::process_request_get(nil, 'deposit/logs', params: _params)
|
332
304
|
|
333
305
|
_logs
|
334
306
|
end
|
@@ -336,24 +308,27 @@ module BlockBee
|
|
336
308
|
|
337
309
|
private
|
338
310
|
|
339
|
-
def self.process_request_get(coin
|
311
|
+
def self.process_request_get(coin, endpoint, params: {})
|
340
312
|
coin = coin.nil? ? '' : "#{coin.tr('_', '/')}/"
|
341
313
|
|
342
|
-
response = Net::HTTP.
|
314
|
+
response = Net::HTTP.get_response(URI.parse("#{BLOCKBEE_URL}#{coin}#{endpoint}/?#{URI.encode_www_form(params)}"))
|
315
|
+
|
316
|
+
response_obj = JSON.parse(response.body)
|
343
317
|
|
344
|
-
|
318
|
+
if !response.is_a?(Net::HTTPSuccess) || response_obj['status'] == 'error'
|
319
|
+
error = APIError.from_status_code(response.code.to_i, response_obj['error'])
|
320
|
+
raise error
|
321
|
+
end
|
322
|
+
|
323
|
+
response_obj
|
345
324
|
end
|
346
325
|
|
347
|
-
def self.process_request_post(coin
|
326
|
+
def self.process_request_post(coin, endpoint, api_key, body: nil, is_json: false)
|
348
327
|
coin_path = coin.nil? ? '' : "#{coin.tr('_', '/')}/"
|
349
328
|
|
350
|
-
p coin_path
|
351
|
-
|
352
329
|
url = "#{BLOCKBEE_URL}#{coin_path}#{endpoint}/?apikey=#{api_key}"
|
353
330
|
uri = URI.parse(url)
|
354
331
|
|
355
|
-
p url
|
356
|
-
|
357
332
|
req = Net::HTTP::Post.new(uri)
|
358
333
|
req['Host'] = BLOCKBEE_HOST
|
359
334
|
|
@@ -366,6 +341,14 @@ module BlockBee
|
|
366
341
|
|
367
342
|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
|
368
343
|
|
369
|
-
JSON.parse(res.body)
|
344
|
+
response_obj = JSON.parse(res.body)
|
345
|
+
|
346
|
+
if res.is_a?(Net::HTTPSuccess) && response_obj['status'] == 'success'
|
347
|
+
response_obj
|
348
|
+
else
|
349
|
+
error_message = response_obj['error'] || "Unexpected error occurred"
|
350
|
+
error = APIError.from_status_code(res.code.to_i, error_message)
|
351
|
+
raise error
|
352
|
+
end
|
370
353
|
end
|
371
354
|
end
|
data/sig/blockbee.rbs
CHANGED
@@ -3,6 +3,14 @@ module BlockBee
|
|
3
3
|
BLOCKBEE_URL: string
|
4
4
|
VERSION: String
|
5
5
|
|
6
|
+
class APIError
|
7
|
+
@status_code: Integer
|
8
|
+
|
9
|
+
def self.from_status_code: -> untyped
|
10
|
+
|
11
|
+
attr_reader status_code: Integer
|
12
|
+
end
|
13
|
+
|
6
14
|
class API
|
7
15
|
@callback_url: string
|
8
16
|
@coin: string
|
@@ -21,7 +29,7 @@ module BlockBee
|
|
21
29
|
|
22
30
|
def get_qrcode: -> untyped
|
23
31
|
|
24
|
-
def get_info: -> untyped
|
32
|
+
def self.get_info: -> untyped
|
25
33
|
|
26
34
|
def self.get_supported_coins: -> untyped
|
27
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockbee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BlockBee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -31,7 +31,7 @@ licenses:
|
|
31
31
|
metadata:
|
32
32
|
homepage_uri: https://blockbee.io
|
33
33
|
source_code_uri: https://github.com/blockbee-io/ruby-blockbee
|
34
|
-
changelog_uri: https://github.com/blockbee-io/ruby-blockbee/blob/
|
34
|
+
changelog_uri: https://github.com/blockbee-io/ruby-blockbee/blob/master/CHANGELOG.md
|
35
35
|
post_install_message:
|
36
36
|
rdoc_options: []
|
37
37
|
require_paths:
|