Sha256: f93892b0a1af98cfa42977704cc733bf68204dcaf3bb57a40c8504b6e43708fe

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

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
      ]

      def add(params)
        self.orders ||= []
        params.delete_if { |k, v| COLUMNS.include?(k) == false }
        orders.push(params)
        params
      end

      def [](index)
        orders[index]
      end

      def count
        orders.count
      end

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

      protected

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xdelivery-0.1.0 lib/xdelivery/api/orders.rb