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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +578 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coinbase.gemspec +30 -0
- data/lib/coinbase/wallet/adapters/em_http.rb +64 -0
- data/lib/coinbase/wallet/adapters/net_http.rb +62 -0
- data/lib/coinbase/wallet/api_client.rb +659 -0
- data/lib/coinbase/wallet/api_errors.rb +112 -0
- data/lib/coinbase/wallet/api_response.rb +37 -0
- data/lib/coinbase/wallet/client.rb +98 -0
- data/lib/coinbase/wallet/models/account.rb +187 -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 +23 -156
- data/spec/account_spec.rb +193 -0
- data/spec/clients/client_spec.rb +34 -0
- data/spec/clients/oauth_client_spec.rb +56 -0
- data/spec/endpoints_spec.rb +346 -0
- data/spec/error_spec.rb +130 -0
- data/spec/models/api_object_spec.rb +63 -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 +72 -82
- 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
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
|