Class: CatalogAPI::Order
- Inherits:
-
Object
- Object
- CatalogAPI::Order
- Defined in:
- lib/catalogapi/order.rb
Instance Attribute Summary collapse
-
#address_1 ⇒ Object
readonly
Returns the value of attribute address_1.
-
#address_2 ⇒ Object
readonly
Returns the value of attribute address_2.
-
#address_3 ⇒ Object
readonly
Returns the value of attribute address_3.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#date_placed ⇒ Object
readonly
Returns the value of attribute date_placed.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#external_order_number ⇒ Object
readonly
Returns the value of attribute external_order_number.
-
#external_user_id ⇒ Object
readonly
Returns the value of attribute external_user_id.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#fulfillments ⇒ Object
readonly
Returns the value of attribute fulfillments.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#order_number ⇒ Object
readonly
Returns the value of attribute order_number.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#postal_code ⇒ Object
readonly
Returns the value of attribute postal_code.
-
#state_province ⇒ Object
readonly
Returns the value of attribute state_province.
Class Method Summary collapse
-
.list(options = {}, request = nil) ⇒ Array[CatalogAPI::Order]
Return all orders placed by that user.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Order
constructor
A new instance of Order.
-
#place ⇒ CatalogAPI::Order
Place an order without requiring a cart.
-
#track ⇒ CatalogAPI::Order
Return the details of a previously placed order, including any shipment information.
Constructor Details
#initialize(opts) ⇒ Order
Returns a new instance of Order.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/catalogapi/order.rb', line 11 def initialize(opts) @date_placed = nil if opts[:date_placed] && !opts[:date_placed].empty? @date_placed = Time.parse(opts[:date_placed]).to_time end @external_user_id = opts[:external_user_id] @order_number = opts[:order_number] @external_user_id = opts[:external_user_id] @external_order_number = opts[:external_order_number] @first_name = opts[:first_name] @last_name = opts[:last_name] @address_1 = opts[:address_1] @address_2 = opts[:address_2] @address_3 = opts[:address_3] @city = opts[:city] @state_province = opts[:state_province] @postal_code = opts[:postal_code] @country = opts[:country] @email = opts[:email] @phone_number = opts[:phone_number] @fulfillments = opts[:fulfillments].to_a @items = opts[:items].to_a end |
Instance Attribute Details
#address_1 ⇒ Object (readonly)
Returns the value of attribute address_1.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def address_1 @address_1 end |
#address_2 ⇒ Object (readonly)
Returns the value of attribute address_2.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def address_2 @address_2 end |
#address_3 ⇒ Object (readonly)
Returns the value of attribute address_3.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def address_3 @address_3 end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def country @country end |
#date_placed ⇒ Object (readonly)
Returns the value of attribute date_placed.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def date_placed @date_placed end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def email @email end |
#external_order_number ⇒ Object (readonly)
Returns the value of attribute external_order_number.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def external_order_number @external_order_number end |
#external_user_id ⇒ Object (readonly)
Returns the value of attribute external_user_id.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def external_user_id @external_user_id end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def first_name @first_name end |
#fulfillments ⇒ Object (readonly)
Returns the value of attribute fulfillments.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def fulfillments @fulfillments end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def items @items end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def last_name @last_name end |
#order_number ⇒ Object (readonly)
Returns the value of attribute order_number.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def order_number @order_number end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def phone_number @phone_number end |
#postal_code ⇒ Object (readonly)
Returns the value of attribute postal_code.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def postal_code @postal_code end |
#state_province ⇒ Object (readonly)
Returns the value of attribute state_province.
5 6 7 |
# File 'lib/catalogapi/order.rb', line 5 def state_province @state_province end |
Class Method Details
.list(options = {}, request = nil) ⇒ Array[CatalogAPI::Order]
Return all orders placed by that user.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/catalogapi/order.rb', line 42 def list( = {}, request = nil) external_user_id = [:external_user_id] raise CatalogAPI::Error, 'No External User ID' if external_user_id.nil? request ||= CatalogAPI.request.new(:order_list) request = request.get(.merge(external_user_id: external_user_id)) orders = request.json.dig( :order_list_response, :order_list_result, :orders, :OrderSummary ).to_a request.data += orders.map { |item| CatalogAPI::Order.new(item.merge(external_user_id: external_user_id)) } # Pagination next_page = [:paginated] ? request.next_page : nil request = list(.merge(page: next_page), request) if next_page request end |
Instance Method Details
#place ⇒ CatalogAPI::Order
Place an order without requiring a cart.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/catalogapi/order.rb', line 61 def place raise CatalogAPI::Error, 'No Items' if items.nil? || items.length.zero? raise CatalogAPI::Error, 'No Socket ID' if items.first.socket_id.nil? raise CatalogAPI::Error, 'No First Name' if first_name.nil? raise CatalogAPI::Error, 'No Last Name' if last_name.nil? raise CatalogAPI::Error, 'No Adress1' if address_1.nil? raise CatalogAPI::Error, 'No City' if city.nil? raise CatalogAPI::Error, 'No State' if state_province.nil? raise CatalogAPI::Error, 'No Postal Code' if postal_code.nil? raise CatalogAPI::Error, 'No Country' if country.nil? raise CatalogAPI::Error, 'No Items' if items.nil? request = CatalogAPI.request.new(:order_place) request.post(place_params(request)) json = request.json.dig(:order_place_response, :order_place_result) request.data = CatalogAPI::Order.new(json) request end |
#track ⇒ CatalogAPI::Order
Return the details of a previously placed order, including any shipment information.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/catalogapi/order.rb', line 81 def track raise CatalogAPI::Error, 'No Order Number' if order_number.nil? request = CatalogAPI.request.new(:order_track).get(order_number: order_number) json = request.json.dig(:order_track_response, :order_track_result, :order) items = json.dig(:items, :OrderItem).to_a.map { |i| CatalogAPI::OrderItem.new(i) } fulfillments = json.dig(:fulfillments, :Fulfillment).to_a.map { |i| CatalogAPI::Fulfillment.new(i) } request.data = CatalogAPI::Order.new(json.merge(items: items, fulfillments: fulfillments)) request end |