Class: Cordial::Products

Inherits:
Object
  • Object
show all
Extended by:
Client
Includes:
HTTParty
Defined in:
lib/cordial/products.rb

Overview

Pragmatic wrapper around the products REST Api.

Class Method Summary collapse

Methods included from Client

client

Class Method Details

.create(id:, name:, options: {}) ⇒ Object

Note:

If the product already exists it will be updated.

Create a new product.

Examples:

Usage.

Cordial::Products.create(
  id: 1,
  name: 'Test Product',
  options: {
    price: 99.99,
    variants: [{
      sku: '123',
      attr: {
        color: 'red',
        size: 'L'
      }
    }],
    inStock: true,
    taxable: true,
    enabled: true,
    properties: {test_metadata: 'my test metadata'}
  }
)

Parameters:

  • id (String|Fixnum)
  • name (String)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options:):

  • :price (Float)
  • :variants (Array<Hash>)
  • :inStock (Boolean)
  • :taxable (Boolean)
  • :enabled (Boolean)
  • :tags (Array)
  • :url (String)
  • :properties (Hash)

See Also:



57
58
59
60
61
62
63
64
# File 'lib/cordial/products.rb', line 57

def self.create(id:, name:, options: {})
  body = {
    productID: id,
    productName: name
  }.merge(options).compact

  client.post('/products', body: body.to_json)
end

.find(id:) ⇒ Hash, {"error"=>true, "message"=>"record not found"}

Find a product.

Examples:

Usage

Cordial::Products.find(id: 1)

Returns:

  • (Hash)
  • ({"error"=>true, "message"=>"record not found"})


16
17
18
# File 'lib/cordial/products.rb', line 16

def self.find(id:)
  client.get("/products/#{id}")
end