Class: BitgoClient::Client
- Inherits:
-
Object
- Object
- BitgoClient::Client
- Defined in:
- lib/bitgo_client/client.rb
Constant Summary collapse
- SENSITIVE_KEYS =
[ :backupXpub, :keychain, :newWalletPassphrase, :otp, :overrideEncryptedPrv, :passcodeEncryptionCode, :passphrase, :password, :prv, :pub, :userKey, :userPassword, :walletPassphrase, :xprv, ]
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#initialize(access_token) ⇒ Client
constructor
A new instance of Client.
- #request(url, payload = nil, method: :get, logger: nil) ⇒ Object
Constructor Details
#initialize(access_token) ⇒ Client
Returns a new instance of Client.
26 27 28 |
# File 'lib/bitgo_client/client.rb', line 26 def initialize(access_token) @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
24 25 26 |
# File 'lib/bitgo_client/client.rb', line 24 def access_token @access_token end |
Instance Method Details
#request(url, payload = nil, method: :get, logger: nil) ⇒ Object
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 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bitgo_client/client.rb', line 30 def request(url, payload = nil, method: :get, logger: nil) body = payload.to_json if payload log logger, "Request url: #{url}, method: #{method}, body:" log logger, payload request = Typhoeus::Request.new( url, method: method, headers: { "Authorization" => "Bearer #{access_token}", "Content-Type" => "application/json" }, body: body ) request.run response = request.response code = response.code body = response.body log logger, "Response code: '#{code}', body: '#{body}'" if [408, 504, 524].include?(code) raise BitgoClient::Errors::RequestError.new("[BitGo API Error] Timeout (code: #{code}).", response) elsif response.failure? raise BitgoClient::Errors::RequestError.new("[BitGo API Error] code: #{code}.", response) elsif body.nil? || body == "" {} elsif valid_json?(body) JSON.parse(body) else raise BitgoClient::Errors::RequestError.new("[BitGo API Error] Invalid JSON (code: #{code}).", response) end end |