coinbase 0.0.1 → 4.2.0

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.

Potentially problematic release.


This version of coinbase might be problematic. Click here for more details.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +7 -0
  4. data/CONTRIBUTING.md +53 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +201 -0
  7. data/README.md +615 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/coinbase.gemspec +26 -0
  12. data/lib/coinbase/util.rb +16 -0
  13. data/lib/coinbase/wallet/adapters/em_http.rb +78 -0
  14. data/lib/coinbase/wallet/adapters/net_http.rb +68 -0
  15. data/lib/coinbase/wallet/api_client.rb +755 -0
  16. data/lib/coinbase/wallet/api_errors.rb +120 -0
  17. data/lib/coinbase/wallet/api_response.rb +41 -0
  18. data/lib/coinbase/wallet/ca-coinbase.crt +78 -0
  19. data/lib/coinbase/wallet/client.rb +101 -0
  20. data/lib/coinbase/wallet/coinbase-callback.pub +14 -0
  21. data/lib/coinbase/wallet/models/account.rb +193 -0
  22. data/lib/coinbase/wallet/models/address.rb +12 -0
  23. data/lib/coinbase/wallet/models/api_object.rb +46 -0
  24. data/lib/coinbase/wallet/models/checkout.rb +19 -0
  25. data/lib/coinbase/wallet/models/order.rb +12 -0
  26. data/lib/coinbase/wallet/models/transaction.rb +21 -0
  27. data/lib/coinbase/wallet/models/transfer.rb +13 -0
  28. data/lib/coinbase/wallet/models/user.rb +15 -0
  29. data/lib/coinbase/wallet/version.rb +5 -0
  30. data/lib/coinbase/wallet.rb +24 -156
  31. data/spec/account_spec.rb +199 -0
  32. data/spec/callback_signature_verification_spec.rb +16 -0
  33. data/spec/clients/client_spec.rb +34 -0
  34. data/spec/clients/oauth_client_spec.rb +56 -0
  35. data/spec/endpoints_spec.rb +352 -0
  36. data/spec/error_spec.rb +137 -0
  37. data/spec/models/address_spec.rb +26 -0
  38. data/spec/models/api_object_spec.rb +63 -0
  39. data/spec/models/checkout_spec.rb +52 -0
  40. data/spec/models/current_user_spec.rb +29 -0
  41. data/spec/models/order_spec.rb +52 -0
  42. data/spec/models/request_spec.rb +47 -0
  43. data/spec/models/transfer_spec.rb +64 -0
  44. data/spec/models/user_spec.rb +24 -0
  45. data/spec/spec_helper.rb +13 -0
  46. metadata +66 -110
  47. data/lib/coinbase/address.rb +0 -127
  48. data/lib/coinbase/asset.rb +0 -20
  49. data/lib/coinbase/balance_map.rb +0 -48
  50. data/lib/coinbase/constants.rb +0 -38
  51. data/lib/coinbase/network.rb +0 -55
  52. data/lib/coinbase/transfer.rb +0 -153
  53. data/lib/coinbase.rb +0 -18
