Class: BitgoClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitgo_client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/bitgo_client/client.rb', line 7

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/bitgo_client/client.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#request(url, payload = nil, method: :get) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bitgo_client/client.rb', line 11

def request(url, payload = nil, method: :get)
  request = Typhoeus::Request.new(
    url,
    method: method,
    headers: {
      "Authorization" => "Bearer #{access_token}",
      "Content-Type"  => "application/json"
    },
    body: (payload ? payload.to_json : nil)
  )

  request.run

  response = request.response

  raise BitgoClient::Errors::RequestError.new("BitGo API response error.", response) if response.failure?

  JSON.parse(response.body)
end