Class: UspsApi::InternationalAddress

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

Overview

Address fields for International locations.

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(street_address: SKIP, street_address_abbreviation: SKIP, secondary_address: SKIP, city_abbreviation: SKIP, city: SKIP, postal_code: SKIP, province: SKIP, province_iso_alpha2_code: SKIP, country: SKIP, country_iso_alpha2_code: SKIP, additional_properties: nil) ⇒ InternationalAddress

Returns a new instance of InternationalAddress.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/usps_api/models/international_address.rb', line 110

def initialize(street_address: SKIP, street_address_abbreviation: SKIP,
               secondary_address: SKIP, city_abbreviation: SKIP, city: SKIP,
               postal_code: SKIP, province: SKIP,
               province_iso_alpha2_code: SKIP, country: SKIP,
               country_iso_alpha2_code: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @street_address = street_address unless street_address == SKIP
  unless street_address_abbreviation == SKIP
    @street_address_abbreviation =
      street_address_abbreviation
  end
  @secondary_address = secondary_address unless secondary_address == SKIP
  @city_abbreviation = city_abbreviation unless city_abbreviation == SKIP
  @city = city unless city == SKIP
  @postal_code = postal_code unless postal_code == SKIP
  @province = province unless province == SKIP
  @province_iso_alpha2_code = province_iso_alpha2_code unless province_iso_alpha2_code == SKIP
  @country = country unless country == SKIP
  @country_iso_alpha2_code = country_iso_alpha2_code unless country_iso_alpha2_code == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#cityString

This is the city name of the address.

Returns:

  • (String)


34
35
36
# File 'lib/usps_api/models/international_address.rb', line 34

def city
  @city
end

#city_abbreviationString

This is the abbreviation of city name for the address.

Returns:

  • (String)


30
31
32
# File 'lib/usps_api/models/international_address.rb', line 30

def city_abbreviation
  @city_abbreviation
end

#countryString

This is the country name used in an international address.

Returns:

  • (String)


57
58
59
# File 'lib/usps_api/models/international_address.rb', line 57

def country
  @country
end

#country_iso_alpha2_codeString

ISO 3166-1 alpha-2 codes are two-letter country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO), to represent countries, dependent territories, and special areas of geographical interest. They are the most widely used of the country codes published by ISO (the others being alpha-3 and numeric), and are used most prominently for the Internet’s country code top-level domains (with a few exceptions). They are also used as country identifiers extending the postal code when appropriate within the international postal system for paper mail, and have replaced the previous one consisting of one-letter codes. They were first included as part of the ISO 3166 standard in its first edition in 1974.

Returns:

  • (String)


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

def country_iso_alpha2_code
  @country_iso_alpha2_code
end

#postal_codeString

This is the Postal Code used for international addresses. Note:

  • When shipping to Canada, this field must start with a letter (A-Z)

  • 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)


44
45
46
# File 'lib/usps_api/models/international_address.rb', line 44

def postal_code
  @postal_code
end

#provinceString

This is the province used for international addresses.

Returns:

  • (String)


48
49
50
# File 'lib/usps_api/models/international_address.rb', line 48

def province
  @province
end

#province_iso_alpha2_codeString

