Class: ConveyClient::Items

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/convey_client/items.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Items

Returns a new instance of Items.



9
10
11
12
13
# File 'lib/convey_client/items.rb', line 9

def initialize(path)
  self.path = path
  self.items = nil
  self.search_params = []
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/convey_client/items.rb', line 7

def items
  @items
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/convey_client/items.rb', line 7

def path
  @path
end

#search_paramsObject

Returns the value of attribute search_params.



7
8
9
# File 'lib/convey_client/items.rb', line 7

def search_params
  @search_params
end

#sort_dirObject

Returns the value of attribute sort_dir.



7
8
9
# File 'lib/convey_client/items.rb', line 7

def sort_dir
  @sort_dir
end

#sort_keyObject

Returns the value of attribute sort_key.



7
8
9
# File 'lib/convey_client/items.rb', line 7

def sort_key
  @sort_key
end

Class Method Details

.allObject



53
54
55
# File 'lib/convey_client/items.rb', line 53

def self.all
  new("items")
end

.find(item_id) ⇒ Object



49
50
51
# File 'lib/convey_client/items.rb', line 49

def self.find(item_id)
  new("items/#{item_id}").to_a.first
end

.in_bucket(bucket_id) ⇒ Object



57
58
59
# File 'lib/convey_client/items.rb', line 57

def self.in_bucket(bucket_id)
  new("buckets/#{bucket_id}/items")
end

.in_bucket_and_using_template(bucket_id, template_id) ⇒ Object



65
66
67
# File 'lib/convey_client/items.rb', line 65

def self.in_bucket_and_using_template(bucket_id, template_id)
  new("buckets/#{bucket_id}/templates/#{template_id}/items")
end

.using_template(template_id) ⇒ Object



61
62
63
# File 'lib/convey_client/items.rb', line 61

def self.using_template(template_id)
  new("templates/#{template_id}/items")
end

Instance Method Details

#[](index) ⇒ Object



45
46
47
# File 'lib/convey_client/items.rb', line 45

def [](index)
  to_a[index]
end

#eachObject



26
27
28
29
# File 'lib/convey_client/items.rb', line 26

def each
  to_a
  items.each { |item| yield item }
end

#lengthObject



31
32
33
34
# File 'lib/convey_client/items.rb', line 31

def length
  to_a
  items.length
end

#sorted(key, dir) ⇒ Object



15
16
17
18
19
# File 'lib/convey_client/items.rb', line 15

def sorted(key, dir)
  self.sort_key = key
  self.sort_dir = dir
  self
end

#to_aObject



36
37
38
39
40
41
42
43
# File 'lib/convey_client/items.rb', line 36

def to_a
  return items if items

  parse(ConveyClient::Request.execute(url))
  items
rescue RequestError
  self.items = []
end

#where(key, operator, val) ⇒ Object



21
22
23
24
# File 'lib/convey_client/items.rb', line 21

def where(key, operator, val)
  search_params << [ key, operator, val ]
  self
end