class HornOfPlenty::Response
Attributes
raw_response[RW]
Public Class Methods
new(raw_response:)
click to toggle source
# File lib/horn_of_plenty/response.rb, line 9 def initialize(raw_response:) self.raw_response = raw_response end
parse(raw_response)
click to toggle source
# File lib/horn_of_plenty/response.rb, line 22 def self.parse(raw_response) new(raw_response: raw_response).tap do |response| fail response.error unless response.successful? end end
Public Instance Methods
body()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 28 def body @body ||= JSON.parse(raw_response.body) || '' end
items()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 18 def items @items ||= body.is_a?(Array) ? body : [body] end
result()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 13 def result @result ||= ::HornOfPlenty::Collection.new(items: items, parser: parser_class) end
status_code()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 32 def status_code @status_code ||= raw_response.status end
status_message()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 36 def status_message @status_message ||= body['message'] end
successful?()
click to toggle source
# File lib/horn_of_plenty/response.rb, line 40 def successful? (200..299).cover? status_code end