Class: ConveyClient::Items
- Inherits:
-
Object
- Object
- ConveyClient::Items
- Includes:
- Enumerable
- Defined in:
- lib/convey_client/items.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#path ⇒ Object
Returns the value of attribute path.
-
#search_params ⇒ Object
Returns the value of attribute search_params.
-
#sort_dir ⇒ Object
Returns the value of attribute sort_dir.
-
#sort_key ⇒ Object
Returns the value of attribute sort_key.
Class Method Summary collapse
- .all ⇒ Object
- .find(item_id) ⇒ Object
- .in_bucket(bucket_id) ⇒ Object
- .in_bucket_and_using_template(bucket_id, template_id) ⇒ Object
- .using_template(template_id) ⇒ Object
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
-
#initialize(path) ⇒ Items
constructor
A new instance of Items.
- #length ⇒ Object
- #sorted(key, dir) ⇒ Object
- #to_a ⇒ Object
- #where(key, operator, val) ⇒ Object
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
#items ⇒ Object
Returns the value of attribute items.
7 8 9 |
# File 'lib/convey_client/items.rb', line 7 def items @items end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/convey_client/items.rb', line 7 def path @path end |
#search_params ⇒ Object
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_dir ⇒ Object
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_key ⇒ Object
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
.all ⇒ Object
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 |
#each ⇒ Object
26 27 28 29 |
# File 'lib/convey_client/items.rb', line 26 def each to_a items.each { |item| yield item } end |
#length ⇒ Object
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_a ⇒ Object
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 |