data/README.md ADDED
@@ -0,0 +1,615 @@
1
+ # Coinbase Wallet Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/coinbase.svg)](https://badge.fury.io/rb/coinbase)
4
+ [![Build Status](https://travis-ci.org/coinbase/coinbase-ruby.svg?branch=master)](https://travis-ci.org/coinbase/coinbase-ruby)
5
+
6
+ This is the official client library for the [Coinbase Wallet API v2](https://developers.coinbase.com/api/v2). We provide an intuitive, stable interface to integrate Coinbase Wallet into your Ruby project.
7
+
8
+ _Important:_ As this library is targeted for newer API v2, it requires v2 permissions (i.e. `wallet:accounts:read`). If you're still using v1, please use [older version](https://github.com/coinbase/coinbase-ruby/releases/tag/v2.1.1) of this library.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'coinbase'
15
+
16
+ Then execute:
17
+
18
+ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ gem install coinbase
23
+
24
+ ## Authentication
25
+
26
+ ### API Key (HMAC Client)
27
+
28
+ We provide a synchronous client based on Net::HTTP as well as a asynchronous client based on the EM-HTTP-Request gem. For most users, the synchronous client will suffice.
29
+
30
+ ```ruby
31
+ require 'coinbase/wallet'
32
+ client = Coinbase::Wallet::Client.new(api_key: <api key>, api_secret: <api secret>)
33
+ ```
34
+
35
+ The primary intention of the asynchronous client is to integrate nicely with the [Coinbase Exchange Gem](https://github.com/coinbase/coinbase-exchange-ruby). If your project interfaces with our Exchange as well, please consider using this. *To use this interface, you must include em-http-request gem on your own.*
36
+
37
+ ```ruby
38
+ require 'coinbase/wallet'
39
+ require 'em-http'
40
+
41
+ client = Coinbase::Wallet::AsyncClient.new(api_key: <api_key>, api_secret: <api secret>)
42
+ ```
43
+
44
+ ### OAuth2 Client
45
+
46
+ We provide an OAuth client if you need access to user accounts other than your own. Currently, the gem does not handle the handshake process, and assumes you have an access token when it's initialized. The OAuth client is synchronous. Please reach out if you would like us to add an asynchronous OAuth client as well.
47
+
48
+ ```ruby
49
+ require 'coinbase/wallet'
50
+
51
+ # Initializing OAuthClient with both access and refresh token
52
+ client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>, refresh_token: <refresh_token>)
53
+
54
+ # Initializing OAuthClient with only access token
55
+ client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>)
56
+ ```
57
+
58
+ The OAuth client provides a few extra methods to refresh and revoke the access token.
59
+
60
+ ```ruby
61
+ client.refresh!
62
+ ```
63
+
64
+ ```ruby
65
+ client.revoke!
66
+ ```
67
+
68
+ _Protip:tm::_ You can test OAuth2 authentication easily with Developer Access Tokens which can be created under your [OAuth2 application settings](https://www.coinbase.com/settings/api). These are short lived tokens which authenticate but don't require full OAuth2 handshake to obtain.
69
+
70
+ #### Two factor authentication
71
+
72
+ Send money endpoint requires 2FA token in certain situations (read more [here](https://developers.coinbase.com/docs/wallet/coinbase-connect#two-factor-authentication)). Specific exception is thrown when this is required:
73
+
74
+ ```ruby
75
+ account = client.primary_account
76
+ begin
77
+ account.send(to: 'test@test.com', amount: '1', currency: "BTC")
78
+ rescue Coinbase::Client::TwoFactorRequiredError
79
+ # Show 2FA dialog to user and collect 2FA token
80
+
81
+ # Re-try call with `two_factor_token` param
82
+ account.send(to: 'test@test.com', amount: '1', currency: "BTC", two_factor_token: "123456")
83
+ end
84
+ ```
85
+
86
+ ## Requests
87
+
88
+ We provide one method per API endpoint. Several methods require one or more identifiers to be passed as arguments. Additionally, all parameters can be appended as [keyword arguements](https://robots.thoughtbot.com/ruby-2-keyword-arguments). If a required parameter is not supplied, the client will raise an error. For instance, the following call will send 100 bitcoin to the account registered with example@coinbase.com.
89
+
90
+ ```ruby
91
+ account = client.primary_account
92
+ account.send(to: 'example@coinbase.com', amount: 100, currency: "USD", description: 'Sending 100 bitcoin')
93
+ ```
94
+
95
+ ### Pagination
96
+
97
+ Several endpoints are [paginated](https://developers.coinbase.com/api/v2#pagination). By default, the gem will only fetch the first page of data for a given request. You can implement your own pagination scheme, such as [pipelining](https://en.wikipedia.org/wiki/HTTP_pipelining), by setting the starting_after parameter in your response.
98
+
99
+ ```ruby
100
+ client.transactions(account_id) do |data, resp|
101
+ transactions = data
102
+ end
103
+
104
+ more_pages = true
105
+ while more_pages
106
+ client.transactions(account_id, starting_after: transactions.last['id']) do |data, resp|
107
+ more_pages = resp.has_more?
108
+ transactions << data
109
+ transactions.flatten!
110
+ end
111
+ end
112
+ ```
113
+
114
+ If you want to automatically download the entire dataset, you may pass `fetch_all=true` as a parameter.
115
+
116
+ ```ruby
117
+ client.transactions(account_id, fetch_all: true) do |data, resp|
118
+ ...
119
+ end
120
+ ```
121
+
122
+ ## Responses
123
+
124
+ We provide several ways to access return data. Methods will return the data field of the response in hash format.
125
+
126
+ ```ruby
127
+ txs = account.transactions(account_id)
128
+ txs.each do |tx|
129
+ p tx['id']
130
+ end
131
+ ```
132
+
133
+ You can also handle data inside a block you pass to the method. **You must access data this way if you're using the asynchronous client.**
134
+
135
+ ```ruby
136
+ account.transactions(account_id) do |txs|
137
+ txs.each { |tx| p tx['id'] }
138
+ end
139
+ ```
140
+
141
+ If you need to access the response metadata (headers, pagination info, etc.) you can access the entire response as the second block paramenter.
142
+
143
+ ```ruby
144
+ account.transactions(account_id) do |txs, resp|
145
+ p "STATUS: #{resp.status}"
146
+ p "HEADERS: #{resp.headers}"
147
+ p "BODY: #{resp.body}"
148
+ end
149
+ ```
150
+
151
+ **Response Object**
152
+
153
+ The default representation of response data is a JSON hash. However, we further abstract the response to allow access to response fields as though they were methods.
154
+
155
+ ```ruby
156
+ account = client.primary_account
157
+ p "Account:\t account.name"
158
+ p "ID:\t account.id"
159
+ p "Balance:\t #{account.balance.amount} #{account.balance.currency}"
160
+ ```
161
+
162
+ All values are returned directly from the API unmodified, except the following exceptions:
163
+
164
+ - [Money amounts](https://developers.coinbase.com/api/v2#money-hash) are always converted into [BigDecimal](http://ruby-doc.org/stdlib-2.1.1/libdoc/bigdecimal/rdoc/BigDecimal.html) objects. You should always use BigDecimal when handing bitcoin amounts for accurate precision.
165
+ - [Timestamps](https://developers.coinbase.com/api/v2#timestamps) are always converted into [Time](http://ruby-doc.org/stdlib-2.1.1/libdoc/time/rdoc/Time.html) objects.
166
+
167
+ Most methods require an associated account. Thus, responses for the [account endpoints](https://developers.coinbase.com/api/v2#accounts) contain methods for accessing all the relevant endpoints. This is convenient, as it doesn't require you to supply the same account id over and over again.
168
+
169
+ ```ruby
170
+ account = client.primary_account
171
+ account.send(to: "example@coinbase.com", amount: 100, description: "Sending 100 bitcoin")
172
+ ```
173
+
174
+ Alternatively you can pass the account ID straight to the client:
175
+
176
+ ```ruby
177
+ client.transactions(<account_id>)
178
+ ```
179
+
180
+ Account response objects will automatically update if they detect any changes to the account. The easiest way to refresh an account is to call the refresh! method.
181
+
182
+ ```ruby
183
+ account.refresh!
184
+ ```
185
+
186
+ ### Warnings
187
+
188
+ It's prudent to be conscious of warnings. By default, the gem will print all warning to STDERR. If you wish to redirect this stream to somewhere else, such as a log file, then you can simply [change the $stderr global variable](http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby).
189
+
190
+ ### Errors
191
+
192
+ If the request is not successful, the gem will raise an error. We try to raise a unique error for every possible API response. All errors are subclasses of `Coinbase::Wallet::APIError`.
193
+
194
+ |Error|Status|
195
+ |---|---|
196
+ |APIError|*|
197
+ |BadRequestError|400|
198
+ |ParamRequiredError|400|
199
+ |InvalidRequestError|400|
200
+ |PersonalDetailsRequiredError|400|
201
+ |AuthenticationError|401|
202
+ |UnverifiedEmailError|401|
203
+ |InvalidTokenError|401|
204
+ |RevokedTokenError|401|
205
+ |ExpiredTokenError|401|
206
+ |TwoFactorRequiredError|402|
207
+ |InvalidScopeError|403|
208
+ |NotFoundError|404|
209
+ |ValidationError|422|
210
+ |RateLimitError|429|
211
+ |InternalServerError|500|
212
+ |ServiceUnavailableError|503|
213
+
214
+ ## Usage
215
+
216
+ This is not intended to provide complete documentation of the API. For more detail, please refer to the [official documentation](https://developers.coinbase.com/api/v2).
217
+
218
+ ### [Market Data](https://developers.coinbase.com/api/v2#data-api)
219
+
220
+ **List supported native currencies**
221
+
222
+ ```ruby
223
+ client.currencies
224
+ ```
225
+
226
+ **List exchange rates**
227
+
228
+ ```ruby
229
+ client.exchange_rates
230
+ ```
231
+
232
+ **Buy price**
233
+
234
+ ```ruby
235
+ client.buy_price
236
+ # or
237
+ client.buy_price(currency_pair: 'BTC-USD')
238
+ ```
239
+
240
+ **Sell price**
241
+
242
+ ```ruby
243
+ client.sell_price
244
+ # or
245
+ client.sell_price(currency_pair: 'ETH-BTC')
246
+ ```
247
+
248
+ **Spot price**
249
+
250
+ ```ruby
251
+ client.spot_price
252
+ # or
253
+ client.spot_price(currency_pair: 'BTC-EUR')
254
+ ```
255
+
256
+ **Current server time**
257
+
258
+ ```ruby
259
+ client.time
260
+ ```
261
+
262
+ ### [Users](https://developers.coinbase.com/api/v2#users)
263
+
264
+ **Get authorization info**
265
+
266
+ ```ruby
267
+ client.auth_info
268
+ ```
269
+
270
+ **Lookup user info**
271
+
272
+ ```ruby
273
+ client.user(user_id)
274
+ ```
275
+
276
+ **Get current user**
277
+
278
+ ```ruby
279
+ client.current_user
280
+ ```
281
+
282
+ **Update current user**
283
+
284
+ ```ruby
285
+ client.update_current_user(name: "New Name")
286
+ ```
287
+
288
+ ### [Accounts](https://developers.coinbase.com/api/v2#accounts)
289
+
290
+ **List all accounts**
291
+
292
+ ```ruby
293
+ client.accounts
294
+ ```
295
+
296
+ **List account details**
297
+
298
+ ```ruby
299
+ client.account(account_id)
300
+ ```
301
+
302
+ **List primary account details**
303
+
304
+ ```ruby
305
+ client.primary_account
306
+ ```
307
+
308
+ **Set account as primary**
309
+
310
+ ```ruby
311
+ account.make_primary!
312
+ ```
313
+
314
+ **Create a new bitcoin account**
315
+
316
+ ```ruby
317
+ client.create_account(name: "New Account")
318
+ ```
319
+
320
+ **Update an account**
321
+
322
+ ```ruby
323
+ account.update!(name: "New Account Name")
324
+ ```
325
+
326
+ **Delete an account**
327
+
328
+ ```ruby
329
+ account.delete!
330
+ ```
331
+
332
+ ### [Addresses](https://developers.coinbase.com/api/v2#addresses)
333
+
334
+ **List receive addresses for account**
335
+
336
+ ```ruby
337
+ account.addresses
338
+ ```
339
+
340
+ **Get receive address info**
341
+
342
+ ```ruby
343
+ account.address(address_id)
344
+ ```
345
+
346
+ **List transactiona for address**
347
+
348
+ ```ruby
349
+ account.address_transactions(address_id)
350
+ ```
351
+
352
+ **Create a new receive address**
353
+
354
+ ```ruby
355
+ account.create_address
356
+ ```
357
+
358
+ ### [Transactions](https://developers.coinbase.com/api/v2#transactions)
359
+
360
+ **List transactions**
361
+
362
+ ```ruby
363
+ account.transactions
364
+ ```
365
+
366
+ **Get transaction info**
367
+
368
+ ```ruby
369
+ account.transaction(transaction_id)
370
+ ```
371
+
372
+ **Send funds**
373
+
374
+ ```ruby
375
+ account.send(to: <bitcoin address>, amount: "5.0", currency: "USD", description: "Your first bitcoin!")
376
+ ```
377
+
378
+ **Transfer funds to a new account**
379
+
380
+ ```ruby
381
+ account.transfer(to: <account ID>, amount: "1", currency: "BTC", description: "Your first bitcoin!")
382
+ ```
383
+
384
+ **Request funds**
385
+
386
+ ```ruby
387
+ account.request(to: <email>, amount: "8.0", currency: "USD", description: "Burrito")
388
+ ```
389
+
390
+ **Resend request**
391
+
392
+ ```ruby
393
+ account.resend_request(request_id)
394
+ ```
395
+
396
+ **Cancel request**
397
+
398
+ ```ruby
399
+ account.cancel_request(request_id)
400
+ ```
401
+
402
+ **Fulfill request**
403
+
404
+ ```ruby
405
+ account.complete_request(request_id)
406
+ ```
407
+
408
+ ### [Buys](https://developers.coinbase.com/api/v2#buys)
409
+
410
+ **List buys**
411
+
412
+ ```ruby
413
+ account.list_buys
414
+ ```
415
+
416
+ **Get buy info**
417
+
418
+ ```ruby
419
+ account.list_buy(buy_id)
420
+ ```
421
+
422
+ **Buy bitcoins**
423
+
424
+ ```ruby
425
+ account.buy(amount: "1", currency: "BTC")
426
+ ```
427
+
428
+ **Commit a buy**
429
+
430
+ You only need to do this if you pass `commit=true` when you call the buy method.
431
+
432
+ ```ruby
433
+ buy = account.buy(amount: "1", currency: "BTC", commit: false)
434
+ account.commit_buy(buy.id)
435
+ ```
436
+
437
+ ### [Sells](https://developers.coinbase.com/api/v2#sells)
438
+
439
+ **List sells**
440
+
441
+ ```ruby
442
+ account.list_sells
443
+ ```
444
+
445
+ **Get sell info**
446
+
447
+ ```ruby
448
+ account.list_sell(sell_id)
449
+ ```
450
+
451
+ **Sell bitcoins**
452
+
453
+ ```ruby
454
+ account.sell(amount: "1", currency: "BTC")
455
+ ```
456
+
457
+ **Commit a sell**
458
+
459
+ You only need to do this if you pass `commit=true` when you call the sell method.
460
+
461
+ ```ruby
462
+ sell = account.sell(amount: "1", currency: "BTC", commit: false)
463
+ account.commit_sell(sell.id)
464
+ ```
465
+
466
+ ### [Deposit](https://developers.coinbase.com/api/v2#deposits)
467
+
468
+ **List deposits**
469
+
470
+ ```ruby
471
+ account.list_deposits
472
+ ```
473
+
474
+ **Get deposit info**
475
+
476
+ ```ruby
477
+ account.list_deposit(deposit_id)
478
+ ```
479
+
480
+ **Deposit funds**
481
+
482
+ ```ruby
483
+ account.deposit(amount: "10", currency: "USD")
484
+ ```
485
+
486
+ **Commit a deposit**
487
+
488
+ You only need to do this if you pass `commit=true` when you call the deposit method.
489
+
490
+ ```ruby
491
+ deposit = account.deposit(amount: "1", currency: "BTC", commit: false)
492
+ account.commit_deposit(deposit.id)
493
+ ```
494
+
495
+ ### [Withdrawals](https://developers.coinbase.com/api/v2#withdrawals)
496
+
497
+ **List withdrawals**
498
+
499
+ ```ruby
500
+ account.list_withdrawals
501
+ ```
502
+
503
+ **Get withdrawal**
504
+
505
+ ```ruby
506
+ account.list_withdrawal(withdrawal_id)
507
+ ```
508
+
509
+ **Withdraw funds**
510
+
511
+ ```ruby
512
+ account.withdraw(amount: "10", currency: "USD")
513
+ ```
514
+
515
+ **Commit a withdrawal**
516
+
517
+ You only need to do this if you pass `commit=true` when you call the withdrawal method.
518
+
519
+ ```ruby
520
+ withdraw = account.withdraw(amount: "1", currency: "BTC", commit: false)
521
+ account.commit_withdrawal(withdrawal.id)
522
+ ```
523
+
524
+ ### [Payment Methods](https://developers.coinbase.com/api/v2#payment-methods)
525
+
526
+ **List payment methods**
527
+
528
+ ```ruby
529
+ client.payment_methods
530
+ ```
531
+
532
+ **Get payment method**
533
+
534
+ ```ruby
535
+ client.payment_method(payment_method_id)
536
+ ```
537
+
538
+ ### [Merchants](https://developers.coinbase.com/api/v2#merchants)
539
+
540
+ #### Get merchant
541
+
542
+ ```ruby
543
+ client.merchant(merchant_id)
544
+ ```
545
+
546
+ #### Verify a merchant callback
547
+
548
+ ```ruby
549
+ client.verify_callback(request.raw_post, request.headers['CB-SIGNATURE']) # true/false
550
+ ```
551
+
552
+ ### [Orders](https://developers.coinbase.com/api/v2#orders)
553
+
554
+ #### List orders
555
+
556
+ ```ruby
557
+ client.orders
558
+ ```
559
+
560
+ #### Get order
561
+
562
+ ```ruby
563
+ client.order(order_id)
564
+ ```
565
+
566
+ #### Create order
567
+
568
+ ```ruby
569
+ client.create_order(amount: "1", currency: "BTC", name: "Order #1234")
570
+ ```
571
+
572
+ #### Refund order
573
+
574
+ ```ruby
575
+ order = client.orders.first
576
+ order.refund!
577
+ ```
578
+
579
+ ### Checkouts
580
+
581
+ #### List checkouts
582
+
583
+ ```ruby
584
+ client.checkouts
585
+ ```
586
+
587
+ #### Get checkout
588
+
589
+ ```ruby
590
+ client.checkout(checkout_id)
591
+ ```
592
+
593
+ #### Get checkout's orders
594
+
595
+ ```ruby
596
+ checkout = client.checkout(checkout_id)
597
+ checkout.orders
598
+ ```
599
+
600
+ #### Create order for checkout
601
+
602
+ ```ruby
603
+ checkout = client.checkout(checkout_id)
604
+ checkout.create_order
605
+ ```
606
+
607
+ ## Contributing and testing
608
+
609
+ Any and all contributions are welcome! The process is simple: fork this repo, make your changes, add tests, run the test suite, and submit a pull request. Tests are run via rspec. To run the tests, clone the repository and then:
610
+
611
+ # Install the requirements
612
+ gem install coinbase
613
+
614
+ # Run tests
615
+ rspec spec
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coinbase/wallet"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/coinbase.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coinbase/wallet/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "coinbase"
8
+ gem.version = Coinbase::Wallet::VERSION
9
+ gem.license = 'Apache-2.0'
10
+ gem.authors = ["John Duhamel", "Jori Lallo"]
11
+ gem.email = ["api@coinbase.com"]
12
+ gem.description = "Client library for Coinbase Wallet API v2"
13
+ gem.summary = "Client library for Coinbase Wallet API v2"
14
+ gem.homepage = "https://developers.coinbase.com/api/v2"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "webmock"
24
+ gem.add_development_dependency "timecop"
25
+ gem.add_development_dependency "pry-byebug"
26
+ end
@@ -0,0 +1,16 @@
1
+ module Coinbase::Util
2
+ class CurrencyPairError < StandardError; end
3
+
4
+ # An adaptar that allow converts a currency into
5
+ # a currency pair to coenciede with multiple crypto currenices
6
+ #
7
+ # @param currency [String] the currency option inputed by the developer
8
+ # @return [String] The properly formatted currency pair
9
+ def self.determine_currency_pair(params)
10
+ return 'BTC-USD' if (!params[:currency] && !params[:currency_pair])
11
+ return 'BTC-' + params[:currency] if params[:currency]
12
+ return params[:currency_pair] if params[:currency_pair]
13
+
14
+ raise CurrencyPairError, "invalid currency param"
15
+ end
16
+ end