coinbase 0.0.1 → 4.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +7 -0
- data/CONTRIBUTING.md +53 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +621 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coinbase.gemspec +26 -0
- data/lib/coinbase/util.rb +16 -0
- data/lib/coinbase/wallet/adapters/em_http.rb +78 -0
- data/lib/coinbase/wallet/adapters/net_http.rb +68 -0
- data/lib/coinbase/wallet/api_client.rb +755 -0
- data/lib/coinbase/wallet/api_errors.rb +120 -0
- data/lib/coinbase/wallet/api_response.rb +41 -0
- data/lib/coinbase/wallet/ca-coinbase.crt +101 -0
- data/lib/coinbase/wallet/client.rb +101 -0
- data/lib/coinbase/wallet/coinbase-callback.pub +14 -0
- data/lib/coinbase/wallet/models/account.rb +193 -0
- data/lib/coinbase/wallet/models/address.rb +12 -0
- data/lib/coinbase/wallet/models/api_object.rb +46 -0
- data/lib/coinbase/wallet/models/checkout.rb +19 -0
- data/lib/coinbase/wallet/models/order.rb +12 -0
- data/lib/coinbase/wallet/models/transaction.rb +21 -0
- data/lib/coinbase/wallet/models/transfer.rb +13 -0
- data/lib/coinbase/wallet/models/user.rb +15 -0
- data/lib/coinbase/wallet/version.rb +5 -0
- data/lib/coinbase/wallet.rb +24 -156
- data/spec/account_spec.rb +199 -0
- data/spec/callback_signature_verification_spec.rb +16 -0
- data/spec/clients/client_spec.rb +34 -0
- data/spec/clients/oauth_client_spec.rb +56 -0
- data/spec/endpoints_spec.rb +352 -0
- data/spec/error_spec.rb +137 -0
- data/spec/models/address_spec.rb +26 -0
- data/spec/models/api_object_spec.rb +70 -0
- data/spec/models/checkout_spec.rb +52 -0
- data/spec/models/current_user_spec.rb +29 -0
- data/spec/models/order_spec.rb +52 -0
- data/spec/models/request_spec.rb +47 -0
- data/spec/models/transfer_spec.rb +64 -0
- data/spec/models/user_spec.rb +24 -0
- data/spec/spec_helper.rb +13 -0
- metadata +67 -112
- data/lib/coinbase/address.rb +0 -127
- data/lib/coinbase/asset.rb +0 -20
- data/lib/coinbase/balance_map.rb +0 -48
- data/lib/coinbase/constants.rb +0 -38
- data/lib/coinbase/network.rb +0 -55
- data/lib/coinbase/transfer.rb +0 -153
- data/lib/coinbase.rb +0 -18
@@ -0,0 +1,352 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet do
|
4
|
+
before :all do
|
5
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
6
|
+
end
|
7
|
+
|
8
|
+
#
|
9
|
+
# Data API
|
10
|
+
#
|
11
|
+
it "gets currencies" do
|
12
|
+
stub_request(:get, "https://api.coinbase.com/v2/currencies")
|
13
|
+
.to_return(body: { data: mock_collection }.to_json)
|
14
|
+
expect(@client.currencies).to eq mock_collection
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gets exchange rates" do
|
18
|
+
stub_request(:get, "https://api.coinbase.com/v2/exchange-rates")
|
19
|
+
.to_return(body: { data: mock_item }.to_json)
|
20
|
+
expect(@client.exchange_rates).to eq mock_item
|
21
|
+
end
|
22
|
+
|
23
|
+
it "gets buy price" do
|
24
|
+
stub_request(:get, "https://api.coinbase.com/v2/prices/BTC-USD/buy")
|
25
|
+
.to_return(body: { data: mock_item }.to_json)
|
26
|
+
expect(@client.buy_price).to eq mock_item
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets sell price" do
|
30
|
+
stub_request(:get, "https://api.coinbase.com/v2/prices/BTC-USD/sell")
|
31
|
+
.to_return(body: { data: mock_item }.to_json)
|
32
|
+
expect(@client.sell_price).to eq mock_item
|
33
|
+
end
|
34
|
+
|
35
|
+
it "gets spot price" do
|
36
|
+
stub_request(:get, "https://api.coinbase.com/v2/prices/BTC-USD/spot")
|
37
|
+
.to_return(body: { data: mock_item }.to_json)
|
38
|
+
expect(@client.spot_price).to eq mock_item
|
39
|
+
end
|
40
|
+
|
41
|
+
it "gets time" do
|
42
|
+
stub_request(:get, "https://api.coinbase.com/v2/time")
|
43
|
+
.to_return(body: { data: mock_item }.to_json)
|
44
|
+
expect(@client.time).to eq mock_item
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Wallet API
|
49
|
+
#
|
50
|
+
it "gets user" do
|
51
|
+
stub_request(:get, "https://api.coinbase.com/v2/users/test")
|
52
|
+
.to_return(body: { data: mock_item }.to_json)
|
53
|
+
expect(@client.user('test')).to eq mock_item
|
54
|
+
end
|
55
|
+
|
56
|
+
it "gets current user" do
|
57
|
+
stub_request(:get, "https://api.coinbase.com/v2/user")
|
58
|
+
.to_return(body: { data: mock_item }.to_json)
|
59
|
+
expect(@client.current_user).to eq mock_item
|
60
|
+
end
|
61
|
+
|
62
|
+
it "gets authorization info" do
|
63
|
+
stub_request(:get, "https://api.coinbase.com/v2/user/auth")
|
64
|
+
.to_return(body: { data: mock_item }.to_json)
|
65
|
+
expect(@client.auth_info).to eq mock_item
|
66
|
+
end
|
67
|
+
|
68
|
+
it "updates current user" do
|
69
|
+
stub_request(:put, "https://api.coinbase.com/v2/user")
|
70
|
+
.to_return(body: { data: mock_item }.to_json)
|
71
|
+
expect(@client.update_current_user(name: "test")).to eq mock_item
|
72
|
+
end
|
73
|
+
|
74
|
+
it "gets accounts" do
|
75
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts")
|
76
|
+
.to_return(body: { data: mock_collection }.to_json)
|
77
|
+
expect(@client.accounts).to eq mock_collection
|
78
|
+
end
|
79
|
+
|
80
|
+
it "gets account" do
|
81
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test")
|
82
|
+
.to_return(body: { data: mock_item }.to_json)
|
83
|
+
expect(@client.account("test")).to eq mock_item
|
84
|
+
end
|
85
|
+
|
86
|
+
it "gets account" do
|
87
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/primary")
|
88
|
+
.to_return(body: { data: mock_item }.to_json)
|
89
|
+
expect(@client.primary_account).to eq mock_item
|
90
|
+
end
|
91
|
+
|
92
|
+
it "creates account" do
|
93
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts")
|
94
|
+
.to_return(body: { data: mock_item }.to_json)
|
95
|
+
expect(@client.create_account).to eq mock_item
|
96
|
+
end
|
97
|
+
|
98
|
+
it "changes primary account" do
|
99
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/primary")
|
100
|
+
.to_return(body: { data: mock_item }.to_json)
|
101
|
+
expect(@client.set_primary_account("test")).to eq mock_item
|
102
|
+
end
|
103
|
+
|
104
|
+
it "updates accounts" do
|
105
|
+
stub_request(:put, "https://api.coinbase.com/v2/accounts/test")
|
106
|
+
.to_return(body: { data: mock_item }.to_json)
|
107
|
+
expect(@client.update_account("test", name: "new name")).to eq mock_item
|
108
|
+
end
|
109
|
+
|
110
|
+
it "deletes accounts" do
|
111
|
+
stub_request(:delete, "https://api.coinbase.com/v2/accounts/test")
|
112
|
+
.to_return(body: { data: mock_item }.to_json)
|
113
|
+
expect(@client.delete_account("test")).to eq mock_item
|
114
|
+
end
|
115
|
+
|
116
|
+
it "gets addresses" do
|
117
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/addresses")
|
118
|
+
.to_return(body: { data: mock_collection }.to_json)
|
119
|
+
expect(@client.addresses("test")).to eq mock_collection
|
120
|
+
end
|
121
|
+
|
122
|
+
it "gets address" do
|
123
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/addresses/test2")
|
124
|
+
.to_return(body: { data: mock_item }.to_json)
|
125
|
+
expect(@client.address("test1", "test2")).to eq mock_item
|
126
|
+
end
|
127
|
+
|
128
|
+
it "gets address transactions" do
|
129
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/addresses/test2/transactions")
|
130
|
+
.to_return(body: { data: mock_collection }.to_json)
|
131
|
+
expect(@client.address_transactions("test1", "test2")).to eq mock_collection
|
132
|
+
end
|
133
|
+
|
134
|
+
it "creates address" do
|
135
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/addresses")
|
136
|
+
.to_return(body: { data: mock_item }.to_json)
|
137
|
+
expect(@client.create_address("test1")).to eq mock_item
|
138
|
+
end
|
139
|
+
|
140
|
+
it "gets transactions" do
|
141
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/transactions")
|
142
|
+
.to_return(body: { data: mock_collection }.to_json)
|
143
|
+
expect(@client.transactions("test")).to eq mock_collection
|
144
|
+
end
|
145
|
+
|
146
|
+
it "gets transaction" do
|
147
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/transactions/test2")
|
148
|
+
.to_return(body: { data: mock_item }.to_json)
|
149
|
+
expect(@client.transaction("test1", "test2")).to eq mock_item
|
150
|
+
end
|
151
|
+
|
152
|
+
it "sends money" do
|
153
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/transactions")
|
154
|
+
.to_return(body: { data: mock_item }.to_json)
|
155
|
+
expect(@client.send("test", amount: 10, to: 'example@coinbase.com')).to eq mock_item
|
156
|
+
end
|
157
|
+
|
158
|
+
it "transfers money" do
|
159
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/transactions")
|
160
|
+
.to_return(body: { data: mock_item }.to_json)
|
161
|
+
expect(@client.transfer("test", amount: 10, to: 'example@coinbase.com')).to eq mock_item
|
162
|
+
end
|
163
|
+
|
164
|
+
it "requests money" do
|
165
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/transactions")
|
166
|
+
.to_return(body: { data: mock_item }.to_json)
|
167
|
+
expect(@client.request("test", amount: 10, currency: 'BTC', to: 'example@coinbase.com')).to eq mock_item
|
168
|
+
end
|
169
|
+
|
170
|
+
it "completes request" do
|
171
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/transactions/test2/complete")
|
172
|
+
.to_return(body: { data: mock_item }.to_json)
|
173
|
+
expect(@client.complete_request("test1", "test2")).to eq mock_item
|
174
|
+
end
|
175
|
+
|
176
|
+
it "re-sends request" do
|
177
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/transactions/test2/resend")
|
178
|
+
.to_return(body: { data: mock_item }.to_json)
|
179
|
+
expect(@client.resend_request("test1", "test2")).to eq mock_item
|
180
|
+
end
|
181
|
+
|
182
|
+
it "cancels request" do
|
183
|
+
stub_request(:delete, "https://api.coinbase.com/v2/accounts/test1/transactions/test2")
|
184
|
+
.to_return(body: { data: mock_item }.to_json)
|
185
|
+
expect(@client.cancel_request("test1", "test2")).to eq mock_item
|
186
|
+
end
|
187
|
+
|
188
|
+
it "lists buys" do
|
189
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/buys")
|
190
|
+
.to_return(body: { data: mock_collection }.to_json)
|
191
|
+
expect(@client.list_buys("test")).to eq mock_collection
|
192
|
+
end
|
193
|
+
|
194
|
+
it "lists buy" do
|
195
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/buys/test2")
|
196
|
+
.to_return(body: { data: mock_item }.to_json)
|
197
|
+
expect(@client.list_buy("test1", "test2")).to eq mock_item
|
198
|
+
end
|
199
|
+
|
200
|
+
it "buys bitcoin" do
|
201
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/buys")
|
202
|
+
.to_return(body: { data: mock_item }.to_json)
|
203
|
+
expect(@client.buy("test", amount: 10, currency: 'BTC')).to eq mock_item
|
204
|
+
end
|
205
|
+
|
206
|
+
it "commits buy" do
|
207
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/buys/test2/commit")
|
208
|
+
.to_return(body: { data: mock_item }.to_json)
|
209
|
+
expect(@client.commit_buy("test1", "test2")).to eq mock_item
|
210
|
+
end
|
211
|
+
|
212
|
+
it "lists sells" do
|
213
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/sells")
|
214
|
+
.to_return(body: { data: mock_collection }.to_json)
|
215
|
+
expect(@client.list_sells("test")).to eq mock_collection
|
216
|
+
end
|
217
|
+
|
218
|
+
it "lists sell" do
|
219
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/sells/test2")
|
220
|
+
.to_return(body: { data: mock_item }.to_json)
|
221
|
+
expect(@client.list_sell("test1", "test2")).to eq mock_item
|
222
|
+
end
|
223
|
+
|
224
|
+
it "sells bitcoin" do
|
225
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/sells")
|
226
|
+
.to_return(body: { data: mock_item }.to_json)
|
227
|
+
expect(@client.sell("test", amount: 10, currency: 'BTC')).to eq mock_item
|
228
|
+
end
|
229
|
+
|
230
|
+
it "commits sell" do
|
231
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/sells/test2/commit")
|
232
|
+
.to_return(body: { data: mock_item }.to_json)
|
233
|
+
expect(@client.commit_sell("test1", "test2")).to eq mock_item
|
234
|
+
end
|
235
|
+
|
236
|
+
it "lists deposits" do
|
237
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/deposits")
|
238
|
+
.to_return(body: { data: mock_collection }.to_json)
|
239
|
+
expect(@client.list_deposits("test")).to eq mock_collection
|
240
|
+
end
|
241
|
+
|
242
|
+
it "lists deposit" do
|
243
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/deposits/test2")
|
244
|
+
.to_return(body: { data: mock_item }.to_json)
|
245
|
+
expect(@client.list_deposit("test1", "test2")).to eq mock_item
|
246
|
+
end
|
247
|
+
|
248
|
+
it "deposits bitcoin" do
|
249
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/deposits")
|
250
|
+
.to_return(body: { data: mock_item }.to_json)
|
251
|
+
expect(@client.deposit("test", amount: 10, currency: 'BTC')).to eq mock_item
|
252
|
+
end
|
253
|
+
|
254
|
+
it "commits deposit" do
|
255
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/deposits/test2/commit")
|
256
|
+
.to_return(body: { data: mock_item }.to_json)
|
257
|
+
expect(@client.commit_deposit("test1", "test2")).to eq mock_item
|
258
|
+
end
|
259
|
+
|
260
|
+
it "lists withdrawals" do
|
261
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test/withdrawals")
|
262
|
+
.to_return(body: { data: mock_collection }.to_json)
|
263
|
+
expect(@client.list_withdrawals("test")).to eq mock_collection
|
264
|
+
end
|
265
|
+
|
266
|
+
it "lists withdrawal" do
|
267
|
+
stub_request(:get, "https://api.coinbase.com/v2/accounts/test1/withdrawals/test2")
|
268
|
+
.to_return(body: { data: mock_item }.to_json)
|
269
|
+
expect(@client.list_withdrawal("test1", "test2")).to eq mock_item
|
270
|
+
end
|
271
|
+
|
272
|
+
it "withdrawals bitcoin" do
|
273
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test/withdrawals")
|
274
|
+
.to_return(body: { data: mock_item }.to_json)
|
275
|
+
expect(@client.withdraw("test", amount: 10, currency: 'BTC')).to eq mock_item
|
276
|
+
end
|
277
|
+
|
278
|
+
it "commits withdrawal" do
|
279
|
+
stub_request(:post, "https://api.coinbase.com/v2/accounts/test1/withdrawals/test2/commit")
|
280
|
+
.to_return(body: { data: mock_item }.to_json)
|
281
|
+
expect(@client.commit_withdrawal("test1", "test2")).to eq mock_item
|
282
|
+
end
|
283
|
+
|
284
|
+
it "gets payment methods" do
|
285
|
+
stub_request(:get, "https://api.coinbase.com/v2/payment-methods")
|
286
|
+
.to_return(body: { data: mock_collection }.to_json)
|
287
|
+
expect(@client.payment_methods).to eq mock_collection
|
288
|
+
end
|
289
|
+
|
290
|
+
#
|
291
|
+
# Merchant API
|
292
|
+
#
|
293
|
+
it "gets merchant" do
|
294
|
+
stub_request(:get, "https://api.coinbase.com/v2/merchants/test")
|
295
|
+
.to_return(body: { data: mock_item }.to_json)
|
296
|
+
expect(@client.merchant('test')).to eq mock_item
|
297
|
+
end
|
298
|
+
|
299
|
+
it "gets merchant orders" do
|
300
|
+
stub_request(:get, "https://api.coinbase.com/v2/orders")
|
301
|
+
.to_return(body: { data: mock_collection }.to_json)
|
302
|
+
expect(@client.orders).to eq mock_collection
|
303
|
+
end
|
304
|
+
|
305
|
+
it "gets merchant order" do
|
306
|
+
stub_request(:get, "https://api.coinbase.com/v2/orders/test")
|
307
|
+
.to_return(body: { data: mock_item }.to_json)
|
308
|
+
expect(@client.order("test")).to eq mock_item
|
309
|
+
end
|
310
|
+
|
311
|
+
it "creates an order" do
|
312
|
+
stub_request(:post, "https://api.coinbase.com/v2/orders")
|
313
|
+
.to_return(body: { data: mock_item }.to_json)
|
314
|
+
expect(@client.create_order(name: "test", amount: 10, currency: "BTC")).to eq mock_item
|
315
|
+
end
|
316
|
+
|
317
|
+
it "refunds merchant order" do
|
318
|
+
stub_request(:post, "https://api.coinbase.com/v2/orders/test/refund")
|
319
|
+
.to_return(body: { data: mock_item }.to_json)
|
320
|
+
expect(@client.refund_order("test", currency: "BTC")).to eq mock_item
|
321
|
+
end
|
322
|
+
|
323
|
+
it "gets checkouts" do
|
324
|
+
stub_request(:get, "https://api.coinbase.com/v2/checkouts")
|
325
|
+
.to_return(body: { data: mock_collection }.to_json)
|
326
|
+
expect(@client.checkouts).to eq mock_collection
|
327
|
+
end
|
328
|
+
|
329
|
+
it "gets checkout" do
|
330
|
+
stub_request(:get, "https://api.coinbase.com/v2/checkouts/test")
|
331
|
+
.to_return(body: { data: mock_item }.to_json)
|
332
|
+
expect(@client.checkout("test")).to eq mock_item
|
333
|
+
end
|
334
|
+
|
335
|
+
it "creates checkout" do
|
336
|
+
stub_request(:post, "https://api.coinbase.com/v2/checkouts")
|
337
|
+
.to_return(body: { data: mock_item }.to_json)
|
338
|
+
expect(@client.create_checkout(name: "test", amount: 10, currency: "BTC")).to eq mock_item
|
339
|
+
end
|
340
|
+
|
341
|
+
it "gets checkout orders" do
|
342
|
+
stub_request(:get, "https://api.coinbase.com/v2/checkouts/test/orders")
|
343
|
+
.to_return(body: { data: mock_collection }.to_json)
|
344
|
+
expect(@client.checkout_orders("test")).to eq mock_collection
|
345
|
+
end
|
346
|
+
|
347
|
+
it "creates checkout order" do
|
348
|
+
stub_request(:post, "https://api.coinbase.com/v2/checkouts/test/orders")
|
349
|
+
.to_return(body: { data: mock_item }.to_json)
|
350
|
+
expect(@client.create_checkout_order("test")).to eq mock_item
|
351
|
+
end
|
352
|
+
end
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet do
|
4
|
+
before :all do
|
5
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "passes" do
|
9
|
+
expect(1).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "handles param_required" do
|
13
|
+
stub_request(:get, /.*/)
|
14
|
+
.to_return(body: { errors: [{ id: 'param_required', message: 'test' }] }.to_json,
|
15
|
+
status: 400)
|
16
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::ParamRequiredError
|
17
|
+
end
|
18
|
+
|
19
|
+
it "handles invalid_request" do
|
20
|
+
stub_request(:get, /.*/)
|
21
|
+
.to_return(body: { errors: [{ id: 'invalid_request', message: 'test' }] }.to_json,
|
22
|
+
status: 400)
|
23
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::InvalidRequestError
|
24
|
+
end
|
25
|
+
|
26
|
+
it "handles personal_details_required" do
|
27
|
+
stub_request(:get, /.*/)
|
28
|
+
.to_return(body: { errors: [{ id: 'personal_details_required', message: 'test' }] }.to_json,
|
29
|
+
status: 400)
|
30
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::PersonalDetailsRequiredError
|
31
|
+
end
|
32
|
+
|
33
|
+
it "handles obscure 400" do
|
34
|
+
stub_request(:get, /.*/)
|
35
|
+
.to_return(body: { errors: [{ id: 'obscure_400', message: 'test' }] }.to_json,
|
36
|
+
status: 400)
|
37
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::BadRequestError
|
38
|
+
end
|
39
|
+
|
40
|
+
it "handles authentication_error" do
|
41
|
+
stub_request(:get, /.*/)
|
42
|
+
.to_return(body: { errors: [{ id: 'authentication_error', message: 'test' }] }.to_json,
|
43
|
+
status: 401)
|
44
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::AuthenticationError
|
45
|
+
end
|
46
|
+
|
47
|
+
it "handles unverified_email" do
|
48
|
+
stub_request(:get, /.*/)
|
49
|
+
.to_return(body: { errors: [{ id: 'unverified_email', message: 'test' }] }.to_json,
|
50
|
+
status: 401)
|
51
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::UnverifiedEmailError
|
52
|
+
end
|
53
|
+
|
54
|
+
it "handles invalid_token" do
|
55
|
+
stub_request(:get, /.*/)
|
56
|
+
.to_return(body: { errors: [{ id: 'invalid_token', message: 'test' }] }.to_json,
|
57
|
+
status: 401)
|
58
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::InvalidTokenError
|
59
|
+
end
|
60
|
+
|
61
|
+
it "handles revoked_token" do
|
62
|
+
stub_request(:get, /.*/)
|
63
|
+
.to_return(body: { errors: [{ id: 'revoked_token', message: 'test' }] }.to_json,
|
64
|
+
status: 401)
|
65
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::RevokedTokenError
|
66
|
+
end
|
67
|
+
|
68
|
+
it "handles expired_token" do
|
69
|
+
stub_request(:get, /.*/)
|
70
|
+
.to_return(body: { errors: [{ id: 'expired_token', message: 'test' }] }.to_json,
|
71
|
+
status: 401)
|
72
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::ExpiredTokenError
|
73
|
+
end
|
74
|
+
|
75
|
+
it "handles obscure 401" do
|
76
|
+
stub_request(:get, /.*/)
|
77
|
+
.to_return(body: { errors: [{ id: 'obscure_401', message: 'test' }] }.to_json,
|
78
|
+
status: 401)
|
79
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::AuthenticationError
|
80
|
+
end
|
81
|
+
|
82
|
+
it "handles 402" do
|
83
|
+
stub_request(:get, /.*/)
|
84
|
+
.to_return(body: { errors: [{ id: '402', message: 'test' }] }.to_json,
|
85
|
+
status: 402)
|
86
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::TwoFactorRequiredError
|
87
|
+
end
|
88
|
+
|
89
|
+
it "handles 403" do
|
90
|
+
stub_request(:get, /.*/)
|
91
|
+
.to_return(body: { errors: [{ id: '403', message: 'test' }] }.to_json,
|
92
|
+
status: 403)
|
93
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::InvalidScopeError
|
94
|
+
end
|
95
|
+
|
96
|
+
it "handles 404" do
|
97
|
+
stub_request(:get, /.*/)
|
98
|
+
.to_return(body: { errors: [{ id: '404', message: 'test' }] }.to_json,
|
99
|
+
status: 404)
|
100
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::NotFoundError
|
101
|
+
end
|
102
|
+
|
103
|
+
it "handles 422" do
|
104
|
+
stub_request(:get, /.*/)
|
105
|
+
.to_return(body: { errors: [{ id: '422', message: 'test' }] }.to_json,
|
106
|
+
status: 422)
|
107
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::ValidationError
|
108
|
+
end
|
109
|
+
|
110
|
+
it "handles 429" do
|
111
|
+
stub_request(:get, /.*/)
|
112
|
+
.to_return(body: { errors: [{ id: '429', message: 'test' }] }.to_json,
|
113
|
+
status: 429)
|
114
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::RateLimitError
|
115
|
+
end
|
116
|
+
|
117
|
+
it "handles 500" do
|
118
|
+
stub_request(:get, /.*/)
|
119
|
+
.to_return(body: { errors: [{ id: '500', message: 'test' }] }.to_json,
|
120
|
+
status: 500)
|
121
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::InternalServerError
|
122
|
+
end
|
123
|
+
|
124
|
+
it "handles 503" do
|
125
|
+
stub_request(:get, /.*/)
|
126
|
+
.to_return(body: { errors: [{ id: '503', message: 'test' }] }.to_json,
|
127
|
+
status: 503)
|
128
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::ServiceUnavailableError
|
129
|
+
end
|
130
|
+
|
131
|
+
it "handles oauth exception" do
|
132
|
+
stub_request(:get, /.*/)
|
133
|
+
.to_return(body: { error: "invalid_request", error_description: "test"}.to_json,
|
134
|
+
status: 401)
|
135
|
+
expect { @client.primary_account }.to raise_error Coinbase::Wallet::APIError
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet::Address do
|
4
|
+
before :all do
|
5
|
+
@object_data = {
|
6
|
+
'id' => 'dd3183eb-af1d-5f5d-a90d-cbff946435ff',
|
7
|
+
'address' => 'mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa',
|
8
|
+
'name' => 'One off payment',
|
9
|
+
'created_at' => '2015-01-31T20:49:02Z',
|
10
|
+
'updated_at' => '2015-03-31T17:25:29-07:00',
|
11
|
+
'resource' => 'address',
|
12
|
+
'resource_path' => '/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/addresses/dd3183eb-af1d-5f5d-a90d-cbff946435ff'
|
13
|
+
}
|
14
|
+
|
15
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
16
|
+
@object = Coinbase::Wallet::Address.new(@client, @object_data)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#transactions' do
|
20
|
+
it 'should get latest transactions for address' do
|
21
|
+
stub_request(:get, 'https://api.coinbase.com' + @object_data['resource_path'] + '/transactions')
|
22
|
+
.to_return(body: { data: [mock_item] }.to_json)
|
23
|
+
expect(@object.transactions).to eq [mock_item]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet::APIObject do
|
4
|
+
before :all do
|
5
|
+
@object_data = {
|
6
|
+
'id' => '2bbf394c-193b-5b2a-9155-3b4732659ede',
|
7
|
+
'name' => 'My Wallet',
|
8
|
+
'primary' => true,
|
9
|
+
'type' => 'wallet',
|
10
|
+
'currency' => 'BTC',
|
11
|
+
'balance' => {
|
12
|
+
'amount' => '39.59000000',
|
13
|
+
'currency' => 'BTC'
|
14
|
+
},
|
15
|
+
'native_balance' => {
|
16
|
+
'amount' => '395.90',
|
17
|
+
'currency' => 'USD'
|
18
|
+
},
|
19
|
+
'created_at' => '2015-01-31T20:49:02Z',
|
20
|
+
'updated_at' => '2015-01-31T20:49:02Z',
|
21
|
+
'resource' => 'account',
|
22
|
+
'resource_path' => '/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede'
|
23
|
+
}
|
24
|
+
|
25
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
26
|
+
@object = Coinbase::Wallet::APIObject.new(@client, @object_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should access attributes' do
|
30
|
+
expect(@object.id).to eq @object_data['id']
|
31
|
+
expect(@object.balance.currency).to eq @object_data['balance']['currency']
|
32
|
+
expect(@object.primary).to eq @object_data['primary']
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should convert hashes to APIObjects' do
|
36
|
+
expect(@object.balance.class).to eq Coinbase::Wallet::APIObject
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should convert amounts to BigDecimal' do
|
40
|
+
expect(@object.balance.amount.class).to eq BigDecimal
|
41
|
+
expect(@object.native_balance.amount.to_f).to eq 395.90
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should convert timestamps to Time' do
|
45
|
+
expect(@object.created_at.class).to eq Time
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#format' do
|
49
|
+
it 'should convert negative amounts to BigDecimal' do
|
50
|
+
ret = @object.format('amount', '-0.1234')
|
51
|
+
expect(ret).to eq BigDecimal('-0.1234')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#update' do
|
56
|
+
it 'should update object' do
|
57
|
+
@object.update({'id' => '1234'})
|
58
|
+
expect(@object.id).to eq '1234'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#refresh!' do
|
63
|
+
it 'should fetch new data for object' do
|
64
|
+
stub_request(:get, 'https://api.coinbase.com' + @object_data['resource_path'])
|
65
|
+
.to_return(body: { data: { id: 'new_id' } }.to_json)
|
66
|
+
@object.refresh!
|
67
|
+
expect(@object.id).to eq 'new_id'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet::Checkout do
|
4
|
+
before :all do
|
5
|
+
@object_data = {
|
6
|
+
'id' => 'ffc93ba1-874d-5c55-853c-53c9c4814b1e',
|
7
|
+
'embed_code' => 'af0b52802ad7b36806e307b2d294e3b4',
|
8
|
+
'type' => 'order',
|
9
|
+
'name' => 'My Checkout',
|
10
|
+
'description' => nil,
|
11
|
+
'amount' => {
|
12
|
+
'amount' => '99.00000000',
|
13
|
+
'currency' => 'BTC'
|
14
|
+
},
|
15
|
+
'style' => 'buy_now_large',
|
16
|
+
'customer_defined_amount' => false,
|
17
|
+
'amount_presets' => [],
|
18
|
+
'success_url' => nil,
|
19
|
+
'cancel_url' => nil,
|
20
|
+
'info_url' => nil,
|
21
|
+
'auto_redirect' => false,
|
22
|
+
'collect_shipping_address' => false,
|
23
|
+
'collect_email' => false,
|
24
|
+
'collect_phone_number' => false,
|
25
|
+
'collect_country' => false,
|
26
|
+
'metadata' => {},
|
27
|
+
'created_at' => '2015-01-31T20:49:02Z',
|
28
|
+
'updated_at' => '2015-01-31T20:49:02Z',
|
29
|
+
'resource' => 'checkout',
|
30
|
+
'resource_path' => '/v2/checkouts/ffc93ba1-874d-5c55-853c-53c9c4814b1e'
|
31
|
+
}
|
32
|
+
|
33
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
34
|
+
@object = Coinbase::Wallet::Checkout.new(@client, @object_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#orders' do
|
38
|
+
it 'should get latest order' do
|
39
|
+
stub_request(:get, 'https://api.coinbase.com' + @object_data['resource_path'] + '/orders')
|
40
|
+
.to_return(body: { data: [mock_item] }.to_json)
|
41
|
+
expect(@object.orders).to eq [mock_item]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#create_order' do
|
46
|
+
it 'should create a new order' do
|
47
|
+
stub_request(:post, 'https://api.coinbase.com' + @object_data['resource_path'] + '/orders')
|
48
|
+
.to_return(body: { data: mock_item }.to_json)
|
49
|
+
expect(@object.create_order).to eq mock_item
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coinbase::Wallet::CurrentUser do
|
4
|
+
before :all do
|
5
|
+
@user_data = {
|
6
|
+
'id' => '9da7a204-544e-5fd1-9a12-61176c5d4cd8',
|
7
|
+
'name' => 'User One',
|
8
|
+
'username' => 'user1',
|
9
|
+
'profile_location' => nil,
|
10
|
+
'profile_bio' => nil,
|
11
|
+
'profile_url' => 'https://coinbase.com/user1',
|
12
|
+
'avatar_url' => 'https://images.coinbase.com/avatar?h=vR%2FY8igBoPwuwGren5JMwvDNGpURAY%2F0nRIOgH%2FY2Qh%2BQ6nomR3qusA%2Bh6o2%0Af9rH&s=128',
|
13
|
+
'resource' => 'user',
|
14
|
+
'resource_path' => '/v2/user'
|
15
|
+
}
|
16
|
+
|
17
|
+
@client = Coinbase::Wallet::Client.new(api_key: 'api_key', api_secret: 'api_secret')
|
18
|
+
@user = Coinbase::Wallet::CurrentUser.new(@client, @user_data)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#update!' do
|
22
|
+
it 'should update new data for object' do
|
23
|
+
stub_request(:put, 'https://api.coinbase.com' + @user_data['resource_path'])
|
24
|
+
.to_return(body: { data: { name: 'james smith' } }.to_json)
|
25
|
+
@user.update!(name: 'james smith')
|
26
|
+
expect(@user.name).to eq 'james smith'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|