Sha256: f952f1d4588bce0a2917578a7ec96713ea049c098fe870900182adf6f17f56c3

Contents?: true

Size: 992 Bytes

Versions: 1

Compression:

Stored size: 992 Bytes

Contents

module Wing
  module Actions
    module Orders
      def list_orders(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil, sort: nil })
        get("/order", query: prepare_query(options)).parsed_response
      end

      def get_order(order_id)
        get("/order/#{order_id}").parsed_response
      end

      def create_order(data, options = {})
        post("/order", data, options).parsed_response
      end

      def generate_sticker(order_id:, is_return: true)
        post("/a/awb/#{order_id}#{is_return ? '?returnLabel=true' : ''}").parsed_response
      end

      private

      def prepare_query(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil, sort: nil })
        {
          page: options[:page],
          limit: options[:limit],
          createdBefore: options[:createdBefore],
          createdAfter: options[:createdAfter],
          sort: options[:sort]
        }.delete_if { |key, value| value.nil? }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wing.rb-0.1.2 lib/wing/actions/orders.rb