Module: Cryptoprocessing

Extended by:
Configurable
Defined in:
lib/cryptoprocessing.rb,
lib/cryptoprocessing/cli.rb,
lib/cryptoprocessing/error.rb,
lib/cryptoprocessing/rails.rb,
lib/cryptoprocessing/client.rb,
lib/cryptoprocessing/default.rb,
lib/cryptoprocessing/version.rb,
lib/cryptoprocessing/connection.rb,
lib/cryptoprocessing/models/user.rb,
lib/cryptoprocessing/configurable.rb,
lib/cryptoprocessing/authentication.rb,
lib/cryptoprocessing/models/account.rb,
lib/cryptoprocessing/models/address.rb,
lib/cryptoprocessing/models/tracker.rb,
lib/cryptoprocessing/client/accounts.rb,
lib/cryptoprocessing/client/trackers.rb,
lib/cryptoprocessing/models/callback.rb,
lib/cryptoprocessing/client/addresses.rb,
lib/cryptoprocessing/client/callbacks.rb,
lib/cryptoprocessing/adapters/net_http.rb,
lib/cryptoprocessing/client/api_errors.rb,
lib/cryptoprocessing/models/api_object.rb,
lib/cryptoprocessing/models/transaction.rb,
lib/cryptoprocessing/client/api_response.rb,
lib/cryptoprocessing/client/net_response.rb,
lib/cryptoprocessing/client/transactions.rb,
lib/cryptoprocessing/client/coinbase_wallet.rb,
lib/cryptoprocessing/authentication/token_store.rb

Overview

Copyright 2018 OOM.AG.

Defined Under Namespace

Modules: Api, Authentication, Configurable, Connection, Default Classes: APIError, APIObject, APIResponse, Account, Address, BadRequestError, CLI, Callback, Client, NetHTTPClient, NetHTTPResponse, Rails, Tracker, Transaction, User

Constant Summary collapse

MAJOR =

Current major release.

Returns:

  • (Integer)
0
MINOR =

Current minor release.

Returns:

  • (Integer)
6
PATCH =

Current patch level.

Returns:

  • (Integer)
1
VERSION =

Full release version.

Returns:

  • (String)
[MAJOR, MINOR, PATCH].join('.').freeze

Instance Attribute Summary

Attributes included from Configurable

#access_token, #api_endpoint, #api_namespace, #blockchain_type, #email, #password, #user_agent

Class Method Summary collapse

Methods included from Configurable

configure, keys, netrc?, reset!, same_options?

Class Method Details

.check_response_status(resp) ⇒ Object



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cryptoprocessing/client/net_response.rb', line 31

def self.check_response_status(resp)
  if resp.status == 200 && resp.body.kind_of?(Array)
    return
  end

  (resp.body['warnings'] || []).each do |warning|
    message = "WARNING: #{warning['message']}"
    message += " (#{warning['url']})" if warning["url"]
    $stderr.puts message
  end

  # OAuth2 errors
  if resp.status >= 400 && resp.body['error']
    raise Cryptoprocessing::APIError, resp.body['error_description']
  end

  # Regular errors
  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

  # API errors
  if resp.body['status'] == 'fail'
    raise Cryptoprocessing::APIError, resp.body['message']
  end

  if resp.status > 400
    raise Cryptoprocessing::APIError, "[#{resp.status}] #{resp.body}"
  end
end

.clientCryptoprocessing::Client

API client based on configured options Configurable

Returns:



14
15
16
17
# File 'lib/cryptoprocessing.rb', line 14

def client
  return @client if defined?(@client) && @client.same_options?(options)
  @client = Cryptoprocessing::Client.new(options)
end