Class: WalmartApIs::PackingOption

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

Overview

A packing option contains a set of pack groups plus additional information such as any discounts or fees.

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(discounts:, fees:, packing_groups:, packing_option_id:, status:, supported_configurations:, supported_shipping_configurations:, expiration: SKIP, additional_properties: nil) ⇒ PackingOption

Returns a new instance of PackingOption.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/walmart_ap_is/models/packing_option.rb', line 75

def initialize(discounts:, fees:, packing_groups:, packing_option_id:,
               status:, supported_configurations:,
               supported_shipping_configurations:, expiration: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @discounts = discounts
  @expiration = expiration unless expiration == SKIP
  @fees = fees
  @packing_groups = packing_groups
  @packing_option_id = packing_option_id
  @status = status
  @supported_configurations = supported_configurations
  @supported_shipping_configurations = supported_shipping_configurations
  @additional_properties = additional_properties
end

Instance Attribute Details

#discountsArray[Incentive]

Discount for the offered option.

Returns:



16
17
18
# File 'lib/walmart_ap_is/models/packing_option.rb', line 16

def discounts
  @discounts
end

#expirationDateTime

The time at which this packing option is no longer valid. In ISO 8601 datetime format with pattern yyyy-MM-ddTHH:mm:ss.sssZ.

Returns:

  • (DateTime)


21
22
23
# File 'lib/walmart_ap_is/models/packing_option.rb', line 21

def expiration
  @expiration
end

#feesArray[Incentive]

Fee for the offered option.

Returns:



25
26
27
# File 'lib/walmart_ap_is/models/packing_option.rb', line 25

def fees
  @fees
end

#packing_groupsArray[String]

Packing group IDs.

Returns:

  • (Array[String])


29
30
31
# File 'lib/walmart_ap_is/models/packing_option.rb', line 29

def packing_groups
  @packing_groups
end

#packing_option_idString

Identifier of a packing option.

Returns:

  • (String)


33
34
35
# File 'lib/walmart_ap_is/models/packing_option.rb', line 33

def packing_option_id
  @packing_option_id
end

#statusString

The status of the packing option. Possible values: OFFERED, ACCEPTED, EXPIRED.

Returns:

  • (String)


38
39
40
# File 'lib/walmart_ap_is/models/packing_option.rb', line 38

def status
  @status
end

#supported_configurationsArray[PackingConfiguration]

A list of possible configurations for this option.

Returns:



42
43
44
# File 'lib/walmart_ap_is/models/packing_option.rb', line 42

def supported_configurations
  @supported_configurations
end

#supported_shipping_configurationsArray[ShippingConfiguration]

List of supported shipping modes.

Returns:



46
47
48
# File 'lib/walmart_ap_is/models/packing_option.rb', line 46

def supported_shipping_configurations
  @supported_shipping_configurations
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
161
162
163
164
165
# File 'lib/walmart_ap_is/models/packing_option.rb', line 94

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  discounts = nil
  unless hash['discounts'].nil?
    discounts = []
    hash['discounts'].each do |structure|
      discounts << (Incentive.from_hash(structure) if structure)
    end
  end

  discounts = nil unless hash.key?('discounts')
  # Parameter is an array, so we need to iterate through it
  fees = nil
  unless hash['fees'].nil?
    fees = []
    hash['fees'].each do |structure|
      fees << (Incentive.from_hash(structure) if structure)
    end
  end

  fees = nil unless hash.key?('fees')
  packing_groups = hash.key?('packingGroups') ? hash['packingGroups'] : nil
  packing_option_id =
    hash.key?('packingOptionId') ? hash['packingOptionId'] : nil
  status = hash.key?('status') ? hash['status'] : nil
  # Parameter is an array, so we need to iterate through it
  supported_configurations = nil
  unless hash['supportedConfigurations'].nil?
    supported_configurations = []
    hash['supportedConfigurations'].each do |structure|
      supported_configurations << (PackingConfiguration.from_hash(structure) if structure)
    end
  end

  supported_configurations = nil unless hash.key?('supportedConfigurations')
  # Parameter is an array, so we need to iterate through it
  supported_shipping_configurations = nil
  unless hash['supportedShippingConfigurations'].nil?
    supported_shipping_configurations = []
    hash['supportedShippingConfigurations'].each do |structure|
      supported_shipping_configurations << (ShippingConfiguration.from_hash(structure) if structure)
    end
  end

  supported_shipping_configurations = nil unless hash.key?('supportedShippingConfigurations')
  expiration = if hash.key?('expiration')
                 (DateTimeHelper.from_rfc3339(hash['expiration']) if hash['expiration'])
               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.
  PackingOption.new(discounts: discounts,
                    fees: fees,
                    packing_groups: packing_groups,
                    packing_option_id: packing_option_id,
                    status: status,
                    supported_configurations: supported_configurations,
                    supported_shipping_configurations: supported_shipping_configurations,
                    expiration: expiration,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/walmart_ap_is/models/packing_option.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discounts'] = 'discounts'
  @_hash['expiration'] = 'expiration'
  @_hash['fees'] = 'fees'
  @_hash['packing_groups'] = 'packingGroups'
  @_hash['packing_option_id'] = 'packingOptionId'
  @_hash['status'] = 'status'
  @_hash['supported_configurations'] = 'supportedConfigurations'
  @_hash['supported_shipping_configurations'] =
    'supportedShippingConfigurations'
  @_hash
end

.nullablesObject

An array for nullable fields



71
72
73
# File 'lib/walmart_ap_is/models/packing_option.rb', line 71

def self.nullables
  []
end

.optionalsObject

An array for optional fields



64
65
66
67
68
# File 'lib/walmart_ap_is/models/packing_option.rb', line 64

def self.optionals
  %w[
    expiration
  ]
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/packing_option.rb', line 182

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discounts: #{@discounts.inspect}, expiration: #{@expiration.inspect}, fees:"\
  " #{@fees.inspect}, packing_groups: #{@packing_groups.inspect}, packing_option_id:"\
  " #{@packing_option_id.inspect}, status: #{@status.inspect}, supported_configurations:"\
  " #{@supported_configurations.inspect}, supported_shipping_configurations:"\
  " #{@supported_shipping_configurations.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_expirationObject



167
168
169
# File 'lib/walmart_ap_is/models/packing_option.rb', line 167

def to_custom_expiration
  DateTimeHelper.to_rfc3339(expiration)
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discounts: #{@discounts}, expiration: #{@expiration}, fees: #{@fees},"\
  " packing_groups: #{@packing_groups}, packing_option_id: #{@packing_option_id}, status:"\
  " #{@status}, supported_configurations: #{@supported_configurations},"\
  " supported_shipping_configurations: #{@supported_shipping_configurations},"\
  " additional_properties: #{@additional_properties}>"
end