Class: RakutenApi::Base::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rakuten_api/base/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response = nil) ⇒ Response

Returns a new instance of Response.

Raises:



9
10
11
12
13
# File 'lib/rakuten_api/base/response.rb', line 9

def initialize(faraday_response = nil)
  raise RakutenApi::Error.new('not specified Faraday::Response') if !faraday_response.nil? && !faraday_response.kind_of?(::Faraday::Response)
  @status = faraday_response.nil? ? nil : faraday_response.status
  @body = json_parse(faraday_response.nil? ? '' : faraday_response.body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/rakuten_api/base/response.rb', line 7

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/rakuten_api/base/response.rb', line 6

def status
  @status
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rakuten_api/base/response.rb', line 19

def error?
  !success?
end

#error_messageObject



23
24
25
26
27
28
29
# File 'lib/rakuten_api/base/response.rb', line 23

def error_message
  nil if success?
  message = ''
  message += @body['error'] + ': ' if @body.include? 'error'
  message += @body['error_description'] if @body.include? 'error_description'
  message == '' ? 'no error message' : message;
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rakuten_api/base/response.rb', line 15

def success?
  @status == 200
end