The 2 letter abbreviation representing the destination province. Required for select destination countries when ‘prepayDutiesTaxesFees` is `true`.

Returns:

  • (String)


53
54
55
# File 'lib/usps_api/models/international_address.rb', line 53

def province_iso_alpha2_code
  @province_iso_alpha2_code
end

#secondary_addressString

The secondary unit designator, such as apartment(APT) or suite(STE) number, defining the exact location of the address within a building. For more information please see [Postal Explorer](pe.usps.com/text/pub28/28c2_003.htm).

Returns:

  • (String)


26
27
28
# File 'lib/usps_api/models/international_address.rb', line 26

def secondary_address
  @secondary_address
end

#street_addressString

The number of a building along with the name of the road or street on which it is located.

Returns:

  • (String)


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

def street_address
  @street_address
end

#street_address_abbreviationString

This is the abbreviation of street address line for the address.

Returns:

  • (String)


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

def street_address_abbreviation
  @street_address_abbreviation
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  street_address = hash.key?('streetAddress') ? hash['streetAddress'] : SKIP
  street_address_abbreviation =
    hash.key?('streetAddressAbbreviation') ? hash['streetAddressAbbreviation'] : SKIP
  secondary_address =
    hash.key?('secondaryAddress') ? hash['secondaryAddress'] : SKIP
  city_abbreviation =
    hash.key?('cityAbbreviation') ? hash['cityAbbreviation'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  postal_code = hash.key?('postalCode') ? hash['postalCode'] : SKIP
  province = hash.key?('province') ? hash['province'] : SKIP
  province_iso_alpha2_code =
    hash.key?('provinceISOAlpha2Code') ? hash['provinceISOAlpha2Code'] : SKIP
  country = hash.key?('country') ? hash['country'] : SKIP
  country_iso_alpha2_code =
    hash.key?('countryISOAlpha2Code') ? hash['countryISOAlpha2Code'] : 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.
  InternationalAddress.new(street_address: street_address,
                           street_address_abbreviation: street_address_abbreviation,
                           secondary_address: secondary_address,
                           city_abbreviation: city_abbreviation,
                           city: city,
                           postal_code: postal_code,
                           province: province,
                           province_iso_alpha2_code: province_iso_alpha2_code,
                           country: country,
                           country_iso_alpha2_code: country_iso_alpha2_code,
                           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/usps_api/models/international_address.rb', line 74

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['street_address'] = 'streetAddress'
  @_hash['street_address_abbreviation'] = 'streetAddressAbbreviation'
  @_hash['secondary_address'] = 'secondaryAddress'
  @_hash['city_abbreviation'] = 'cityAbbreviation'
  @_hash['city'] = 'city'
  @_hash['postal_code'] = 'postalCode'
  @_hash['province'] = 'province'
  @_hash['province_iso_alpha2_code'] = 'provinceISOAlpha2Code'
  @_hash['country'] = 'country'
  @_hash['country_iso_alpha2_code'] = 'countryISOAlpha2Code'
  @_hash
end

.nullablesObject

An array for nullable fields



106
107
108
# File 'lib/usps_api/models/international_address.rb', line 106

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    street_address
    street_address_abbreviation
    secondary_address
    city_abbreviation
    city
    postal_code
    province
    province_iso_alpha2_code
    country
    country_iso_alpha2_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



188
189
190
191
192
193
194
195
196
197
# File 'lib/usps_api/models/international_address.rb', line 188

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address.inspect}, street_address_abbreviation:"\
  " #{@street_address_abbreviation.inspect}, secondary_address: #{@secondary_address.inspect},"\
  " city_abbreviation: #{@city_abbreviation.inspect}, city: #{@city.inspect}, postal_code:"\
  " #{@postal_code.inspect}, province: #{@province.inspect}, province_iso_alpha2_code:"\
  " #{@province_iso_alpha2_code.inspect}, country: #{@country.inspect},"\
  " country_iso_alpha2_code: #{@country_iso_alpha2_code.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



177
178
179
180
181
182
183
184
185
# File 'lib/usps_api/models/international_address.rb', line 177

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address}, street_address_abbreviation:"\
  " #{@street_address_abbreviation}, secondary_address: #{@secondary_address},"\
  " city_abbreviation: #{@city_abbreviation}, city: #{@city}, postal_code: #{@postal_code},"\
  " province: #{@province}, province_iso_alpha2_code: #{@province_iso_alpha2_code}, country:"\
  " #{@country}, country_iso_alpha2_code: #{@country_iso_alpha2_code}, additional_properties:"\
  " #{@additional_properties}>"
end