Class: BestbuyApi::Criteria

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bestbuy_api/criteria.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Criteria

Returns a new instance of Criteria.



10
11
12
# File 'lib/bestbuy_api/criteria.rb', line 10

def initialize(klass)
  @klass = klass
end

Instance Method Details

#criteriaObject



14
15
16
# File 'lib/bestbuy_api/criteria.rb', line 14

def criteria
  @criteria ||= { attributes: [], conditions: {} }
end

#limit(limit) ⇒ Object



32
33
34
35
# File 'lib/bestbuy_api/criteria.rb', line 32

def limit(limit)
  criteria[:limit] = limit.to_i
  self
end

#page(page) ⇒ Object



37
38
39
40
# File 'lib/bestbuy_api/criteria.rb', line 37

def page(page)
  criteria[:page] = page.to_i
  self
end

#responseObject



42
43
44
45
# File 'lib/bestbuy_api/criteria.rb', line 42

def response
  params = Params.new(criteria, @klass.attributes)
  request.find(params.structure)
end

#select(args) ⇒ Object



18
19
20
21
22
23
# File 'lib/bestbuy_api/criteria.rb', line 18

def select(args)
  assert_keys(args, @klass.attributes[:read])

  criteria[:attributes] = args
  self
end

#where(args) ⇒ Object



25
26
27
28
29
30
# File 'lib/bestbuy_api/criteria.rb', line 25

def where(args)
  assert_keys(args, @klass.attributes[:search])

  criteria[:conditions].merge!(args)
  self
end