Class: UspsApi::DomesticLabelToAddress

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

Overview

The address where the package is being shipped to. The ZIP Code™ in the ‘toAddress` object is used to calculate pricing. Notes: * The First and Last Name or Firm are always required. * Address elements `streetAddress`, `city`, `state`, `ZIPCode` are required unless a parcel locker is requested in which case the `facilityId`, Recipient Email, First and Last Name or Firm are required. * If the `holdForPickup` field is set to `true` then the `toAddress` object `facilityID`, `email`, and `phone` fields as well as the `fromAddress` object `firstName`, `lastName`, `email`, and `phone` fields are 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(street_address: SKIP, street_address_abbreviation: SKIP, secondary_address: SKIP, city_abbreviation: SKIP, city: SKIP, state: SKIP, zip_code: SKIP, zip_plus4: SKIP, urbanization: SKIP, first_name: SKIP, last_name: SKIP, firm: SKIP, phone: SKIP, email: SKIP, ignore_bad_address: SKIP, parcel_locker_delivery: false, hold_for_pickup: false, facility_id: SKIP, additional_properties: nil) ⇒ DomesticLabelToAddress

Returns a new instance of DomesticLabelToAddress.



175
176
177
178
179
180
181
182
183
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
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 175

def initialize(street_address: SKIP, street_address_abbreviation: SKIP,
               secondary_address: SKIP, city_abbreviation: SKIP, city: SKIP,
               state: SKIP, zip_code: SKIP, zip_plus4: SKIP,
               urbanization: SKIP, first_name: SKIP, last_name: SKIP,
               firm: SKIP, phone: SKIP, email: SKIP,
               ignore_bad_address: SKIP, parcel_locker_delivery: false,
               hold_for_pickup: false, facility_id: 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
  @state = state unless state == SKIP
  @zip_code = zip_code unless zip_code == SKIP
  @zip_plus4 = zip_plus4 unless zip_plus4 == SKIP
  @urbanization = urbanization unless urbanization == SKIP
  @first_name = first_name unless first_name == SKIP
  @last_name = last_name unless last_name == SKIP
  @firm = firm unless firm == SKIP
  @phone = phone unless phone == SKIP
  @email = email unless email == SKIP
  @ignore_bad_address = ignore_bad_address unless ignore_bad_address == SKIP
  @parcel_locker_delivery = parcel_locker_delivery unless parcel_locker_delivery == SKIP
  @hold_for_pickup = hold_for_pickup unless hold_for_pickup == SKIP
  @facility_id = facility_id unless facility_id == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#cityString

This is the city name of the address.

Returns:

  • (String)


42
43
44
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 42

def city
  @city
end

#city_abbreviationString

This is the abbreviation of city name for the address.

Returns:

  • (String)


38
39
40
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 38

def city_abbreviation
  @city_abbreviation
end

#emailString

Email address used for redirect notification via email.

Returns:

  • (String)


82
83
84
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 82

def email
  @email
end

#facility_idString

Facility ID is required when generating a label for parcel locker delivery or Hold for Pickup. The Facility ID is obtained from the API response in the /post-office-locator API.

Returns:

  • (String)


118
119
120
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 118

def facility_id
  @facility_id
end

#firmString

Firm/business name corresponding to the address.

Returns:

  • (String)


73
74
75
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 73

def firm
  @firm
end

#first_nameString

First Name corresponding to the address.

Returns:

  • (String)


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

def first_name
  @first_name
end

#hold_for_pickupTrueClass | FalseClass

Indicator to request Hold for Pickup at a Post Office Facility. If this field is set as true then the ‘toAddress` object: ’facilityID’, ‘email’, and ‘phone’ as well as the ‘fromAddress` object: ’firstName’, ‘lastName’, ‘email’, and ‘phone’ fields are required.

Returns:

  • (TrueClass | FalseClass)


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

def hold_for_pickup
  @hold_for_pickup
end

#ignore_bad_addressTrueClass | FalseClass

Allows Non-Validated Destination Street Address. Enter ‘true` to bypass street address validation failures/errors or `false` if only validated addresses should be allowed. Note: Integrators are recommended to always use `false` to ensure no delivery issues. In the event USPS cannot validate the street address, this tag will “bypass” address validation error when `true` is indicated to allow label creation which could impact delivery. This will automatically be set to `false` if extra service code `415 - USPS Label Delivery` is requested.

Returns:

  • (TrueClass | FalseClass)


95
96
97
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 95

def ignore_bad_address
  @ignore_bad_address
end

#last_nameString

Last Name corresponding to the address.

Returns:

  • (String)


69
70
71
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 69

def last_name
  @last_name
end

#parcel_locker_deliveryTrueClass | FalseClass

Indicator to request delivery to a parcel locker instead of the recipient’s address. If this field is set as true then the facilityId, email, and firstName/lastName or firm fields are required. Note:

  • Packages that require customs forms are not eligible to be shipped to a

Smart Locker. Parcel lockers are not eligible for Hold for Pickup shipments.

Returns:

  • (TrueClass | FalseClass)


105
106
107
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 105

def parcel_locker_delivery
  @parcel_locker_delivery
end

#phoneString

The phone number, including the country extension and area code or the local national format, with no punctuation.

Returns:

  • (String)


78
79
80
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 78

def phone
  @phone
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)


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

def secondary_address
  @secondary_address
