Class: Celery::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/celery/resources/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Product

Returns a new instance of Product.



5
6
7
# File 'lib/celery/resources/product.rb', line 5

def initialize(api)
  @api = api
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



3
4
5
# File 'lib/celery/resources/product.rb', line 3

def api
  @api
end

Instance Method Details

#all(params = {}) ⇒ JSON

Returns a list of products you have.

Examples:


products = celery.product.all(limit: 25, skip: 2, sort: 'created', order: 'asc')
products.total
=> 28

Parameters:

  • limit (Integer)

    (optional) Limit the number of results.

  • skip (Integer)

    (optional) Skip n results.

  • sort (String)

    (optional) Field name to sort on.

  • order (String)

    (optional) Either ‘asc` or `desc`.

Returns:

  • (JSON)

    A JSON object with the following attributes:

    • total [Integer]

    • count [Integer]

    • offset [Integer]

    • limit [Integer]

    • has_more [Boolean]

    • products [Array]

See Also:



32
33
34
# File 'lib/celery/resources/product.rb', line 32

def all(params = {})
  @api.get("products", query: params)
end

#destroy(product_id) ⇒ JSON

Deletes an existing product object.

Examples:


result = celery.product.destroy("123abc")
result["status"]
=> true

Parameters:

  • product_id (String)

    (required) The identifier of the Product to be deleted.

Returns:

  • (JSON)

    A JSON object with the following attributes:

    • status [Boolean]

See Also:



117
118
119
# File 'lib/celery/resources/product.rb', line 117

def destroy(product_id)
  @api.delete("products/#{product_id}")
end

#find(product_id) ⇒ JSON

Retrieves a product that has previously been created.

Examples:


product = celery.product.find("123abc")
product["slug"]
=> "test-product"

Parameters:

  • product_id (String)

    (required) The identifier of the Product to be retrieved.

Returns:

  • (JSON)

    A Product object.

See Also:



50
51
52
# File 'lib/celery/resources/product.rb', line 50

def find(product_id)
  @api.get("products/#{product_id}")
end

#new(product) ⇒ JSON

Creates a new product object.

Examples:


product = {
  name: "New Product",
  price: 1999,
}
new_product = celery.product.new(product)
new_product["name"]
=> "New Product"

Parameters:

  • product (Hash)

    A hash of product attributes.

Options Hash (product):

  • name (String) — default: optional

    the product name.

  • price (Integer) — default: optional

    in cents.

  • deposit (Integer) — default: optional

    in cents.

  • options (Array) — default: optional

Returns:

  • (JSON)

    A Product object.

See Also:



76
77
78
# File 'lib/celery/resources/product.rb', line 76

def new(product)
  @api.post("products", body: {product: product})
end

#update(product_id, product) ⇒ JSON

Updates an existing product object.

Examples:


product = {
  name: "New Name"
}
updated = celery.product.update("123abc", product)
updated["name"]
=> "New Name"

Parameters:

  • product_id (String)

    (required) The identifier of the Product to be updated.

  • product (Hash)

    A hash of product attributes.

Returns:

  • (JSON)

    A Product object.

See Also:



98
99
100
# File 'lib/celery/resources/product.rb', line 98

def update(product_id, product)
  @api.put("products/#{product_id}", body: {product: product})
end