Class: UspsApi::InternationalOptionsRequest

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/international_options_request.rb

Overview

International Options Request

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(pricing_options:, origin_zip_code:, destination_country_code:, package_description:, foreign_postal_code: SKIP, shipping_filter: SKIP, request_duties_taxes_fees: false, destination_city: SKIP, destination_state: SKIP, items: SKIP, additional_properties: nil) ⇒ InternationalOptionsRequest

Returns a new instance of InternationalOptionsRequest.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/usps_api/models/international_options_request.rb', line 95

def initialize(pricing_options:, origin_zip_code:,
               destination_country_code:, package_description:,
               foreign_postal_code: SKIP, shipping_filter: SKIP,
               request_duties_taxes_fees: false, destination_city: SKIP,
               destination_state: SKIP, items: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @pricing_options = pricing_options
  @origin_zip_code = origin_zip_code
  @foreign_postal_code = foreign_postal_code unless foreign_postal_code == SKIP
  @destination_country_code = destination_country_code
  @package_description = package_description
  @shipping_filter = shipping_filter unless shipping_filter == SKIP
  unless request_duties_taxes_fees == SKIP
    @request_duties_taxes_fees =
      request_duties_taxes_fees
  end
  @destination_city = destination_city unless destination_city == SKIP
  @destination_state = destination_state unless destination_state == SKIP
  @items = items unless items == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#destination_cityString

When ‘requestDutiesTaxesFees` is `true` then `destinationCity` may be required based on the country of import.

Returns:

  • (String)


50
51
52
# File 'lib/usps_api/models/international_options_request.rb', line 50

def destination_city
  @destination_city
end

#destination_country_codeString

The ISO 3166-1 alpha-2 code representing the shipping destination.

Returns:

  • (String)


31
32
33
# File 'lib/usps_api/models/international_options_request.rb', line 31

def destination_country_code
  @destination_country_code
end

#destination_stateString

When ‘requestDutiesTaxesFees` is `true` then `destinationState` may be required based on the country of import.

Returns:

  • (String)


55
56
57
# File 'lib/usps_api/models/international_options_request.rb', line 55

def destination_state
  @destination_state
end

#foreign_postal_codeString

This is the Postal Code used in an international addresses. Note:

  • Different shipping destinations may require a postal code for shipping.

For more details, review the [Individual Country Listing](pe.usps.com/text/imm/immctry.htm) for your shipping destination

Returns:

  • (String)


27
28
29
# File 'lib/usps_api/models/international_options_request.rb', line 27

def foreign_postal_code
  @foreign_postal_code
end

#itemsArray[ShipmentsDeliveryDutiesTaxesAndFeesItem]

A list of items utilized for pricing when ‘requestDutiesTaxesFees` is `true`.



60
61
62
# File 'lib/usps_api/models/international_options_request.rb', line 60

def items
  @items
end

#origin_zip_codeString

The originating ZIP code for the package.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/international_options_request.rb', line 18

def origin_zip_code
  @origin_zip_code
end

#package_descriptionShipmentsInternationalPackageDescription

Details of package being shipped



35
36
37
# File 'lib/usps_api/models/international_options_request.rb', line 35

def package_description
  @package_description
end

#pricing_optionsArray[InternationalPricingOption]

List of international pricing options

Returns:



14
15
16
# File 'lib/usps_api/models/international_options_request.rb', line 14

def pricing_options
  @pricing_options
end

#request_duties_taxes_feesTrueClass | FalseClass

When ‘true` the returned `rateOption` elements will include the duties and taxes cost for each item and package fees.

Returns:

  • (TrueClass | FalseClass)


45
46
47
# File 'lib/usps_api/models/international_options_request.rb', line 45

def request_duties_taxes_fees
  @request_duties_taxes_fees
end

#shipping_filterShippingFilter1

A filter for international results to return only one response based on lowest price. There are no service standards for international.

Returns:



40
41
42
# File 'lib/usps_api/models/international_options_request.rb', line 40

def shipping_filter
  @shipping_filter
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/usps_api/models/international_options_request.rb', line 121

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
  pricing_options = nil
  unless hash['pricingOptions'].nil?
    pricing_options = []
    hash['pricingOptions'].each do |structure|
      pricing_options << (InternationalPricingOption.from_hash(structure) if structure)
    end
  end

  pricing_options = nil unless hash.key?('pricingOptions')
  origin_zip_code = hash.key?('originZIPCode') ? hash['originZIPCode'] : nil
  destination_country_code =
    hash.key?('destinationCountryCode') ? hash['destinationCountryCode'] : nil
  if hash['packageDescription']
    package_description = ShipmentsInternationalPackageDescription.from_hash(hash['packageDescription'])
  end
  foreign_postal_code =
    hash.key?('foreignPostalCode') ? hash['foreignPostalCode'] : SKIP
  shipping_filter =
    hash.key?('shippingFilter') ? hash['shippingFilter'] : SKIP
  request_duties_taxes_fees = hash['requestDutiesTaxesFees'] ||= false
  destination_city =
    hash.key?('destinationCity') ? hash['destinationCity'] : SKIP
  destination_state =
    hash.key?('destinationState') ? hash['destinationState'] : SKIP
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (ShipmentsDeliveryDutiesTaxesAndFeesItem.from_hash(structure) if structure)
    end
  end

  items = SKIP unless hash.key?('items')

  # 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.
  InternationalOptionsRequest.new(pricing_options: pricing_options,
                                  origin_zip_code: origin_zip_code,
                                  destination_country_code: destination_country_code,
                                  package_description: package_description,
                                  foreign_postal_code: foreign_postal_code,
                                  shipping_filter: shipping_filter,
                                  request_duties_taxes_fees: request_duties_taxes_fees,
                                  destination_city: destination_city,
                                  destination_state: destination_state,
                                  items: items,
                                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/usps_api/models/international_options_request.rb', line 63

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['pricing_options'] = 'pricingOptions'
  @_hash['origin_zip_code'] = 'originZIPCode'
  @_hash['foreign_postal_code'] = 'foreignPostalCode'
  @_hash['destination_country_code'] = 'destinationCountryCode'
  @_hash['package_description'] = 'packageDescription'
  @_hash['shipping_filter'] = 'shippingFilter'
  @_hash['request_duties_taxes_fees'] = 'requestDutiesTaxesFees'
  @_hash['destination_city'] = 'destinationCity'
  @_hash['destination_state'] = 'destinationState'
  @_hash['items'] = 'items'
  @_hash
end

.nullablesObject

An array for nullable fields



91
92
93
# File 'lib/usps_api/models/international_options_request.rb', line 91

def self.nullables
  []
end

.optionalsObject

An array for optional fields



79
80
81
82
83
84
85
86
87
88
# File 'lib/usps_api/models/international_options_request.rb', line 79

def self.optionals
  %w[
    foreign_postal_code
    shipping_filter
    request_duties_taxes_fees
    destination_city
    destination_state
    items
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/usps_api/models/international_options_request.rb', line 184

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.pricing_options,
                            ->(val) { InternationalPricingOption.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
        APIHelper.valid_type?(value.origin_zip_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.destination_country_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.package_description,
                              ->(val) { ShipmentsInternationalPackageDescription.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['pricingOptions'],
                          ->(val) { InternationalPricingOption.validate(val) },
                          is_model_hash: true,
                          is_inner_model_hash: true) and
      APIHelper.valid_type?(value['originZIPCode'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['destinationCountryCode'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['packageDescription'],
                            ->(val) { ShipmentsInternationalPackageDescription.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



231
232
233
234
235
236
237
238
239
240
# File 'lib/usps_api/models/international_options_request.rb', line 231

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} pricing_options: #{@pricing_options.inspect}, origin_zip_code:"\
  " #{@origin_zip_code.inspect}, foreign_postal_code: #{@foreign_postal_code.inspect},"\
  " destination_country_code: #{@destination_country_code.inspect}, package_description:"\
  " #{@package_description.inspect}, shipping_filter: #{@shipping_filter.inspect},"\
  " request_duties_taxes_fees: #{@request_duties_taxes_fees.inspect}, destination_city:"\
  " #{@destination_city.inspect}, destination_state: #{@destination_state.inspect}, items:"\
  " #{@items.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



219
220
221
222
223
224
225
226
227
228
# File 'lib/usps_api/models/international_options_request.rb', line 219

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} pricing_options: #{@pricing_options}, origin_zip_code: #{@origin_zip_code},"\
  " foreign_postal_code: #{@foreign_postal_code}, destination_country_code:"\
  " #{@destination_country_code}, package_description: #{@package_description},"\
  " shipping_filter: #{@shipping_filter}, request_duties_taxes_fees:"\
  " #{@request_duties_taxes_fees}, destination_city: #{@destination_city}, destination_state:"\
  " #{@destination_state}, items: #{@items}, additional_properties:"\
  " #{@additional_properties}>"
end