Class: UspsApi::InternationalPricesDeliveryDutiesTaxesAndFeesItem

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

Overview

When ‘requestDutiesTaxesFees` is true at least one item is 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_id:, item_value:, item_quantity:, weight: SKIP, country_of_origin: SKIP, hs_tariff_number: SKIP, additional_properties: nil) ⇒ InternationalPricesDeliveryDutiesTaxesAndFeesItem

Returns a new instance of InternationalPricesDeliveryDutiesTaxesAndFeesItem.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 69

def initialize(item_id:, item_value:, item_quantity:, weight: SKIP,
               country_of_origin: SKIP, hs_tariff_number: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @item_id = item_id
  @item_value = item_value
  @item_quantity = item_quantity
  @weight = weight unless weight == SKIP
  @country_of_origin = country_of_origin unless country_of_origin == SKIP
  @hs_tariff_number = hs_tariff_number unless hs_tariff_number == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#country_of_originString

A two digit Alpha Country Code defined by ISO representing where the item is from.

Returns:

  • (String)


33
34
35
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 33

def country_of_origin
  @country_of_origin
end

#hs_tariff_numberString

The HS tariff number is based on the Harmonized Commodity Description and Coding System developed by the World Customs Organization. The value should follow the regular expression pattern: ‘^.*(?:[A-Za-zd].*)6,14$`. For more information, see: [hts.usitc.gov/current](https://hts.usitc.gov/current).

Returns:

  • (String)


41
42
43
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 41

def hs_tariff_number
  @hs_tariff_number
end

#item_idString

A user-provided item identifier. The itemId is echoed in the response to correlate duties and taxes to this item.

Returns:

  • (String)


15
16
17
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 15

def item_id
  @item_id
end

#item_quantityFloat

The quantity of the item.

Returns:

  • (Float)


23
24
25
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 23

def item_quantity
  @item_quantity
end

#item_valueFloat

The value of the item.

Returns:

  • (Float)


19
20
21
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 19

def item_value
  @item_value
end

#weightFloat

The calculated weight for each individual item within a quantity based on user input.

Returns:

  • (Float)


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

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 85

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_id = hash.key?('itemId') ? hash['itemId'] : nil
  item_value = hash.key?('itemValue') ? hash['itemValue'] : nil
  item_quantity = hash.key?('itemQuantity') ? hash['itemQuantity'] : nil
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  country_of_origin =
    hash.key?('countryOfOrigin') ? hash['countryOfOrigin'] : SKIP
  hs_tariff_number =
    hash.key?('HSTariffNumber') ? hash['HSTariffNumber'] : 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.
  InternationalPricesDeliveryDutiesTaxesAndFeesItem.new(item_id: item_id,
                                                        item_value: item_value,
                                                        item_quantity: item_quantity,
                                                        weight: weight,
                                                        country_of_origin: country_of_origin,
                                                        hs_tariff_number: hs_tariff_number,
                                                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



44
45
46
47
48
49
50
51
52
53
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 44

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['item_id'] = 'itemId'
  @_hash['item_value'] = 'itemValue'
  @_hash['item_quantity'] = 'itemQuantity'
  @_hash['weight'] = 'weight'
  @_hash['country_of_origin'] = 'countryOfOrigin'
  @_hash['hs_tariff_number'] = 'HSTariffNumber'
  @_hash
end

.nullablesObject

An array for nullable fields



65
66
67
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 65

def self.nullables
  []
end

.optionalsObject

An array for optional fields



56
57
58
59
60
61
62
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 56

def self.optionals
  %w[
    weight
    country_of_origin
    hs_tariff_number
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



124
125
126
127
128
129
130
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 124

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} item_id: #{@item_id.inspect}, item_value: #{@item_value.inspect},"\
  " item_quantity: #{@item_quantity.inspect}, weight: #{@weight.inspect}, country_of_origin:"\
  " #{@country_of_origin.inspect}, hs_tariff_number: #{@hs_tariff_number.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



116
117
118
119
120
121
# File 'lib/usps_api/models/international_prices_delivery_duties_taxes_and_fees_item.rb', line 116

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} item_id: #{@item_id}, item_value: #{@item_value}, item_quantity:"\
  " #{@item_quantity}, weight: #{@weight}, country_of_origin: #{@country_of_origin},"\
  " hs_tariff_number: #{@hs_tariff_number}, additional_properties: #{@additional_properties}>"
end