class RakutenApi::Base::Response

Attributes

body[R]
status[R]

Public Class Methods

new(faraday_response = nil) click to toggle source
# 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

Public Instance Methods

error?() click to toggle source
# File lib/rakuten_api/base/response.rb, line 19
def error?
  !success?
end
error_message() click to toggle source
# 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?() click to toggle source
# File lib/rakuten_api/base/response.rb, line 15
def success?
  @status == 200
end

Protected Instance Methods

json_parse(data) click to toggle source
# File lib/rakuten_api/base/response.rb, line 33
def json_parse(data)
  ::JSON.parse(data)
rescue ::JSON::ParserError => e
  {}
end