class Fulfillment::Order

Constants

REJECT_CODES
REJECT_CODE_BAD_ORDER_INFO
REJECT_CODE_GENERIC
REJECT_CODE_OUT_OF_STOCK

Attributes

client[RW]

Public Class Methods

new(client, data) click to toggle source
# File lib/fulfillment/order.rb, line 11
def initialize(client, data)
  @client = client
  make_getter_methods(data)
end
order_shipments(client, public_id, first_page_num = 1) click to toggle source
# File lib/fulfillment/order.rb, line 49
def order_shipments(client, public_id, first_page_num = 1)
  Fulfillment::PagedResult.construct(first_page_num) do |page_num|
    curl = Curl::Easy.http_get(client.build_auth_url("/orders/#{public_id}/shipments")) do |curl|
      client.configure_http(curl)
      client.set_request_page(curl, page_num)
    end

    raise Fulfillment::ClientException.new("Could not load index of shipments for #{public_id}: \n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

    shipment_hashes = JSON.parse(curl.body_str)
    result = shipment_hashes.map { |sh| Fulfillment::Shipment.new(client, sh) }

    Fulfillment::PagingEnvelope.envelop(curl, result)
  end
end
processed_transition(client, public_id) click to toggle source
# File lib/fulfillment/order.rb, line 75
def processed_transition(client, public_id)
  curl = Curl::Easy.http_put(client.build_auth_url("/orders/#{public_id}/processed"), {}) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::CreationException.new("Could not complete processed transition for #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end
processing_transition(client, public_id) click to toggle source
# File lib/fulfillment/order.rb, line 65
def processing_transition(client, public_id)
  curl = Curl::Easy.http_put(client.build_auth_url("/orders/#{public_id}/process"), {}) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::CreationException.new("Could not complete processing transition for #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end
ready(client, first_page_num = 1) click to toggle source

return a collection of orders for fulfiller in ready status

# File lib/fulfillment/order.rb, line 132
def ready(client, first_page_num = 1)
  Fulfillment::PagedResult.construct(first_page_num) do |page_num|
    curl = Curl::Easy.new(client.build_auth_url("/orders/ready")) do |curl|
      client.configure_http(curl)
      client.set_request_page(curl, page_num)
    end

    curl.perform
    ready_order_hashes = JSON.parse(curl.body_str)
    result = ready_order_hashes.map { |roh| new(client, roh) }

    Fulfillment::PagingEnvelope.envelop(curl, result)
  end
end
reject(client, public_id, rejected_code) click to toggle source

Reject the given FulfillmentOrder based on the public ID. The client must be the named FulfillmentProvider in order for the “rejection” to be successful.

# File lib/fulfillment/order.rb, line 108
def reject(client, public_id, rejected_code)
  raise ArgumentError.new("Invalid Reject Code. The following are valid reject codes #{REJECT_CODES.join(",")}") unless REJECT_CODES.include?(rejected_code)
  error_payload = {"rejected_code" => rejected_code}

  curl = Curl::Easy.http_put(client.build_auth_url("/orders/#{public_id}/reject"), error_payload.to_json) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::CreationException.new("Could not reject order for #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end
shipped_transition(client, public_id) click to toggle source
# File lib/fulfillment/order.rb, line 95
def shipped_transition(client, public_id)
  curl = Curl::Easy.http_put(client.build_auth_url("/orders/#{public_id}/shipped"), {}.to_json) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::CreationException.new("Could not create shipped transition for #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end
shipping_transition(client, public_id) click to toggle source
# File lib/fulfillment/order.rb, line 85
def shipping_transition(client, public_id)
  curl = Curl::Easy.http_put(client.build_auth_url("/orders/#{public_id}/shipping"), {}.to_json) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::CreationException.new("Could not create shipped transition for #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end
show(client, public_id) click to toggle source
# File lib/fulfillment/order.rb, line 121
def show(client, public_id)
  curl = Curl::Easy.http_get(client.build_auth_url("/orders/#{public_id}")) do |curl|
    client.configure_http(curl)
  end

  raise Fulfillment::ClientException.new("Could not get Order #{public_id}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200

  new(client, JSON.parse(curl.body_str))
end

Public Instance Methods

create_shipment(shipment_hash) click to toggle source
# File lib/fulfillment/order.rb, line 40
def create_shipment(shipment_hash)
  Fulfillment::Shipment.create(self.client, self.public_id, shipment_hash)
end
order_items(first_page_num = 1) click to toggle source
# File lib/fulfillment/order.rb, line 16
def order_items(first_page_num = 1)
  Fulfillment::OrderItem.list(self.client, self.public_id, first_page_num)
end
order_shipments() click to toggle source
# File lib/fulfillment/order.rb, line 44
def order_shipments
  Fulfillment::Order.order_shipments(self.client, self.public_id)
end
process() click to toggle source
# File lib/fulfillment/order.rb, line 20
def process
  Fulfillment::Order.processing_transition(self.client, self.public_id)
end
processed() click to toggle source
# File lib/fulfillment/order.rb, line 24
def processed
  Fulfillment::Order.processed_transition(self.client, self.public_id)
end
reject(rejected_code) click to toggle source
# File lib/fulfillment/order.rb, line 36
def reject(rejected_code)
  Fulfillment::Order.reject(self.client, self.public_id, rejected_code)
end
shipped() click to toggle source
# File lib/fulfillment/order.rb, line 32
def shipped
  Fulfillment::Order.shipped_transition(self.client, self.public_id)
end
shipping() click to toggle source
# File lib/fulfillment/order.rb, line 28
def shipping
  Fulfillment::Order.shipping_transition(self.client, self.public_id)
end