Class: UspsApi::AddressesAddressResponse

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

Overview

Standardizes street addresses including city and street abbreviations, and provides missing information such as ZIP Code™ and ZIP + 4®.

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(firm: SKIP, address: SKIP, additional_info: SKIP, corrections: SKIP, matches: SKIP, warnings: SKIP) ⇒ AddressesAddressResponse

Returns a new instance of AddressesAddressResponse.



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

def initialize(firm: SKIP, address: SKIP, additional_info: SKIP,
               corrections: SKIP, matches: SKIP, warnings: SKIP)
  @firm = firm unless firm == SKIP
  @address = address unless address == SKIP
  @additional_info = additional_info unless additional_info == SKIP
  @corrections = corrections unless corrections == SKIP
  @matches = matches unless matches == SKIP
  @warnings = warnings unless warnings == SKIP
end

Instance Attribute Details

#additional_infoAddressesAddressAdditionalInformation

Extra information about the request.



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

def additional_info
  @additional_info
end

#addressAddressesDomesticAddress

Address fields for US locations



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

def address
  @address
end

#correctionsArray[AddressCorrection]

Codes that indicate how to improve the address input to get a better match. Code ‘32` will indicate “Default address: The address you entered was found but more information is needed (such as an apartment, suite, or box number.” The recommended change would be to add additional information, such as an apartment, suite, or box number, to match to a specific address. Code `22` will indicate “Multiple addresses were found for the information you entered, and no default exists.” The address could not be resolved as entered and more information would be needed to identify the address.

Returns:



36
37
38
# File 'lib/usps_api/models/addresses_address_response.rb', line 36

def corrections
  @corrections
end

#firmString

This is the firm/business name at the address.

Returns:

  • (String)


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

def firm
  @firm
end

#matchesArray[AddressMatch]

Codes that indicate if an address is an exact match. Code ‘31` will be returned “Single Response - exact match” indicating that the address was correctly matched to a ZIP+4 record.

Returns:



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

def matches
  @matches
end

#warningsArray[String]

Codes that indicate if an address is an exact match. Code ‘31` will be returned “Single Response - exact match” indicating that the address was correctly matched to a ZIP+4 record.

Returns:

  • (Array[String])


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

def warnings
  @warnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/usps_api/models/addresses_address_response.rb', line 90

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  firm = hash.key?('firm') ? hash['firm'] : SKIP
  address = AddressesDomesticAddress.from_hash(hash['address']) if hash['address']
  additional_info = AddressesAddressAdditionalInformation.from_hash(hash['additionalInfo']) if
    hash['additionalInfo']
  # Parameter is an array, so we need to iterate through it
  corrections = nil
  unless hash['corrections'].nil?
    corrections = []
    hash['corrections'].each do |structure|
      corrections << (AddressCorrection.from_hash(structure) if structure)
    end
  end

  corrections = SKIP unless hash.key?('corrections')
  # Parameter is an array, so we need to iterate through it
  matches = nil
  unless hash['matches'].nil?
    matches = []
    hash['matches'].each do |structure|
      matches << (AddressMatch.from_hash(structure) if structure)
    end
  end

  matches = SKIP unless hash.key?('matches')
  warnings = hash.key?('warnings') ? hash['warnings'] : SKIP

  # Create object from extracted values.
  AddressesAddressResponse.new(firm: firm,
                               address: address,
                               additional_info: additional_info,
                               corrections: corrections,
                               matches: matches,
                               warnings: warnings)
end

.namesObject

A mapping from model property names to API property names.



51
52
53
54
55
56
57
58
59
60
# File 'lib/usps_api/models/addresses_address_response.rb', line 51

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['firm'] = 'firm'
  @_hash['address'] = 'address'
  @_hash['additional_info'] = 'additionalInfo'
  @_hash['corrections'] = 'corrections'
  @_hash['matches'] = 'matches'
  @_hash['warnings'] = 'warnings'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



63
64
65
66
67
68
69
70
71
72
# File 'lib/usps_api/models/addresses_address_response.rb', line 63

def self.optionals
  %w[
    firm
    address
    additional_info
    corrections
    matches
    warnings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



137
138
139
140
141
142
# File 'lib/usps_api/models/addresses_address_response.rb', line 137

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} firm: #{@firm.inspect}, address: #{@address.inspect}, additional_info:"\
  " #{@additional_info.inspect}, corrections: #{@corrections.inspect}, matches:"\
  " #{@matches.inspect}, warnings: #{@warnings.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



130
131
132
133
134
# File 'lib/usps_api/models/addresses_address_response.rb', line 130

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} firm: #{@firm}, address: #{@address}, additional_info: #{@additional_info},"\
  " corrections: #{@corrections}, matches: #{@matches}, warnings: #{@warnings}>"
end