coinbase 0.0.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

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
@@ -0,0 +1,78 @@
1
+ module Coinbase
2
+ module Wallet
3
+ # EM-Http Adapter
4
+ class EMHTTPClient < APIClient
5
+ private
6
+
7
+ def http_verb(method, path, body = nil, headers = {})
8
+ if !EventMachine.reactor_running?
9
+ EM.run do
10
+ # FIXME: This doesn't work with paginated endpoints
11
+ http_verb(method, path, body) do |resp|
12
+ yield(resp)
13
+ EM.stop
14
+ end
15
+ end
16
+ else
17
+ headers['Content-Type'] = 'application/json'
18
+ headers['User-Agent'] = "coinbase/ruby-em/#{Coinbase::Wallet::VERSION}"
19
+ auth_headers(method, path, body).each do |key, val|
20
+ headers[key] = val
21
+ end
22
+
23
+ # NOTE: This is documented but not implemented in em-http-request
24
+ # https://github.com/igrigorik/em-http-request/issues/182
25
+ # https://github.com/igrigorik/em-http-request/pull/179
26
+ ssl_opts = { cert_chain_file: File.expand_path(File.join(File.dirname(__FILE__), 'ca-coinbase.crt')),
27
+ verify_peer: true }
28
+
29
+ case method
30
+ when 'GET'
31
+ req = EM::HttpRequest.new(@api_uri).get(path: path, head: headers, body: body, ssl: ssl_opts)
32
+ when 'POST'
33
+ req = EM::HttpRequest.new(@api_uri).put(path: path, head: headers, body: body, ssl: ssl_opts)
34
+ when 'POST'
35
+ req = EM::HttpRequest.new(@api_uri).post(path: path, head: headers, body: body, ssl: ssl_opts)
36
+ when 'DELETE'
37
+ req = EM::HttpRequest.new(@api_uri).delete(path: path, head: headers, ssl: ssl_opts)
38
+ else raise
39
+ end
40
+ req.callback do |resp|
41
+ out = EMHTTPResponse.new(resp)
42
+ Coinbase::Wallet::check_response_status(out)
43
+ yield(out)
44
+ end
45
+ req.errback do |resp|
46
+ raise APIError, "#{method} #{@api_uri}#{path}: #{resp.error}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ # EM-Http response object
53
+ class EMHTTPResponse < APIResponse
54
+ def body
55
+ JSON.parse(@response.response)
56
+ end
57
+
58
+ def data
59
+ body['data']
60
+ end
61
+
62
+ def body=(body)
63
+ @response.response = body.to_json
64
+ end
65
+
66
+ def headers
67
+ out = @response.response_header.map do |key, val|
68
+ [ key.upcase.gsub('_', '-'), val ]
69
+ end
70
+ out.to_h
71
+ end
72
+
73
+ def status
74
+ @response.response_header.status
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,68 @@
1
+ module Coinbase
2
+ module Wallet
3
+ # Net-HTTP adapter
4
+ class NetHTTPClient < APIClient
5
+ def initialize(base_uri, options = {})
6
+ @conn = Net::HTTP.new(base_uri.host, base_uri.port)
7
+ @conn.use_ssl = true if base_uri.scheme == 'https'
8
+ @conn.cert_store = self.class.whitelisted_certificates
9
+ @conn.ssl_version = :TLSv1
10
+ end
11
+
12
+ private
13
+
14
+ def http_verb(method, path, body = nil, headers = {})
15
+ case method
16
+ when 'GET' then req = Net::HTTP::Get.new(path)
17
+ when 'PUT' then req = Net::HTTP::Put.new(path)
18
+ when 'POST' then req = Net::HTTP::Post.new(path)
19
+ when 'DELETE' then req = Net::HTTP::Delete.new(path)
20
+ else raise
21
+ end
22
+
23
+ req.body = body
24
+
25
+ req['Content-Type'] = 'application/json'
26
+ req['User-Agent'] = "coinbase/ruby/#{Coinbase::Wallet::VERSION}"
27
+ auth_headers(method, path, body).each do |key, val|
28
+ req[key] = val
29
+ end
30
+ headers.each do |key, val|
31
+ req[key] = val
32
+ end
33
+
34
+ resp = @conn.request(req)
35
+ out = NetHTTPResponse.new(resp)
36
+ Coinbase::Wallet::check_response_status(out)
37
+ yield(out)
38
+ out.data
39
+ end
40
+ end
41
+
42
+ # Net-Http response object
43
+ class NetHTTPResponse < APIResponse
44
+ def body
45
+ JSON.parse(@response.body) rescue {}
46
+ end
47
+
48
+ def body=(body)
49
+ @response.body = body.to_json
50
+ end
51
+
52
+ def data
53
+ body['data']
54
+ end
55
+
56
+ def headers
57
+ out = @response.to_hash.map do |key, val|
58
+ [ key.upcase.gsub('_', '-'), val.count == 1 ? val.first : val ]
59
+ end
60
+ out.to_h
61
+ end
62
+
63
+ def status
64
+ @response.code.to_i
65
+ end
66
+ end
67
+ end
68
+ end