Class: UspsApi::LabelsCustomsFormPackageContents

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

Overview

Required repeating up to 30 times if generating an Integrated Customs Form, otherwise not required.

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(item_description: SKIP, item_quantity: SKIP, item_value: SKIP, item_total_value: SKIP, weight_uom: WeightUom::LB, item_weight: SKIP, item_total_weight: SKIP, hs_tariff_number: SKIP, countryof_origin: SKIP, item_category: SKIP, item_subcategory: SKIP, additional_properties: nil) ⇒ LabelsCustomsFormPackageContents

Returns a new instance of LabelsCustomsFormPackageContents.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 116

def initialize(item_description: SKIP, item_quantity: SKIP,
               item_value: SKIP, item_total_value: SKIP,
               weight_uom: WeightUom::LB, item_weight: SKIP,
               item_total_weight: SKIP, hs_tariff_number: SKIP,
               countryof_origin: SKIP, item_category: SKIP,
               item_subcategory: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @item_description = item_description unless item_description == SKIP
  @item_quantity = item_quantity unless item_quantity == SKIP
  @item_value = item_value unless item_value == SKIP
  @item_total_value = item_total_value unless item_total_value == SKIP
  @weight_uom = weight_uom unless weight_uom == SKIP
  @item_weight = item_weight unless item_weight == SKIP
  @item_total_weight = item_total_weight unless item_total_weight == SKIP
  @hs_tariff_number = hs_tariff_number unless hs_tariff_number == SKIP
  @countryof_origin = countryof_origin unless countryof_origin == SKIP
  @item_category = item_category unless item_category == SKIP
  @item_subcategory = item_subcategory unless item_subcategory == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#countryof_originString

2 digit Alpha Country Code defined by ISO is required for international address.

Returns:

  • (String)


67
68
69
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 67

def countryof_origin
  @countryof_origin
end

#hs_tariff_numberString

For commercial items only. The HS tariff number is based on the Harmonized Commodity Description and Coding System developed by the World Customs Organization. Providing this value is strongly recommended for faster processing. If not supplied, USPS will attempt to look up the HS tariff number, which may result in longer response times. The value should follow the pattern: ‘^.*(?:[A-Za-zd].*)6,14$`. For more information, see: [hts.usitc.gov/current](https://hts.usitc.gov/current).

Returns:

  • (String)


62
63
64
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 62

def hs_tariff_number
  @hs_tariff_number
end

#item_categoryString

Category of the item being shipped.

Returns:

  • (String)


71
72
73
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 71

def item_category
  @item_category
end

#item_descriptionString

Description of the item. It is important to note that the following descriptions, regardless of case sensitivity, are not considered valid: None, Not Applicable, N/A, Null, Gift, and Merchandise.

Returns:

  • (String)


17
18
19
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 17

def item_description
  @item_description
end

#item_quantityInteger

Quantity of the item. Integer value required.

Returns:

  • (Integer)


21
22
23
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 21

def item_quantity
  @item_quantity
end

#item_subcategoryString

Subcategory of the item being shipped.

Returns:

  • (String)


75
76
77
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 75

def item_subcategory
  @item_subcategory
end

#item_total_valueFloat

The total item value, in USD, of the items matching the ‘itemDescription`.

Returns:

  • (Float)


32
33
34
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 32

def item_total_value
  @item_total_value
end

#item_total_weightFloat

Provide the total weight in ‘weightUOM` for the all items matching the `itemDescription`.

Returns:

  • (Float)


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

def item_total_weight
  @item_total_weight
end

#item_valueFloat

Value of the individual item in USD. Note:

  • This field has been deprecated in favor of ‘itemTotalValue` and will be

removed in a future release. Please transition to using ‘itemTotalValue`.

Returns:

  • (Float)


28
29
30
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 28

def item_value
  @item_value
end

#item_weightFloat

Provide the weight in ‘weightUOM` for the individual item listed with `itemDescription`. Note:

  • This field has been deprecated in favor of ‘itemTotalWeight` and will be

removed in a future release. Please transition to using ‘itemTotalWeight`.

Returns:

  • (Float)


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

def item_weight
  @item_weight
end

#weight_uomWeightUom

Weight Unit of Measurement

* lb - Pounds

Returns:



37
38
39
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 37

def weight_uom
  @weight_uom
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 140

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_description =
    hash.key?('itemDescription') ? hash['itemDescription'] : SKIP
  item_quantity = hash.key?('itemQuantity') ? hash['itemQuantity'] : SKIP
  item_value = hash.key?('itemValue') ? hash['itemValue'] : SKIP
  item_total_value =
    hash.key?('itemTotalValue') ? hash['itemTotalValue'] : SKIP
  weight_uom = hash['weightUOM'] ||= WeightUom::LB
  item_weight = hash.key?('itemWeight') ? hash['itemWeight'] : SKIP
  item_total_weight =
    hash.key?('itemTotalWeight') ? hash['itemTotalWeight'] : SKIP
  hs_tariff_number =
    hash.key?('HSTariffNumber') ? hash['HSTariffNumber'] : SKIP
  countryof_origin =
    hash.key?('countryofOrigin') ? hash['countryofOrigin'] : SKIP
  item_category = hash.key?('itemCategory') ? hash['itemCategory'] : SKIP
  item_subcategory =
    hash.key?('itemSubcategory') ? hash['itemSubcategory'] : SKIP

  # 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.
  LabelsCustomsFormPackageContents.new(item_description: item_description,
                                       item_quantity: item_quantity,
                                       item_value: item_value,
                                       item_total_value: item_total_value,
                                       weight_uom: weight_uom,
                                       item_weight: item_weight,
                                       item_total_weight: item_total_weight,
                                       hs_tariff_number: hs_tariff_number,
                                       countryof_origin: countryof_origin,
                                       item_category: item_category,
                                       item_subcategory: item_subcategory,
                                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 78

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['item_description'] = 'itemDescription'
  @_hash['item_quantity'] = 'itemQuantity'
  @_hash['item_value'] = 'itemValue'
  @_hash['item_total_value'] = 'itemTotalValue'
  @_hash['weight_uom'] = 'weightUOM'
  @_hash['item_weight'] = 'itemWeight'
  @_hash['item_total_weight'] = 'itemTotalWeight'
  @_hash['hs_tariff_number'] = 'HSTariffNumber'
  @_hash['countryof_origin'] = 'countryofOrigin'
  @_hash['item_category'] = 'itemCategory'
  @_hash['item_subcategory'] = 'itemSubcategory'
  @_hash
end

.nullablesObject

An array for nullable fields



112
113
114
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 112

def self.nullables
  []
end

.optionalsObject

An array for optional fields



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 95

def self.optionals
  %w[
    item_description
    item_quantity
    item_value
    item_total_value
    weight_uom
    item_weight
    item_total_weight
    hs_tariff_number
    countryof_origin
    item_category
    item_subcategory
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



186
187
188
189
190
191
192
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 186

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



206
207
208
209
210
211
212
213
214
215
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 206

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} item_description: #{@item_description.inspect}, item_quantity:"\
  " #{@item_quantity.inspect}, item_value: #{@item_value.inspect}, item_total_value:"\
  " #{@item_total_value.inspect}, weight_uom: #{@weight_uom.inspect}, item_weight:"\
  " #{@item_weight.inspect}, item_total_weight: #{@item_total_weight.inspect},"\
  " hs_tariff_number: #{@hs_tariff_number.inspect}, countryof_origin:"\
  " #{@countryof_origin.inspect}, item_category: #{@item_category.inspect}, item_subcategory:"\
  " #{@item_subcategory.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



195
196
197
198
199
200
201
202
203
# File 'lib/usps_api/models/labels_customs_form_package_contents.rb', line 195

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} item_description: #{@item_description}, item_quantity: #{@item_quantity},"\
  " item_value: #{@item_value}, item_total_value: #{@item_total_value}, weight_uom:"\
  " #{@weight_uom}, item_weight: #{@item_weight}, item_total_weight: #{@item_total_weight},"\
  " hs_tariff_number: #{@hs_tariff_number}, countryof_origin: #{@countryof_origin},"\
  " item_category: #{@item_category}, item_subcategory: #{@item_subcategory},"\
  " additional_properties: #{@additional_properties}>"
end