Class: Fulfillment::Order
- Defined in:
- lib/fulfillment/order.rb
Constant Summary collapse
- REJECT_CODE_BAD_ORDER_INFO =
1
- REJECT_CODE_GENERIC =
2
- REJECT_CODE_OUT_OF_STOCK =
3
- REJECT_CODES =
[REJECT_CODE_BAD_ORDER_INFO, REJECT_CODE_GENERIC, REJECT_CODE_OUT_OF_STOCK]
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
- .order_shipments(client, public_id, first_page_num = 1) ⇒ Object
- .processed_transition(client, public_id) ⇒ Object
- .processing_transition(client, public_id) ⇒ Object
-
.ready(client, first_page_num = 1) ⇒ Object
return a collection of orders for fulfiller in ready status.
-
.reject(client, public_id, rejected_code) ⇒ Object
Reject the given FulfillmentOrder based on the public ID.
- .search(client, search_options = {}) ⇒ Object
- .shipped_transition(client, public_id) ⇒ Object
- .shipping_transition(client, public_id) ⇒ Object
- .show(client, public_id) ⇒ Object
Instance Method Summary collapse
- #create_shipment(shipment_hash) ⇒ Object
-
#initialize(client, data) ⇒ Order
constructor
A new instance of Order.
- #order_items(first_page_num = 1) ⇒ Object
- #order_shipments ⇒ Object
- #process ⇒ Object
- #processed ⇒ Object
- #reject(rejected_code) ⇒ Object
- #shipped ⇒ Object
- #shipping ⇒ Object
Constructor Details
#initialize(client, data) ⇒ Order
Returns a new instance of Order.
11 12 13 14 |
# File 'lib/fulfillment/order.rb', line 11 def initialize(client, data) @client = client make_getter_methods(data) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/fulfillment/order.rb', line 9 def client @client end |
Class Method Details
.order_shipments(client, public_id, first_page_num = 1) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
return a collection of orders for fulfiller in ready status
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# 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) ⇒ Object
Reject the given FulfillmentOrder based on the public ID. The client must be the named FulfillmentProvider in order for the “rejection” to be successful.
108 109 110 111 112 113 114 115 116 117 118 119 |
# 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 |
.search(client, search_options = {}) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fulfillment/order.rb', line 147 def search(client, = {}) first_page_num = 1 Fulfillment::PagedResult.construct(first_page_num) do |page_num| curl = Curl::Easy.http_get(client.build_auth_url("/orders/search")) do |curl| client.configure_http(curl) client.set_request_page(curl, page_num) .each { |k, v| client.add_query_parameter(curl, k, v) } curl end raise Fulfillment::SearchException.new("Could not search orders with search options #{}:\n\n Response Body:\n #{curl.body_str}") unless curl.response_code == 200 search_result_order_array = JSON.parse(curl.body_str) orders = [] search_result_order_array.each { |oh| orders << new(client, oh) } Fulfillment::PagingEnvelope.envelop(curl, orders) end end |
.shipped_transition(client, public_id) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# 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 |
Instance Method Details
#create_shipment(shipment_hash) ⇒ Object
40 41 42 |
# 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) ⇒ Object
16 17 18 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/fulfillment/order.rb', line 44 def order_shipments Fulfillment::Order.order_shipments(self.client, self.public_id) end |
#process ⇒ Object
20 21 22 |
# File 'lib/fulfillment/order.rb', line 20 def process Fulfillment::Order.processing_transition(self.client, self.public_id) end |
#processed ⇒ Object
24 25 26 |
# File 'lib/fulfillment/order.rb', line 24 def processed Fulfillment::Order.processed_transition(self.client, self.public_id) end |
#reject(rejected_code) ⇒ Object
36 37 38 |
# File 'lib/fulfillment/order.rb', line 36 def reject(rejected_code) Fulfillment::Order.reject(self.client, self.public_id, rejected_code) end |
#shipped ⇒ Object
32 33 34 |
# File 'lib/fulfillment/order.rb', line 32 def shipped Fulfillment::Order.shipped_transition(self.client, self.public_id) end |
#shipping ⇒ Object
28 29 30 |
# File 'lib/fulfillment/order.rb', line 28 def shipping Fulfillment::Order.shipping_transition(self.client, self.public_id) end |