Class: Xdelivery::API::Sales

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xdelivery/api/sales.rb

Constant Summary collapse

COLUMNS =
[
  :order_id, :recipient, :mobile, :email, :address,
  :items, :warehouse_items, :total_order_amount, :cash_on_delivery, :order_created_at,
  :note, :callback_url, :ref_id, :tag, :tracking_code, :merchant_note, :shop_id
]
INVOICE_COLUMNS =
[
  :create_type, :email, :company_code, :company_title, :donate_code, :device_id, :device, :items
]

Constants inherited from Base

Base::BASE_URL

Instance Attribute Summary collapse

Attributes inherited from Base

#access_key, #merchant_no

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Xdelivery::API::Base

Instance Attribute Details

#salesObject

Returns the value of attribute sales.



6
7
8
# File 'lib/xdelivery/api/sales.rb', line 6

def sales
  @sales
end

Instance Method Details

#[](index) ⇒ Object



33
34
35
# File 'lib/xdelivery/api/sales.rb', line 33

def [](index)
  sales[index]
end

#add(params, invoice_params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xdelivery/api/sales.rb', line 18

def add(params, invoice_params={})
  self.sales ||= []
  (params || {}).delete_if do |k, v|
    COLUMNS.include?(k) == false
  end
  invoice_params.delete_if do |k, v|
    INVOICE_COLUMNS.include?(k) == false
  end

  params.merge!(invoice: invoice_params) unless invoice_params.empty?

  sales.push(params)
  params
end

#countObject



37
38
39
# File 'lib/xdelivery/api/sales.rb', line 37

def count
  sales.count
end

#create!Object



41
42
43
44
# File 'lib/xdelivery/api/sales.rb', line 41

def create!
  response = post('/sales/batch.json')
  Response::Orders.new(response)
end