Class: Cordial::Orders

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

Overview

Pragmatic wrapper around the orders REST Api.

Class Method Summary collapse

Methods included from Client

client

Class Method Details

.create(options) ⇒ {"success"=>true}, {"error"=>true, "messages"=>"ID must be unique"}

Note:

This endpoint does not support upsert.

Create a new order.

Examples:

Usage.

Cordial::Orders.create({...})

Returns:

  • ({"success"=>true})
  • ({"error"=>true, "messages"=>"ID must be unique"})


30
31
32
33
# File 'lib/cordial/orders.rb', line 30

def self.create(options)
  order = Cordial::Order.new(options)
  client.post('/orders', body: order.to_json)
end

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

Find an order

Examples:

Usage

Cordial::Orders.find(id: 1)

Parameters:

  • id (String|Fixnum)

    The order’s id.

Returns:

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


17
18
19
# File 'lib/cordial/orders.rb', line 17

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

.index(options = {}) ⇒ Array<Hash>

List Orders matching criteria.

Examples:

Cordial::Orders.index(
  fields: 'orderID,purchaseDate',
  purchaseDate: { 'lt': '2018-10-21 11:11:11' },
  per_page: 5
)

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :fields (String)

    Comma delimited string of fields to be returned.

  • :cID (String)

    Where Customer ID is..

  • :email (String)

    Where email is..

  • :purchaseDate (Hash)

    When purchased on, before, and after (YYYY-MM-DD HH:ii:ss) {

    'eq': '2018-10-31 11:59:59',
    'lt': '2018-10-31 11:59:59',
    'gt': '2018-10-31 11:59:59'
    }
    
  • :page (Fixnum)

    Which page of results

  • :per_page (Fixnum)

    How many results to return on a page (max: 10,000)

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cordial/orders.rb', line 57

def self.index(options = {})
  client.get(
    '/orders',
    query: {
      'fields': options[:fields],
      'cID': options[:cID],
      'email': options[:email],
      'purchaseDate': options[:purchaseDate],
      'page': options[:page],
      'per_page': options[:per_page]
    }.compact
  )
end