Class: DuffelAPI::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/duffel_api/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



10
11
12
# File 'lib/duffel_api/response.rb', line 10

def initialize(response)
  @response = response
end

Instance Method Details

#metaObject

Returns the meta hash of the response



24
25
26
27
28
29
30
# File 'lib/duffel_api/response.rb', line 24

def meta
  return {} if parsed_body.nil?

  parsed_body.fetch("meta", {})
rescue JSON::ParserError
  {}
end

#parsed_bodyObject

Return the body of parsed JSON body of the API response



19
20
21
# File 'lib/duffel_api/response.rb', line 19

def parsed_body
  JSON.parse(raw_body) unless raw_body.empty?
end

#raw_bodyObject



14
15
16
# File 'lib/duffel_api/response.rb', line 14

def raw_body
  @response.body
end

#request_idObject

Returns the request ID from the response headers



33
34
35
# File 'lib/duffel_api/response.rb', line 33

def request_id
  normalised_headers["x-request-id"]
end