Class: SpreePlatformApiClient::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#responseObject

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

#codeObject



24
25
26
# File 'lib/spree_platform_api_client/response.rb', line 24

def code
  response.code
end

#error_responseObject



28
29
30
# File 'lib/spree_platform_api_client/response.rb', line 28

def error_response
  "#{response.code} #{response.reason}"
end

#parseObject



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

#reasonObject



20
21
22
# File 'lib/spree_platform_api_client/response.rb', line 20

def reason
  response.reason
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/spree_platform_api_client/response.rb', line 16

def success?
  HTTP_OK_CODES.include?(response.code)
end