Class: WalmartApIs::Order

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/order.rb

Overview

Order Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(purchase_order_id:, seller_id:, order_status:, purchase_date:, customer_order_id: SKIP, fulfillment_type: SKIP, last_updated_date: SKIP, order_total: SKIP, shipping_address: SKIP, order_lines: SKIP, additional_properties: nil) ⇒ Order

Returns a new instance of Order.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/walmart_ap_is/models/order.rb', line 86

def initialize(purchase_order_id:, seller_id:, order_status:,
               purchase_date:, customer_order_id: SKIP,
               fulfillment_type: SKIP, last_updated_date: SKIP,
               order_total: SKIP, shipping_address: SKIP, order_lines: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @purchase_order_id = purchase_order_id
  @customer_order_id = customer_order_id unless customer_order_id == SKIP
  @seller_id = seller_id
  @order_status = order_status
  @fulfillment_type = fulfillment_type unless fulfillment_type == SKIP
  @purchase_date = purchase_date
  @last_updated_date = last_updated_date unless last_updated_date == SKIP
  @order_total = order_total unless order_total == SKIP
  @shipping_address = shipping_address unless shipping_address == SKIP
  @order_lines = order_lines unless order_lines == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#customer_order_idString

Customer-facing order reference

Returns:

  • (String)


19
20
21
# File 'lib/walmart_ap_is/models/order.rb', line 19

def customer_order_id
  @customer_order_id
end

#fulfillment_typeFulfillmentType

Customer-facing order reference

Returns:



31
32
33
# File 'lib/walmart_ap_is/models/order.rb', line 31

def fulfillment_type
  @fulfillment_type
end

#last_updated_dateDateTime

Customer-facing order reference

Returns:

  • (DateTime)


39
40
41
# File 'lib/walmart_ap_is/models/order.rb', line 39

def last_updated_date
  @last_updated_date
end

#order_linesArray[OrderLine]

Customer-facing order reference

Returns:



51
52
53
# File 'lib/walmart_ap_is/models/order.rb', line 51

def order_lines
  @order_lines
end

#order_statusOrderStatus

Customer-facing order reference

Returns:



27
28
29
# File 'lib/walmart_ap_is/models/order.rb', line 27

def order_status
  @order_status
end

#order_totalMoney

Customer-facing order reference

Returns:



43
44
45
# File 'lib/walmart_ap_is/models/order.rb', line 43

def order_total
  @order_total
end

#purchase_dateDateTime

Customer-facing order reference

Returns:

  • (DateTime)


35
36
37
# File 'lib/walmart_ap_is/models/order.rb', line 35

def purchase_date
  @purchase_date
end

#purchase_order_idString

Walmart-assigned Purchase Order ID

Returns:

  • (String)


15
16
17
# File 'lib/walmart_ap_is/models/order.rb', line 15

def purchase_order_id
  @purchase_order_id
end

#seller_idString

Customer-facing order reference

Returns:

  • (String)


23
24
25
# File 'lib/walmart_ap_is/models/order.rb', line 23

def seller_id
  @seller_id
end

#shipping_addressAddress2

Customer-facing order reference

Returns:



47
48
49
# File 'lib/walmart_ap_is/models/order.rb', line 47

def shipping_address
  @shipping_address
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/walmart_ap_is/models/order.rb', line 108

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  purchase_order_id =
    hash.key?('purchaseOrderId') ? hash['purchaseOrderId'] : nil
  seller_id = hash.key?('sellerId') ? hash['sellerId'] : nil
  order_status = hash.key?('orderStatus') ? hash['orderStatus'] : nil
  purchase_date = if hash.key?('purchaseDate')
                    (DateTimeHelper.from_rfc3339(hash['purchaseDate']) if hash['purchaseDate'])
                  end
  customer_order_id =
    hash.key?('customerOrderId') ? hash['customerOrderId'] : SKIP
  fulfillment_type =
    hash.key?('fulfillmentType') ? hash['fulfillmentType'] : SKIP
  last_updated_date = if hash.key?('lastUpdatedDate')
                        (DateTimeHelper.from_rfc3339(hash['lastUpdatedDate']) if hash['lastUpdatedDate'])
                      else
                        SKIP
                      end
  order_total = Money.from_hash(hash['orderTotal']) if hash['orderTotal']
  shipping_address = Address2.from_hash(hash['shippingAddress']) if hash['shippingAddress']
  # Parameter is an array, so we need to iterate through it
  order_lines = nil
  unless hash['orderLines'].nil?
    order_lines = []
    hash['orderLines'].each do |structure|
      order_lines << (OrderLine.from_hash(structure) if structure)
    end
  end

  order_lines = SKIP unless hash.key?('orderLines')

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Order.new(purchase_order_id: purchase_order_id,
            seller_id: seller_id,
            order_status: order_status,
            purchase_date: purchase_date,
            customer_order_id: customer_order_id,
            fulfillment_type: fulfillment_type,
            last_updated_date: last_updated_date,
            order_total: order_total,
            shipping_address: shipping_address,
            order_lines: order_lines,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/walmart_ap_is/models/order.rb', line 54

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['purchase_order_id'] = 'purchaseOrderId'
  @_hash['customer_order_id'] = 'customerOrderId'
  @_hash['seller_id'] = 'sellerId'
  @_hash['order_status'] = 'orderStatus'
  @_hash['fulfillment_type'] = 'fulfillmentType'
  @_hash['purchase_date'] = 'purchaseDate'
  @_hash['last_updated_date'] = 'lastUpdatedDate'
  @_hash['order_total'] = 'orderTotal'
  @_hash['shipping_address'] = 'shippingAddress'
  @_hash['order_lines'] = 'orderLines'
  @_hash
end

.nullablesObject

An array for nullable fields



82
83
84
# File 'lib/walmart_ap_is/models/order.rb', line 82

def self.nullables
  []
end

.optionalsObject

An array for optional fields



70
71
72
73
74
75
76
77
78
79
# File 'lib/walmart_ap_is/models/order.rb', line 70

def self.optionals
  %w[
    customer_order_id
    fulfillment_type
    last_updated_date
    order_total
    shipping_address
    order_lines
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



182
183
184
185
186
187
188
189
190
# File 'lib/walmart_ap_is/models/order.rb', line 182

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} purchase_order_id: #{@purchase_order_id.inspect}, customer_order_id:"\
  " #{@customer_order_id.inspect}, seller_id: #{@seller_id.inspect}, order_status:"\
  " #{@order_status.inspect}, fulfillment_type: #{@fulfillment_type.inspect}, purchase_date:"\
  " #{@purchase_date.inspect}, last_updated_date: #{@last_updated_date.inspect}, order_total:"\
  " #{@order_total.inspect}, shipping_address: #{@shipping_address.inspect}, order_lines:"\
  " #{@order_lines.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_last_updated_dateObject



166
167
168
# File 'lib/walmart_ap_is/models/order.rb', line 166

def to_custom_last_updated_date
  DateTimeHelper.to_rfc3339(last_updated_date)
end

#to_custom_purchase_dateObject



162
163
164
# File 'lib/walmart_ap_is/models/order.rb', line 162

def to_custom_purchase_date
  DateTimeHelper.to_rfc3339(purchase_date)
end

#to_sObject

Provides a human-readable string representation of the object.



171
172
173
174
175
176
177
178
179
# File 'lib/walmart_ap_is/models/order.rb', line 171

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} purchase_order_id: #{@purchase_order_id}, customer_order_id:"\
  " #{@customer_order_id}, seller_id: #{@seller_id}, order_status: #{@order_status},"\
  " fulfillment_type: #{@fulfillment_type}, purchase_date: #{@purchase_date},"\
  " last_updated_date: #{@last_updated_date}, order_total: #{@order_total}, shipping_address:"\
  " #{@shipping_address}, order_lines: #{@order_lines}, additional_properties:"\
  " #{@additional_properties}>"
end