Module: Coinbase::Wallet
- Defined in:
- lib/coinbase/wallet.rb,
lib/coinbase/wallet/client.rb,
lib/coinbase/wallet/version.rb,
lib/coinbase/wallet/api_client.rb,
lib/coinbase/wallet/api_errors.rb,
lib/coinbase/wallet/models/user.rb,
lib/coinbase/wallet/api_response.rb,
lib/coinbase/wallet/models/order.rb,
lib/coinbase/wallet/models/account.rb,
lib/coinbase/wallet/models/address.rb,
lib/coinbase/wallet/models/checkout.rb,
lib/coinbase/wallet/models/transfer.rb,
lib/coinbase/wallet/adapters/em_http.rb,
lib/coinbase/wallet/adapters/net_http.rb,
lib/coinbase/wallet/models/api_object.rb,
lib/coinbase/wallet/models/transaction.rb
Defined Under Namespace
Classes: APIClient, APIError, APIObject, APIResponse, Account, Address, AsyncClient, AuthenticationError, BadRequestError, Checkout, Client, CurrentUser, EMHTTPClient, EMHTTPResponse, ExpiredTokenError, InternalServerError, InvalidRequestError, InvalidScopeError, InvalidTokenError, NetHTTPClient, NetHTTPResponse, NotFoundError, OAuthClient, Order, ParamRequiredError, PersonalDetailsRequiredError, RateLimitError, Request, RevokedTokenError, ServiceUnavailableError, Transaction, Transfer, TwoFactorRequiredError, UnverifiedEmailError, User, ValidationError
Constant Summary
collapse
- BASE_API_URL =
"https://api.coinbase.com"
- API_VERSION =
'2015-06-16'
- VERSION =
"4.2.3"
Class Method Summary
collapse
Class Method Details
.check_response_status(resp) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/coinbase/wallet/api_errors.rb', line 11
def self.check_response_status(resp)
(resp.body['warnings'] || []).each do |warning|
message = "WARNING: #{warning['message']}"
message += " (#{warning['url']})" if warning["url"]
$stderr.puts message
end
if resp.status >= 400 && resp.body['error']
raise APIError, resp.body['error_description']
end
if resp.body['errors']
case resp.status
when 400
case resp.body['errors'].first['id']
when 'param_required' then raise ParamRequiredError, format_error(resp)
when 'invalid_request' then raise InvalidRequestError, format_error(resp)
when 'personal_details_required' then raise PersonalDetailsRequiredError, format_error(resp)
end
raise BadRequestError, format_error(resp)
when 401
case resp.body['errors'].first['id']
when 'authentication_error' then raise AuthenticationError, format_error(resp)
when 'unverified_email' then raise UnverifiedEmailError, format_error(resp)
when 'invalid_token' then raise InvalidTokenError, format_error(resp)
when 'revoked_token' then raise RevokedTokenError, format_error(resp)
when 'expired_token' then raise ExpiredTokenError, format_error(resp)
end
raise AuthenticationError, format_error(resp)
when 402 then raise TwoFactorRequiredError, format_error(resp)
when 403 then raise InvalidScopeError, format_error(resp)
when 404 then raise NotFoundError, format_error(resp)
when 422 then raise ValidationError, format_error(resp)
when 429 then raise RateLimitError, format_error(resp)
when 500 then raise InternalServerError, format_error(resp)
when 503 then raise ServiceUnavailableError, format_error(resp)
end
end
if resp.status > 400
raise APIError, "[#{resp.status}] #{resp.body}"
end
end
|
3
4
5
6
7
8
9
|
# File 'lib/coinbase/wallet/api_errors.rb', line 3
def self.format_error(resp)
error = resp.body && (resp.body['errors'] || resp.body['warnings']).first
return resp.body unless error
message = error['message']
message += " (#{error['url']})" if error["url"]
message
end
|