Class: Voucherify::Service::Products
- Inherits:
-
Object
- Object
- Voucherify::Service::Products
- Defined in:
- lib/voucherify/service/products.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #create(product) ⇒ Object
- #create_sku(product_id, sku) ⇒ Object
- #delete(product_id) ⇒ Object
- #delete_sku(product_id, sku_id) ⇒ Object
- #get(product_id) ⇒ Object
- #get_sku(product_id, sku_id) ⇒ Object
-
#initialize(client) ⇒ Products
constructor
A new instance of Products.
- #list(query = {}) ⇒ Object
- #list_skus(product_id) ⇒ Object
- #update(product) ⇒ Object
- #update_sku(product_id, sku) ⇒ Object
Constructor Details
#initialize(client) ⇒ Products
Returns a new instance of Products.
8 9 10 |
# File 'lib/voucherify/service/products.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/voucherify/service/products.rb', line 6 def client @client end |
Instance Method Details
#create(product) ⇒ Object
12 13 14 |
# File 'lib/voucherify/service/products.rb', line 12 def create(product) @client.post('/products', product.to_json) end |
#create_sku(product_id, sku) ⇒ Object
32 33 34 |
# File 'lib/voucherify/service/products.rb', line 32 def create_sku(product_id, sku) @client.post("/products/#{URI.encode(product_id)}/skus", sku.to_json) end |
#delete(product_id) ⇒ Object
24 25 26 |
# File 'lib/voucherify/service/products.rb', line 24 def delete(product_id) @client.delete("/products/#{URI.encode(product_id)}") end |
#delete_sku(product_id, sku_id) ⇒ Object
44 45 46 |
# File 'lib/voucherify/service/products.rb', line 44 def delete_sku(product_id, sku_id) @client.delete("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku_id)}") end |
#get(product_id) ⇒ Object
16 17 18 |
# File 'lib/voucherify/service/products.rb', line 16 def get(product_id) @client.get("/products/#{URI.encode(product_id)}") end |
#get_sku(product_id, sku_id) ⇒ Object
36 37 38 |
# File 'lib/voucherify/service/products.rb', line 36 def get_sku(product_id, sku_id) @client.get("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku_id)}") end |
#list(query = {}) ⇒ Object
28 29 30 |
# File 'lib/voucherify/service/products.rb', line 28 def list(query = {}) @client.get('/products', query) end |
#list_skus(product_id) ⇒ Object
48 49 50 |
# File 'lib/voucherify/service/products.rb', line 48 def list_skus(product_id) @client.get("/products/#{URI.encode(product_id)}/skus") end |
#update(product) ⇒ Object
20 21 22 |
# File 'lib/voucherify/service/products.rb', line 20 def update(product) @client.put("/products/#{URI.encode(product['id'] || product[:id])}", product.to_json) end |
#update_sku(product_id, sku) ⇒ Object
40 41 42 |
# File 'lib/voucherify/service/products.rb', line 40 def update_sku(product_id, sku) @client.put("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku['id'] || sku[:id])}", sku.to_json) end |