coinbase 0.0.1 → 4.0.7
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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +611 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coinbase.gemspec +27 -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 +692 -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 +629 -0
- data/lib/coinbase/wallet/client.rb +101 -0
- data/lib/coinbase/wallet/models/account.rb +187 -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 +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 +352 -0
- data/spec/error_spec.rb +137 -0
- data/spec/models/address_spec.rb +26 -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 +62 -98
- 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,120 @@
|
|
1
|
+
module Coinbase
|
2
|
+
module Wallet
|
3
|
+
def self.format_error(resp)
|
4
|
+
error = resp.body && (resp.body['errors'] || resp.body['warnings']).first
|
5
|
+
return resp.body unless error
|
6
|
+
message = error['message']
|
7
|
+
message += " (#{error['url']})" if error["url"]
|
8
|
+
message
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.check_response_status(resp)
|
12
|
+
(resp.body['warnings'] || []).each do |warning|
|
13
|
+
message = "WARNING: #{warning['message']}"
|
14
|
+
message += " (#{warning['url']})" if warning["url"]
|
15
|
+
$stderr.puts message
|
16
|
+
end
|
17
|
+
|
18
|
+
# OAuth2 errors
|
19
|
+
if resp.status >= 400 && resp.body['error']
|
20
|
+
raise APIError, resp.body['error_description']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Regular errors
|
24
|
+
if resp.body['errors']
|
25
|
+
case resp.status
|
26
|
+
when 400
|
27
|
+
case resp.body['errors'].first['id']
|
28
|
+
when 'param_required' then raise ParamRequiredError, format_error(resp)
|
29
|
+
when 'invalid_request' then raise InvalidRequestError, format_error(resp)
|
30
|
+
when 'personal_details_required' then raise PersonalDetailsRequiredError, format_error(resp)
|
31
|
+
end
|
32
|
+
raise BadRequestError, format_error(resp)
|
33
|
+
when 401
|
34
|
+
case resp.body['errors'].first['id']
|
35
|
+
when 'authentication_error' then raise AuthenticationError, format_error(resp)
|
36
|
+
when 'unverified_email' then raise UnverifiedEmailError, format_error(resp)
|
37
|
+
when 'invalid_token' then raise InvalidTokenError, format_error(resp)
|
38
|
+
when 'revoked_token' then raise RevokedTokenError, format_error(resp)
|
39
|
+
when 'expired_token' then raise ExpiredTokenError, format_error(resp)
|
40
|
+
end
|
41
|
+
raise AuthenticationError, format_error(resp)
|
42
|
+
when 402 then raise TwoFactorRequiredError, format_error(resp)
|
43
|
+
when 403 then raise InvalidScopeError, format_error(resp)
|
44
|
+
when 404 then raise NotFoundError, format_error(resp)
|
45
|
+
when 422 then raise ValidationError, format_error(resp)
|
46
|
+
when 429 then raise RateLimitError, format_error(resp)
|
47
|
+
when 500 then raise InternalServerError, format_error(resp)
|
48
|
+
when 503 then raise ServiceUnavailableError, format_error(resp)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if resp.status > 400
|
53
|
+
raise APIError, "[#{resp.status}] #{resp.body}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Rest API Errors
|
59
|
+
#
|
60
|
+
class APIError < RuntimeError
|
61
|
+
end
|
62
|
+
|
63
|
+
# Status 400
|
64
|
+
class BadRequestError < APIError
|
65
|
+
end
|
66
|
+
|
67
|
+
class ParamRequiredError < APIError
|
68
|
+
end
|
69
|
+
|
70
|
+
class InvalidRequestError < APIError
|
71
|
+
end
|
72
|
+
|
73
|
+
class PersonalDetailsRequiredError < APIError
|
74
|
+
end
|
75
|
+
|
76
|
+
# Status 401
|
77
|
+
class AuthenticationError < APIError
|
78
|
+
end
|
79
|
+
|
80
|
+
class UnverifiedEmailError < APIError
|
81
|
+
end
|
82
|
+
|
83
|
+
class InvalidTokenError < APIError
|
84
|
+
end
|
85
|
+
|
86
|
+
class RevokedTokenError < APIError
|
87
|
+
end
|
88
|
+
|
89
|
+
class ExpiredTokenError < APIError
|
90
|
+
end
|
91
|
+
|
92
|
+
# Status 402
|
93
|
+
class TwoFactorRequiredError < APIError
|
94
|
+
end
|
95
|
+
|
96
|
+
# Status 403
|
97
|
+
class InvalidScopeError < APIError
|
98
|
+
end
|
99
|
+
|
100
|
+
# Status 404
|
101
|
+
class NotFoundError < APIError
|
102
|
+
end
|
103
|
+
|
104
|
+
# Status 422
|
105
|
+
class ValidationError < APIError
|
106
|
+
end
|
107
|
+
|
108
|
+
# Status 429
|
109
|
+
class RateLimitError < APIError
|
110
|
+
end
|
111
|
+
|
112
|
+
# Status 500
|
113
|
+
class InternalServerError < APIError
|
114
|
+
end
|
115
|
+
|
116
|
+
# Status 503
|
117
|
+
class ServiceUnavailableError < APIError
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Coinbase
|
2
|
+
module Wallet
|
3
|
+
# Encapsulate data for an API response
|
4
|
+
class APIResponse
|
5
|
+
attr_reader :received_at
|
6
|
+
attr_accessor :client
|
7
|
+
attr_accessor :method
|
8
|
+
attr_accessor :params
|
9
|
+
|
10
|
+
def initialize(resp)
|
11
|
+
@received_at = Time.now
|
12
|
+
@response = resp
|
13
|
+
end
|
14
|
+
|
15
|
+
def raw
|
16
|
+
@response
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
alias_method :data, :body
|
23
|
+
|
24
|
+
def body=(body)
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
def headers
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
def status
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def has_more?
|
37
|
+
body.has_key?('pagination') && body['pagination']['next_uri'] != nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|