Class: Twocheckout::Product
- Inherits:
-
HashObject
- Object
- HashObject
- Twocheckout::Product
- Defined in:
- lib/twocheckout/product.rb
Class Method Summary collapse
-
.create(opts) ⇒ Object
Creates a new product and returns the Product object.
-
.find(opts) ⇒ Object
Finds product by ID and returns a Product object.
-
.list(opts) ⇒ Object
Get product list in an array.
- .with_product_id(product_id) ⇒ Object
Instance Method Summary collapse
-
#delete! ⇒ Object
Deletes the product and returns the response.
-
#update(opts) ⇒ Object
Updates product and returns a new Product object.
Methods inherited from HashObject
#initialize, #inspect, #method_missing
Constructor Details
This class inherits a constructor from Twocheckout::HashObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Twocheckout::HashObject
Class Method Details
.create(opts) ⇒ Object
Creates a new product and returns the Product object
19 20 21 22 |
# File 'lib/twocheckout/product.rb', line 19 def self.create(opts) response = Twocheckout::API.request(:post, 'products/create_product', opts) find(:product_id => response['product_id']) end |
.find(opts) ⇒ Object
Finds product by ID and returns a Product object
7 8 9 10 |
# File 'lib/twocheckout/product.rb', line 7 def self.find(opts) response = Twocheckout::API.request(:get, 'products/detail_product', opts) Product.new(response['product']) end |
.list(opts) ⇒ Object
Get product list in an array
45 46 47 48 |
# File 'lib/twocheckout/product.rb', line 45 def self.list(opts) response = Twocheckout::API.request(:get, 'products/list_products', opts) response['products'] end |
.with_product_id(product_id) ⇒ Object
12 13 14 |
# File 'lib/twocheckout/product.rb', line 12 def self.with_product_id(product_id) find(:product_id => product_id) end |
Instance Method Details
#delete! ⇒ Object
Deletes the product and returns the response
37 38 39 40 |
# File 'lib/twocheckout/product.rb', line 37 def delete! opts = {:product_id => self.product_id} Twocheckout::API.request(:post, 'products/delete_product', opts) end |
#update(opts) ⇒ Object
Updates product and returns a new Product object
27 28 29 30 31 32 |
# File 'lib/twocheckout/product.rb', line 27 def update(opts) opts = opts.merge(:product_id => self.product_id) Twocheckout::API.request(:post, 'products/update_product', opts) response = Twocheckout::API.request(:get, 'products/detail_product', opts) Product.new(response['product']) end |