Class: FetchAPI::Item
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.create(options) ⇒ Object
Creates a new Item.
-
.find(selector, params = {}) ⇒ Object
Find :all items or a specific SKU.
Instance Method Summary collapse
-
#destroy ⇒ Object
Permanently deletes the Item.
-
#downloads ⇒ Object
Returns all the downloads associated with this Item.
-
#initialize(id_or_attributes) ⇒ Item
constructor
:nodoc:.
-
#update(options) ⇒ Object
Immediately updates the Item.
Methods inherited from Base
Constructor Details
#initialize(id_or_attributes) ⇒ Item
:nodoc:
5 6 7 8 9 10 11 12 13 |
# File 'lib/fetchapi/item.rb', line 5 def initialize(id_or_attributes) #:nodoc: case id_or_attributes when Integer, String @attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}") @attributes = @attributes[self.class.singularized_class_name] when Hash @attributes = id_or_attributes end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FetchAPI::Base
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/fetchapi/item.rb', line 3 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/fetchapi/item.rb', line 3 def id @id end |
Class Method Details
.create(options) ⇒ Object
Creates a new Item
27 28 29 |
# File 'lib/fetchapi/item.rb', line 27 def self.create() return FetchAPI::Item.new(execute(:post, "/items/create", :item => )["item"]) end |
.find(selector, params = {}) ⇒ Object
Find :all items or a specific SKU
21 22 23 |
# File 'lib/fetchapi/item.rb', line 21 def self.find(selector, params={}) super(selector, params={}) end |
Instance Method Details
#destroy ⇒ Object
Permanently deletes the Item
36 37 38 |
# File 'lib/fetchapi/item.rb', line 36 def destroy delete("/items/#{sku}/delete") end |
#downloads ⇒ Object
Returns all the downloads associated with this Item
47 48 49 50 51 52 |
# File 'lib/fetchapi/item.rb', line 47 def downloads downloads = get("/items/#{sku}/downloads") if downloads downloads["downloads"].map { |data| FetchAPI::Download.new(data) } end end |
#update(options) ⇒ Object
Immediately updates the Item
41 42 43 44 |
# File 'lib/fetchapi/item.rb', line 41 def update() self.attributes = put("/items/#{sku}", :item => )["item"] self.id = self.sku end |