class Retentiongrid::Order

Retentiongrid Order

To create a new Retentiongrid::Order object:

order = Retentiongrid::Order.new(order_id: "A123", customer_id: 'C123', currency: 'EUR', total_price: 12.00, order_created_at: Time.now).save

To get a order from the API:

order = Retentiongrid::Order.find('A123')

Constants

ATTRIBUTES_NAMES

The set of attributes defined by the API documentation

BASE_PATH

Attributes

customer[RW]

Public Class Methods

find(order_id) click to toggle source

Find an order with given id @param [Fixnum] order_id the order id to be found @return [Order] if found any

# File lib/retentiongrid/order.rb, line 44
def self.find(order_id)
  begin
    result = Api.get("#{BASE_PATH}/#{order_id}")
    new(result.parsed_response["rg_order"])
  rescue NotFound
    nil
  end
end
new(attribs={}) click to toggle source
Calls superclass method
# File lib/retentiongrid/order.rb, line 25
def initialize(attribs={})
  super
  if order_created_at.class == String && !order_created_at.nil?
    @order_created_at = Time.parse(order_created_at)
  end
end

Public Instance Methods

customer=(customer) click to toggle source

relations

# File lib/retentiongrid/order.rb, line 34
def customer=(customer)
  @customer_id = customer.customer_id
  @customer = customer
end
destroy() click to toggle source

Delete this order at retention grid @return [Boolean] successfully deleted?

# File lib/retentiongrid/order.rb, line 63
def destroy
  Api.delete("#{BASE_PATH}/#{order_id}")
  true
end
save!() click to toggle source

Create or update an order with given id @return [Order] if successfully created or updated @raise [Httparty::Error] for all sorts of HTTP statuses.

# File lib/retentiongrid/order.rb, line 56
def save!
  result = Api.post("#{BASE_PATH}/#{order_id}", { body: attributes.to_json })
  Order.new(result.parsed_response["rg_order"])
end