coinbase 0.0.1 → 4.0.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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +67 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +578 -0
  7. data/Rakefile +7 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +7 -0
  10. data/coinbase.gemspec +30 -0
  11. data/lib/coinbase/wallet/adapters/em_http.rb +64 -0
  12. data/lib/coinbase/wallet/adapters/net_http.rb +62 -0
  13. data/lib/coinbase/wallet/api_client.rb +659 -0
  14. data/lib/coinbase/wallet/api_errors.rb +112 -0
  15. data/lib/coinbase/wallet/api_response.rb +37 -0
  16. data/lib/coinbase/wallet/client.rb +98 -0
  17. data/lib/coinbase/wallet/models/account.rb +187 -0
  18. data/lib/coinbase/wallet/models/api_object.rb +46 -0
  19. data/lib/coinbase/wallet/models/checkout.rb +19 -0
  20. data/lib/coinbase/wallet/models/order.rb +12 -0
  21. data/lib/coinbase/wallet/models/transaction.rb +21 -0
  22. data/lib/coinbase/wallet/models/transfer.rb +13 -0
  23. data/lib/coinbase/wallet/models/user.rb +15 -0
  24. data/lib/coinbase/wallet/version.rb +5 -0
  25. data/lib/coinbase/wallet.rb +23 -156
  26. data/spec/account_spec.rb +193 -0
  27. data/spec/clients/client_spec.rb +34 -0
  28. data/spec/clients/oauth_client_spec.rb +56 -0
  29. data/spec/endpoints_spec.rb +346 -0
  30. data/spec/error_spec.rb +130 -0
  31. data/spec/models/api_object_spec.rb +63 -0
  32. data/spec/models/checkout_spec.rb +52 -0
  33. data/spec/models/current_user_spec.rb +29 -0
  34. data/spec/models/order_spec.rb +52 -0
  35. data/spec/models/request_spec.rb +47 -0
  36. data/spec/models/transfer_spec.rb +64 -0
  37. data/spec/models/user_spec.rb +24 -0
  38. data/spec/spec_helper.rb +13 -0
  39. metadata +72 -82
  40. data/lib/coinbase/address.rb +0 -127
  41. data/lib/coinbase/asset.rb +0 -20
  42. data/lib/coinbase/balance_map.rb +0 -48
  43. data/lib/coinbase/constants.rb +0 -38
  44. data/lib/coinbase/network.rb +0 -55
  45. data/lib/coinbase/transfer.rb +0 -153
  46. data/lib/coinbase.rb +0 -18
data/coinbase.gemspec ADDED
@@ -0,0 +1,30 @@
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.licenses = ["MIT"]
10
+ gem.authors = ["John Duhamel"]
11
+ gem.email = ["jjd@coinbase.com"]
12
+ gem.description = ["An easy way to buy, send, and accept bitcoin."]
13
+ gem.summary = ["An easy way to buy, send, and accept bitcoin."]
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_dependency "bigdecimal"
22
+ gem.add_dependency "em-http-request"
23
+
24
+ gem.add_development_dependency "bundler", "~> 1.10"
25
+ gem.add_development_dependency "rake", "~> 10.0"
26
+ gem.add_development_dependency "rgem"
27
+ gem.add_development_dependency "webmock"
28
+ gem.add_development_dependency "timecop"
29
+ gem.add_development_dependency "pry", "~> 0"
30
+ end
@@ -0,0 +1,64 @@
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
+ case method
24
+ when 'GET'
25
+ req = EM::HttpRequest.new(@api_uri).get(path: path, head: headers, body: body)
26
+ when 'POST'
27
+ req = EM::HttpRequest.new(@api_uri).put(path: path, head: headers, body: body)
28
+ when 'POST'
29
+ req = EM::HttpRequest.new(@api_uri).post(path: path, head: headers, body: body)
30
+ when 'DELETE'
31
+ req = EM::HttpRequest.new(@api_uri).delete(path: path, head: headers)
32
+ else raise
33
+ end
34
+ req.callback do |resp|
35
+ out = EMHTTPResponse.new(resp)
36
+ Coinbase::Wallet::check_response_status(out)
37
+ yield(out)
38
+ end
39
+ req.errback do |resp|
40
+ raise APIError, "#{method} #{@api_uri}#{path}: #{resp.error}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ # EM-Http response object
47
+ class EMHTTPResponse < APIResponse
48
+ def body
49
+ JSON.parse(@response.response)
50
+ end
51
+
52
+ def headers
53
+ out = @response.response_header.map do |key, val|
54
+ [ key.upcase.gsub('_', '-'), val ]
55
+ end
56
+ out.to_h
57
+ end
58
+
59
+ def status
60
+ @response.response_header.status
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,62 @@
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
+ end
9
+
10
+ private
11
+
12
+ def http_verb(method, path, body = nil, headers = {})
13
+ case method
14
+ when 'GET' then req = Net::HTTP::Get.new(path)
15
+ when 'PUT' then req = Net::HTTP::Put.new(path)
16
+ when 'POST' then req = Net::HTTP::Post.new(path)
17
+ when 'DELETE' then req = Net::HTTP::Delete.new(path)
18
+ else raise
19
+ end
20
+
21
+ req.body = body
22
+
23
+ req['Content-Type'] = 'application/json'
24
+ req['User-Agent'] = "coinbase/ruby/#{Coinbase::Wallet::VERSION}"
25
+ auth_headers(method, path, body).each do |key, val|
26
+ req[key] = val
27
+ end
28
+ headers.each do |key, val|
29
+ req[key] = val
30
+ end
31
+
32
+ resp = @conn.request(req)
33
+ out = NetHTTPResponse.new(resp)
34
+ Coinbase::Wallet::check_response_status(out)
35
+ yield(out)
36
+ out.data
37
+ end
38
+ end
39
+
40
+ # Net-Http response object
41
+ class NetHTTPResponse < APIResponse
42
+ def body
43
+ JSON.parse(@response.body) rescue {}
44
+ end
45
+
46
+ def data
47
+ body['data']
48
+ end
49
+
50
+ def headers
51
+ out = @response.to_hash.map do |key, val|
52
+ [ key.upcase.gsub('_', '-'), val.count == 1 ? val.first : val ]
53
+ end
54
+ out.to_h
55
+ end
56
+
57
+ def status
58
+ @response.code.to_i
59
+ end
60
+ end
61
+ end
62
+ end