Class: WalmartApIs::Shipment

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

Overview

Shipment 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(shipment_id:, shipment_status:, order_id: SKIP, seller_order_id: SKIP, item_list: SKIP, ship_from_address: SKIP, ship_to_address: SKIP, package_dimensions: SKIP, weight: SKIP, insurance: SKIP, shipping_service: SKIP, label: SKIP, created_date: SKIP, last_updated_date: SKIP, additional_properties: nil) ⇒ Shipment

Returns a new instance of Shipment.



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
# File 'lib/walmart_ap_is/models/shipment.rb', line 112

def initialize(shipment_id:, shipment_status:, order_id: SKIP,
               seller_order_id: SKIP, item_list: SKIP,
               ship_from_address: SKIP, ship_to_address: SKIP,
               package_dimensions: SKIP, weight: SKIP, insurance: SKIP,
               shipping_service: SKIP, label: SKIP, created_date: SKIP,
               last_updated_date: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @shipment_id = shipment_id
  @order_id = order_id unless order_id == SKIP
  @seller_order_id = seller_order_id unless seller_order_id == SKIP
  @item_list = item_list unless item_list == SKIP
  @ship_from_address = ship_from_address unless ship_from_address == SKIP
  @ship_to_address = ship_to_address unless ship_to_address == SKIP
  @package_dimensions = package_dimensions unless package_dimensions == SKIP
  @weight = weight unless weight == SKIP
  @insurance = insurance unless insurance == SKIP
  @shipping_service = shipping_service unless shipping_service == SKIP
  @label = label unless label == SKIP
  @shipment_status = shipment_status
  @created_date = created_date unless created_date == SKIP
  @last_updated_date = last_updated_date unless last_updated_date == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#created_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


63
64
65
# File 'lib/walmart_ap_is/models/shipment.rb', line 63

def created_date
  @created_date
end

#insuranceMoney

TODO: Write general description for this method

Returns:



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

def insurance
  @insurance
end

#item_listArray[Item2]

TODO: Write general description for this method

Returns:



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

def item_list
  @item_list
end

#labelLabel

TODO: Write general description for this method

Returns:



55
56
57
# File 'lib/walmart_ap_is/models/shipment.rb', line 55

def label
  @label
end

#last_updated_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


67
68
69
# File 'lib/walmart_ap_is/models/shipment.rb', line 67

def last_updated_date
  @last_updated_date
end

#order_idString

TODO: Write general description for this method

Returns:

  • (String)


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

def order_id
  @order_id
end

#package_dimensionsPackageDimensions

TODO: Write general description for this method

Returns:



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

def package_dimensions
  @package_dimensions
end

#seller_order_idString

TODO: Write general description for this method

Returns:

  • (String)


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

def seller_order_id
  @seller_order_id
end

#ship_from_addressAddress1

TODO: Write general description for this method

Returns:



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

def ship_from_address
  @ship_from_address
end

#ship_to_addressAddress1

TODO: Write general description for this method

Returns:



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

def ship_to_address
  @ship_to_address
end

#shipment_idString

TODO: Write general description for this method

Returns:

  • (String)


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

def shipment_id
  @shipment_id
end

#shipment_statusShipmentStatus

TODO: Write general description for this method

Returns:



59
60
61
# File 'lib/walmart_ap_is/models/shipment.rb', line 59

def shipment_status
  @shipment_status
end

#shipping_serviceShippingService

TODO: Write general description for this method

Returns:



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

def shipping_service
  @shipping_service
end

#weightWeight

TODO: Write general description for this method

Returns:



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

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/walmart_ap_is/models/shipment.rb', line 139

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  shipment_id = hash.key?('shipmentId') ? hash['shipmentId'] : nil
  shipment_status =
    hash.key?('shipmentStatus') ? hash['shipmentStatus'] : nil
  order_id = hash.key?('orderId') ? hash['orderId'] : SKIP
  seller_order_id =
    hash.key?('sellerOrderId') ? hash['sellerOrderId'] : SKIP
  # Parameter is an array, so we need to iterate through it
  item_list = nil
  unless hash['itemList'].nil?
    item_list = []
    hash['itemList'].each do |structure|
      item_list << (Item2.from_hash(structure) if structure)
    end
  end

  item_list = SKIP unless hash.key?('itemList')
  ship_from_address = Address1.from_hash(hash['shipFromAddress']) if hash['shipFromAddress']
  ship_to_address = Address1.from_hash(hash['shipToAddress']) if hash['shipToAddress']
  package_dimensions = PackageDimensions.from_hash(hash['packageDimensions']) if
    hash['packageDimensions']
  weight = Weight.from_hash(hash['weight']) if hash['weight']
  insurance = Money.from_hash(hash['insurance']) if hash['insurance']
  shipping_service = ShippingService.from_hash(hash['shippingService']) if
    hash['shippingService']
  label = Label.from_hash(hash['label']) if hash['label']
  created_date = if hash.key?('createdDate')
                   (DateTimeHelper.from_rfc3339(hash['createdDate']) if hash['createdDate'])
                 else
                   SKIP
                 end
  last_updated_date = if hash.key?('lastUpdatedDate')
                        (DateTimeHelper.from_rfc3339(hash['lastUpdatedDate']) if hash['lastUpdatedDate'])
                      else
                        SKIP
                      end

  # 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.
  Shipment.new(shipment_id: shipment_id,
               shipment_status: shipment_status,
               order_id: order_id,
               seller_order_id: seller_order_id,
               item_list: item_list,
               ship_from_address: ship_from_address,
               ship_to_address: ship_to_address,
               package_dimensions: package_dimensions,
               weight: weight,
               insurance: insurance,
               shipping_service: shipping_service,
               label: label,
               created_date: created_date,
               last_updated_date: last_updated_date,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/walmart_ap_is/models/shipment.rb', line 70

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['shipment_id'] = 'shipmentId'
  @_hash['order_id'] = 'orderId'
  @_hash['seller_order_id'] = 'sellerOrderId'
  @_hash['item_list'] = 'itemList'
  @_hash['ship_from_address'] = 'shipFromAddress'
  @_hash['ship_to_address'] = 'shipToAddress'
  @_hash['package_dimensions'] = 'packageDimensions'
  @_hash['weight'] = 'weight'
  @_hash['insurance'] = 'insurance'
  @_hash['shipping_service'] = 'shippingService'
  @_hash['label'] = 'label'
  @_hash['shipment_status'] = 'shipmentStatus'
  @_hash['created_date'] = 'createdDate'
  @_hash['last_updated_date'] = 'lastUpdatedDate'
  @_hash
end

.nullablesObject

An array for nullable fields



108
109
110
# File 'lib/walmart_ap_is/models/shipment.rb', line 108

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    order_id
    seller_order_id
    item_list
    ship_from_address
    ship_to_address
    package_dimensions
    weight
    insurance
    shipping_service
    label
    created_date
    last_updated_date
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



225
226
227
228
229
230
231
232
233
234
235
# File 'lib/walmart_ap_is/models/shipment.rb', line 225

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} shipment_id: #{@shipment_id.inspect}, order_id: #{@order_id.inspect},"\
  " seller_order_id: #{@seller_order_id.inspect}, item_list: #{@item_list.inspect},"\
  " ship_from_address: #{@ship_from_address.inspect}, ship_to_address:"\
  " #{@ship_to_address.inspect}, package_dimensions: #{@package_dimensions.inspect}, weight:"\
  " #{@weight.inspect}, insurance: #{@insurance.inspect}, shipping_service:"\
  " #{@shipping_service.inspect}, label: #{@label.inspect}, shipment_status:"\
  " #{@shipment_status.inspect}, created_date: #{@created_date.inspect}, last_updated_date:"\
  " #{@last_updated_date.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_created_dateObject



204
205
206
# File 'lib/walmart_ap_is/models/shipment.rb', line 204

def to_custom_created_date
  DateTimeHelper.to_rfc3339(created_date)
end

#to_custom_last_updated_dateObject



208
209
210
# File 'lib/walmart_ap_is/models/shipment.rb', line 208

def to_custom_last_updated_date
  DateTimeHelper.to_rfc3339(last_updated_date)
end

#to_sObject

Provides a human-readable string representation of the object.



213
214
215
216
217
218
219
220
221
222
# File 'lib/walmart_ap_is/models/shipment.rb', line 213

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} shipment_id: #{@shipment_id}, order_id: #{@order_id}, seller_order_id:"\
  " #{@seller_order_id}, item_list: #{@item_list}, ship_from_address: #{@ship_from_address},"\
  " ship_to_address: #{@ship_to_address}, package_dimensions: #{@package_dimensions}, weight:"\
  " #{@weight}, insurance: #{@insurance}, shipping_service: #{@shipping_service}, label:"\
  " #{@label}, shipment_status: #{@shipment_status}, created_date: #{@created_date},"\
  " last_updated_date: #{@last_updated_date}, additional_properties:"\
  " #{@additional_properties}>"
end