Class: Lipseys::Order

Inherits:
SoapClient show all
Defined in:
lib/lipseys/order.rb

Overview

Required options when submitting an order:

  • ‘:email` and `:password`

  • ‘:item_number` OR `:upc`

  • ‘:quantity`

  • ‘:purchase_order`

Optional order params:

  • ‘:notify_by_email` (boolean)

  • ‘:note`

Constant Summary

Constants inherited from SoapClient

SoapClient::API_URL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Order

Returns a new instance of Order.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lipseys/order.rb', line 15

def initialize(options = {})
  requires!(options, :username, :password, :quantity, :purchase_order)
  @email = options[:username]
  @password = options[:password]
  @quantity = options[:quantity]

  @notify_by_email = (options[:notify_by_email] == true ? 'Y' : nil)
  @purchase_order = options[:purchase_order]
  @note = options[:note]

  @item_number_or_upc = options[:item_number] || options[:upc]
  raise ArgumentError.new("Either :item_number or :upc must be given") if @item_number_or_upc.nil?
end

Class Method Details

.submit!(*args) ⇒ Object



30
31
32
# File 'lib/lipseys/order.rb', line 30

def self.submit!(*args)
  new(*args).submit!
end

Instance Method Details

#submit!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lipseys/order.rb', line 34

def submit!
  response = soap_client.call(:submit_order, message: build_order_data)

  raise Lipseys::NotAuthenticated if not_authenticated?(response)

  order_result = response.body[:submit_order_response][:submit_order_result]

  {
    order_number: order_result[:order_no],
    new_order: (order_result[:new_order] == 'Y'),
    success: (order_result[:success] == 'Y'),
    description: order_result[:return_desc],
    quantity_received: Integer(order_result[:qty_received]),
  }
rescue Savon::Error => e
  { success: false, description: e.to_s }
end