Class: RemoteResource::Response
- Inherits:
-
Object
- Object
- RemoteResource::Response
- Defined in:
- lib/remote_resource/response.rb
Instance Method Summary collapse
- #error_messages_response_body ⇒ Object
-
#initialize(response, connection_options = {}) ⇒ Response
constructor
A new instance of Response.
- #parsed_response_body ⇒ Object
- #response_body ⇒ Object
- #response_code ⇒ Object
- #sanitized_response_body ⇒ Object
- #sanitized_response_meta ⇒ Object
- #success? ⇒ Boolean
- #unprocessable_entity? ⇒ Boolean
Constructor Details
#initialize(response, connection_options = {}) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 |
# File 'lib/remote_resource/response.rb', line 7 def initialize(response, = {}) @original_response = response @original_request = response.request @connection_options = end |
Instance Method Details
#error_messages_response_body ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/remote_resource/response.rb', line 45 def return empty_hash if response_body.blank? return empty_hash if parsed_response_body.blank? return parsed_response_body["errors"] if parsed_response_body.try :has_key?, "errors" return unpacked_parsed_response_body["errors"] if unpacked_parsed_response_body.try :has_key?, "errors" empty_hash end |
#parsed_response_body ⇒ Object
55 56 57 58 59 |
# File 'lib/remote_resource/response.rb', line 55 def parsed_response_body @parsed_response_body ||= JSON.parse response_body rescue JSON::ParserError nil end |
#response_body ⇒ Object
21 22 23 |
# File 'lib/remote_resource/response.rb', line 21 def response_body original_response.body end |
#response_code ⇒ Object
25 26 27 |
# File 'lib/remote_resource/response.rb', line 25 def response_code original_response.response_code end |
#sanitized_response_body ⇒ Object
29 30 31 32 33 34 |
# File 'lib/remote_resource/response.rb', line 29 def sanitized_response_body return empty_hash if response_body.blank? return empty_hash if parsed_response_body.blank? unpacked_parsed_response_body end |
#sanitized_response_meta ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/remote_resource/response.rb', line 36 def return empty_hash if response_body.blank? return empty_hash if parsed_response_body.blank? return parsed_response_body['meta'] if parsed_response_body.try :has_key?, 'meta' empty_hash end |
#success? ⇒ Boolean
13 14 15 |
# File 'lib/remote_resource/response.rb', line 13 def success? original_response.success? end |
#unprocessable_entity? ⇒ Boolean
17 18 19 |
# File 'lib/remote_resource/response.rb', line 17 def unprocessable_entity? response_code == 422 end |