Class: Jets::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_resp) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
# File 'lib/jets/api/response.rb', line 12

def initialize(http_resp)
  @http_resp = http_resp
  @http_body = http_resp.body
  @http_headers = http_resp.to_hash
  @http_status = http_resp.code.to_i
  @request_id = http_resp["request-id"]
end

Instance Attribute Details

#http_bodyObject (readonly)

Returns the value of attribute http_body.



5
6
7
# File 'lib/jets/api/response.rb', line 5

def http_body
  @http_body
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



5
6
7
# File 'lib/jets/api/response.rb', line 5

def http_headers
  @http_headers
end

#http_respObject (readonly)

Returns the value of attribute http_resp.



5
6
7
# File 'lib/jets/api/response.rb', line 5

def http_resp
  @http_resp
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



5
6
7
# File 'lib/jets/api/response.rb', line 5

def http_status
  @http_status
end

#request_idObject (readonly)

Returns the value of attribute request_id.



5
6
7
# File 'lib/jets/api/response.rb', line 5

def request_id
  @request_id
end

Instance Method Details

#dataObject



20
21
22
23
24
25
# File 'lib/jets/api/response.rb', line 20

def data
  data = JSON.parse(@http_resp.body, symbolize_names: true)
  Hashie::Mash.new(data)
rescue JSON::ParserError
  raise Jets::Api::Error, http_resp
end