end

#stateString

This is the two-character state code of the address.

Returns:

  • (String)


46
47
48
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 46

def state
  @state
end

#street_addressString

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

Returns:

  • (String)


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

def street_address
  @street_address
end

#street_address_abbreviationString

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

Returns:

  • (String)


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

def street_address_abbreviation
  @street_address_abbreviation
end

#urbanizationString

An area, sector, or residential development within a geographic area (typically used for addresses in Puerto Rico).

Returns:

  • (String)


61
62
63
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 61

def urbanization
  @urbanization
end

#zip_codeString

This is the 5-digit ZIP code.

Returns:

  • (String)


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

def zip_code
  @zip_code
end

#zip_plus4String

This is the 4-digit component of the ZIP+4 code. Using the correct Zip+4 reduces the number of times your mail is handled and can decrease the chance of a misdelivery or error.

Returns:

  • (String)


56
57
58
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 56

def zip_plus4
  @zip_plus4
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 211

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
  state = hash.key?('state') ? hash['state'] : SKIP
  zip_code = hash.key?('ZIPCode') ? hash['ZIPCode'] : SKIP
  zip_plus4 = hash.key?('ZIPPlus4') ? hash['ZIPPlus4'] : SKIP
  urbanization = hash.key?('urbanization') ? hash['urbanization'] : SKIP
  first_name = hash.key?('firstName') ? hash['firstName'] : SKIP
  last_name = hash.key?('lastName') ? hash['lastName'] : SKIP
  firm = hash.key?('firm') ? hash['firm'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  email = hash.key?('email') ? hash['email'] : SKIP
  ignore_bad_address =
    hash.key?('ignoreBadAddress') ? hash['ignoreBadAddress'] : SKIP
  parcel_locker_delivery = hash['parcelLockerDelivery'] ||= false
  hold_for_pickup = hash['holdForPickup'] ||= false
  facility_id = hash.key?('facilityId') ? hash['facilityId'] : 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.
  DomesticLabelToAddress.new(street_address: street_address,
                             street_address_abbreviation: street_address_abbreviation,
                             secondary_address: secondary_address,
                             city_abbreviation: city_abbreviation,
                             city: city,
                             state: state,
                             zip_code: zip_code,
                             zip_plus4: zip_plus4,
                             urbanization: urbanization,
                             first_name: first_name,
                             last_name: last_name,
                             firm: firm,
                             phone: phone,
                             email: email,
                             ignore_bad_address: ignore_bad_address,
                             parcel_locker_delivery: parcel_locker_delivery,
                             hold_for_pickup: hold_for_pickup,
                             facility_id: facility_id,
                             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 121

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['state'] = 'state'
  @_hash['zip_code'] = 'ZIPCode'
  @_hash['zip_plus4'] = 'ZIPPlus4'
  @_hash['urbanization'] = 'urbanization'
  @_hash['first_name'] = 'firstName'
  @_hash['last_name'] = 'lastName'
  @_hash['firm'] = 'firm'
  @_hash['phone'] = 'phone'
  @_hash['email'] = 'email'
  @_hash['ignore_bad_address'] = 'ignoreBadAddress'
  @_hash['parcel_locker_delivery'] = 'parcelLockerDelivery'
  @_hash['hold_for_pickup'] = 'holdForPickup'
  @_hash['facility_id'] = 'facilityId'
  @_hash
end

.nullablesObject

An array for nullable fields



169
170
171
172
173
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 169

def self.nullables
  %w[
    zip_plus4
  ]
end

.optionalsObject

An array for optional fields



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 145

def self.optionals
  %w[
    street_address
    street_address_abbreviation
    secondary_address
    city_abbreviation
    city
    state
    zip_code
    zip_plus4
    urbanization
    first_name
    last_name
    firm
    phone
    email
    ignore_bad_address
    parcel_locker_delivery
    hold_for_pickup
    facility_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



269
270
271
272
273
274
275
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 269

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.



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 291

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}, state:"\
  " #{@state.inspect}, zip_code: #{@zip_code.inspect}, zip_plus4: #{@zip_plus4.inspect},"\
  " urbanization: #{@urbanization.inspect}, first_name: #{@first_name.inspect}, last_name:"\
  " #{@last_name.inspect}, firm: #{@firm.inspect}, phone: #{@phone.inspect}, email:"\
  " #{@email.inspect}, ignore_bad_address: #{@ignore_bad_address.inspect},"\
  " parcel_locker_delivery: #{@parcel_locker_delivery.inspect}, hold_for_pickup:"\
  " #{@hold_for_pickup.inspect}, facility_id: #{@facility_id.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



278
279
280
281
282
283
284
285
286
287
288
# File 'lib/usps_api/models/domestic_label_to_address.rb', line 278

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}, state: #{@state}, zip_code:"\
  " #{@zip_code}, zip_plus4: #{@zip_plus4}, urbanization: #{@urbanization}, first_name:"\
  " #{@first_name}, last_name: #{@last_name}, firm: #{@firm}, phone: #{@phone}, email:"\
  " #{@email}, ignore_bad_address: #{@ignore_bad_address}, parcel_locker_delivery:"\
  " #{@parcel_locker_delivery}, hold_for_pickup: #{@hold_for_pickup}, facility_id:"\
  " #{@facility_id}, additional_properties: #{@additional_properties}>"
end