Class: SpreePlatformApiClient::Response
- Inherits:
-
Object
- Object
- SpreePlatformApiClient::Response
- Defined in:
- lib/spree_platform_api_client/response.rb
Constant Summary collapse
- HTTP_OK_CODES =
%w(200 201 202 203 204 205 206 207 208 226)
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #code ⇒ Object
- #error_response ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #parse ⇒ Object
- #reason ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/spree_platform_api_client/response.rb', line 6 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/spree_platform_api_client/response.rb', line 5 def response @response end |
Instance Method Details
#code ⇒ Object
24 25 26 |
# File 'lib/spree_platform_api_client/response.rb', line 24 def code response.code end |
#error_response ⇒ Object
28 29 30 |
# File 'lib/spree_platform_api_client/response.rb', line 28 def error_response "#{response.code} #{response.reason}" end |
#parse ⇒ Object
10 11 12 13 14 |
# File 'lib/spree_platform_api_client/response.rb', line 10 def parse response.parse(:json) rescue JSON::ParserError response end |
#reason ⇒ Object
20 21 22 |
# File 'lib/spree_platform_api_client/response.rb', line 20 def reason response.reason end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/spree_platform_api_client/response.rb', line 16 def success? HTTP_OK_CODES.include?(response.code) end |