Class: Atlast::Fulfillment
- Inherits:
-
Object
- Object
- Atlast::Fulfillment
- Defined in:
- lib/atlast/fulfillment.rb
Constant Summary collapse
- ROOT_URL =
"https://api.atlastfulfillment.com"
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #available?(sku) ⇒ Boolean
- #cancel(order_id) ⇒ Object
-
#initialize(key) ⇒ Fulfillment
constructor
A new instance of Fulfillment.
- #inventory(sku = nil) ⇒ Object
- #product(sku) ⇒ Object
- #products ⇒ Object
- #ship(options) ⇒ Object
- #shipment_status(order_id) ⇒ Object
Constructor Details
#initialize(key) ⇒ Fulfillment
Returns a new instance of Fulfillment.
6 7 8 |
# File 'lib/atlast/fulfillment.rb', line 6 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/atlast/fulfillment.rb', line 4 def key @key end |
Instance Method Details
#available?(sku) ⇒ Boolean
26 27 28 |
# File 'lib/atlast/fulfillment.rb', line 26 def available?(sku) inventory(sku)["response"]["products"]["product"]["availableQuantity"].to_i > 0 end |
#cancel(order_id) ⇒ Object
66 67 68 69 70 |
# File 'lib/atlast/fulfillment.rb', line 66 def cancel(order_id) params = {key: key, orderId: order_id} response = RestClient.get ROOT_URL + "/cancel_shipment.aspx", params: params Crack::XML.parse response end |
#inventory(sku = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/atlast/fulfillment.rb', line 18 def inventory(sku=nil) params = {key: key} params[:sku] = sku if sku inventory_xml = RestClient.get ROOT_URL + "/inventory.aspx", params: params Crack::XML.parse inventory_xml end |
#product(sku) ⇒ Object
15 16 |
# File 'lib/atlast/fulfillment.rb', line 15 def product(sku) end |
#products ⇒ Object
10 11 12 13 |
# File 'lib/atlast/fulfillment.rb', line 10 def products products_xml = RestClient.get(ROOT_URL + "/products.aspx", params: {key: key}) Crack::XML.parse products_xml end |
#ship(options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atlast/fulfillment.rb', line 30 def ship() address = [:address] ship_method = [:ship_method] items = [:items] order_id = [:order_id] || UUID.new.generate builder = Builder::XmlMarkup.new builder.instruct! :xml, version: "1.0", encoding: "UTF-8" xml = builder.Orders(apiKey: key) do |orders| orders.Order(orderID: order_id) do |order| order.CustomerInfo do |ci| ci.FirstName address.first_name ci.LastName address.last_name ci.Address1 address.address ci.Address2 address.suite ci.City address.city ci.State address.state ci.Zip address.postal_code ci.Country "USA" end order.OrderDate Time.now.strftime("%D") order.ShipMethod ship_method order.Items do |xml_items| items.each do |item| xml_items.Item do |xml_item| xml_item.SKU item.sku xml_item.Qty item.quantity end end end end end response = RestClient.post(ROOT_URL + "/post_shipments.aspx", xml, content_type: :xml, accept: :xml) Crack::XML.parse response end |
#shipment_status(order_id) ⇒ Object
72 73 74 75 76 |
# File 'lib/atlast/fulfillment.rb', line 72 def shipment_status(order_id) params = {key: key, id: order_id} response = RestClient.get ROOT_URL + "/shipments.aspx", params: params Crack::XML.parse response end |