Class: CoreLibrary::HttpResponse
- Inherits:
-
Object
- Object
- CoreLibrary::HttpResponse
- Defined in:
- lib/apimatic-core/http/response/http_response.rb
Overview
Http response received.
Constant Summary collapse
- BODY_PARAM_POINTER =
'$response.body'.freeze
- HEADER_PARAM_POINTER =
'$response.headers'.freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#reason_phrase ⇒ Object
readonly
Returns the value of attribute reason_phrase.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#get_value_by_json_pointer(json_pointer) ⇒ Object?
Resolves a JSON pointer against either the response body or response headers.
-
#initialize(status_code, reason_phrase, headers, raw_body, request) ⇒ HttpResponse
constructor
The constructor.
Constructor Details
#initialize(status_code, reason_phrase, headers, raw_body, request) ⇒ HttpResponse
The constructor
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 15 def initialize(status_code, reason_phrase, headers, raw_body, request) @status_code = status_code @reason_phrase = reason_phrase @headers = headers @raw_body = raw_body @request = request end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 7 def headers @headers end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
7 8 9 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 7 def raw_body @raw_body end |
#reason_phrase ⇒ Object (readonly)
Returns the value of attribute reason_phrase.
7 8 9 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 7 def reason_phrase @reason_phrase end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 7 def request @request end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
7 8 9 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 7 def status_code @status_code end |
Instance Method Details
#get_value_by_json_pointer(json_pointer) ⇒ Object?
Resolves a JSON pointer against either the response body or response headers.
This method is useful when extracting a specific value from an API response using a JSON pointer. It determines whether to extract from the body or headers based on the prefix in the pointer.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/apimatic-core/http/response/http_response.rb', line 35 def get_value_by_json_pointer(json_pointer) param_pointer, field_pointer = JsonPointerHelper.split_into_parts(json_pointer) value = case param_pointer when HEADER_PARAM_POINTER JsonPointerHelper.get_value_by_json_pointer(@headers, field_pointer) when BODY_PARAM_POINTER JsonPointerHelper.get_value_by_json_pointer( ApiHelper.json_deserialize(@raw_body), field_pointer ) else nil end value.nil? || (value.is_a? JsonPointer::NotFound) ? nil : value end |