Class: Activite::HTTP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/activite/http/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, headers) ⇒ Request

Returns a new instance of Request.


10
11
12
13
# File 'lib/activite/http/request.rb', line 10

def initialize(access_token, headers)
  @access_token = access_token
  @headers = headers
end

Instance Method Details

#get(path, options = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/activite/http/request.rb', line 15

def get(path, options = {})
  uri = "#{BASE_URI}#{path}?#{hash_to_query(options)}"
  response = @access_token.get(uri, @headers)
  if response.code.to_i < 200 or response.code.to_i >= 400
    raise Activite::Error::ClientConfigurationError, response.body
  end
  body = JSON.parse(response.body)
  if body['status'].to_i != 0
    raise Activite::Error::InvalidResponseError, "#{body['status']} - #{body['error']}"
  end
  body['body']
end