Class: InvisibleHand::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/invisiblehand/response.rb

Constant Summary collapse

FIELDS =

Array of fields that exist on a response returned from the InvisibleHand API.

[
  :info,
  :results,
]

Instance Method Summary collapse

Constructor Details

#initialize(raw, api) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
19
20
21
22
# File 'lib/invisiblehand/response.rb', line 14

def initialize raw, api
  @api = api
  @raw = raw
  FIELDS.each { |key| self.send("#{key}=", @raw[key.to_s]) }

  if @raw["results"]
    self.results = @raw["results"].map { |json| Product.new(json, @api) }
  end
end

Instance Method Details

#each(&block) ⇒ Object



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

def each &block
  self.results.each(&block)
end