Class: FetchAppAPI::Product
- Defined in:
- lib/fetchapp-api-ruby/product.rb
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 Product.
-
.find(selector, params = {}) ⇒ Object
Find :all products or a specific SKU.
Instance Method Summary collapse
-
#destroy ⇒ Object
Permanently deletes the Product.
-
#downloads ⇒ Object
Returns all the downloads associated with this Product.
-
#files ⇒ Object
Returns all the downloads associated with this Product.
-
#initialize(id_or_attributes) ⇒ Product
constructor
:nodoc:.
-
#stats ⇒ Object
Returns stats about this Product.
-
#update(options) ⇒ Object
Immediately updates the Product.
Methods inherited from Base
basic_auth, can_connect?, key, time
Constructor Details
#initialize(id_or_attributes) ⇒ Product
:nodoc:
5 6 7 8 9 10 11 12 13 |
# File 'lib/fetchapp-api-ruby/product.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 FetchAppAPI::Base
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/fetchapp-api-ruby/product.rb', line 3 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/fetchapp-api-ruby/product.rb', line 3 def id @id end |
Class Method Details
.create(options) ⇒ Object
Creates a new Product
27 28 29 |
# File 'lib/fetchapp-api-ruby/product.rb', line 27 def self.create() return FetchAppAPI::Product.new(execute(:post, "/products/create", :product => )["product"]) end |
.find(selector, params = {}) ⇒ Object
Find :all products or a specific SKU
21 22 23 |
# File 'lib/fetchapp-api-ruby/product.rb', line 21 def self.find(selector, params={}) super(selector, params) end |
Instance Method Details
#destroy ⇒ Object
Permanently deletes the Product
36 37 38 |
# File 'lib/fetchapp-api-ruby/product.rb', line 36 def destroy delete("/products/#{self.sku}/delete") end |
#downloads ⇒ Object
Returns all the downloads associated with this Product
47 48 49 50 51 52 |
# File 'lib/fetchapp-api-ruby/product.rb', line 47 def downloads downloads = get("/products/#{sku}/downloads") if downloads downloads["downloads"].map { |data| FetchAppAPI::Download.new(data) } end end |
#files ⇒ Object
Returns all the downloads associated with this Product
55 56 57 58 59 60 |
# File 'lib/fetchapp-api-ruby/product.rb', line 55 def files files = get("/products/#{sku}/files") if files files["files"].map { |data| FetchAppAPI::File.new(data) } end end |
#stats ⇒ Object
Returns stats about this Product
63 64 65 66 67 68 |
# File 'lib/fetchapp-api-ruby/product.rb', line 63 def stats stats = get("/products/#{sku}/stats") if stats FetchAppAPI::Product.new(stats["product"]) end end |
#update(options) ⇒ Object
Immediately updates the Product
41 42 43 44 |
# File 'lib/fetchapp-api-ruby/product.rb', line 41 def update() self.attributes = put("/products/#{self.sku}", :product => )["product"] self.id = self.sku end |