Sha256: 3ad4cdca7f52f57059db2954d44f9bb03df55d01a74b5e041906533b0a61ec2e

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module Xdelivery
  module API
    class Orders < Base
      include Enumerable

      attr_accessor :orders

      COLUMNS = [
        :order_id, :provider, :recipient, :mobile, :email, :store_id, :store_name, :address,
        :items, :warehouse_items, :total_order_amount, :cash_on_delivery, :order_created_at,
        :note, :callback_url, :ref_id, :tag, :merchant_note, :shop_id
      ]

      INVOICE_COLUMNS = [
        :create_type, :email, :company_code, :company_title, :donate_code, :device_id, :device, :items
      ]

      def add(params, invoice_params={})
        self.orders ||= []
        (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?

        orders.push(params)
        params
      end

      def [](index)
        orders[index]
      end

      def count
        orders.count
      end

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

      protected

      def post_data
        { import: { orders: orders } }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xdelivery-2.0.3 lib/xdelivery/api/orders.rb
xdelivery-2.0.1 lib/xdelivery/api/orders.rb
xdelivery-2.0.0 lib/xdelivery/api/orders.rb
xdelivery-1.0.2 lib/xdelivery/api/orders.rb
xdelivery-1.0.1 lib/xdelivery/api/orders.rb
xdelivery-1.0.0 lib/xdelivery/api/orders.rb