Class: DuffelAPI::Response
- Inherits:
-
Object
- Object
- DuffelAPI::Response
- Extended by:
- Forwardable
- Defined in:
- lib/duffel_api/response.rb
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#meta ⇒ Object
Returns the meta hash of the response.
-
#parsed_body ⇒ Object
Return the body of parsed JSON body of the API response.
- #raw_body ⇒ Object
-
#request_id ⇒ Object
Returns the request ID from the response headers.
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
#meta ⇒ Object
Returns the meta hash of the response
24 25 26 27 28 29 30 |
# File 'lib/duffel_api/response.rb', line 24 def return {} if parsed_body.nil? parsed_body.fetch("meta", {}) rescue JSON::ParserError {} end |
#parsed_body ⇒ Object
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_body ⇒ Object
14 15 16 |
# File 'lib/duffel_api/response.rb', line 14 def raw_body @response.body end |
#request_id ⇒ Object
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 |