Class: Pricesphere::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/pricesphere/product.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Pricesphere::Base

Instance Method Details

#search(term = '') ⇒ Object



3
4
5
6
# File 'lib/pricesphere/product.rb', line 3

def search(term = '')
  return {} if term == ''
  with_attributes( search: term )
end

#with_attributes(attributes = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pricesphere/product.rb', line 8

def with_attributes(attributes = {})
  return {} if attributes == {}
  page = 1
  last_page = false
  Enumerator.new do |yielder|
    loop do
      raise StopIteration if last_page
      result = get(attributes.merge(page: page))

      if page == result['meta']['pages'].to_i
        last_page = true
      end
      page += 1
      result['products'].each do |product|
        yielder.yield product
      end
    end

  end
end