Class: UspsApi::PmodDomesticAddress

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

Overview

The address of the Business Mail Entry Unit (BMEU) or authorized acceptance location facility where the Open and Distribute container is being entered. The origin ZIP Code is used for calculating pricing.

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:, city:, state:, zip_code:, secondary_address: SKIP, zip_plus4: SKIP, urbanization: SKIP, additional_properties: nil) ⇒ PmodDomesticAddress

Returns a new instance of PmodDomesticAddress.



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

def initialize(street_address:, city:, state:, zip_code:,
               secondary_address: SKIP, zip_plus4: SKIP, urbanization: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @street_address = street_address
  @secondary_address = secondary_address unless secondary_address == SKIP
  @city = city
  @state = state
  @zip_code = zip_code
  @zip_plus4 = zip_plus4 unless zip_plus4 == SKIP
  @urbanization = urbanization unless urbanization == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#cityString

This is the city name of the address.

Returns:

  • (String)


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

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


24
25
26
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 24

def secondary_address
  @secondary_address
end

#stateString

This is two-character state code of the address.

Returns:

  • (String)


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

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)


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

def street_address
  @street_address
end

#urbanizationString

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

Returns:

  • (String)


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

def urbanization
  @urbanization
end

#zip_codeString

This is the 5-digit ZIP code.

Returns:

  • (String)


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

def zip_code
  @zip_code
end

#zip_plus4String

This is the ZIP+4 extension.

Returns:

  • (String)


40
41
42
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 40

def zip_plus4
  @zip_plus4
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  street_address = hash.key?('streetAddress') ? hash['streetAddress'] : nil
  city = hash.key?('city') ? hash['city'] : nil
  state = hash.key?('state') ? hash['state'] : nil
  zip_code = hash.key?('ZIPCode') ? hash['ZIPCode'] : nil
  secondary_address =
    hash.key?('secondaryAddress') ? hash['secondaryAddress'] : SKIP
  zip_plus4 = hash.key?('ZIPPlus4') ? hash['ZIPPlus4'] : SKIP
  urbanization = hash.key?('urbanization') ? hash['urbanization'] : 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.
  PmodDomesticAddress.new(street_address: street_address,
                          city: city,
                          state: state,
                          zip_code: zip_code,
                          secondary_address: secondary_address,
                          zip_plus4: zip_plus4,
                          urbanization: urbanization,
                          additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 48

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['street_address'] = 'streetAddress'
  @_hash['secondary_address'] = 'secondaryAddress'
  @_hash['city'] = 'city'
  @_hash['state'] = 'state'
  @_hash['zip_code'] = 'ZIPCode'
  @_hash['zip_plus4'] = 'ZIPPlus4'
  @_hash['urbanization'] = 'urbanization'
  @_hash
end

.nullablesObject

An array for nullable fields



70
71
72
73
74
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 70

def self.nullables
  %w[
    zip_plus4
  ]
end

.optionalsObject

An array for optional fields



61
62
63
64
65
66
67
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 61

def self.optionals
  %w[
    secondary_address
    zip_plus4
    urbanization
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 126

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.street_address,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.city,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.state,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.zip_code,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['streetAddress'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['city'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['state'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['ZIPCode'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



164
165
166
167
168
169
170
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 164

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address.inspect}, secondary_address:"\
  " #{@secondary_address.inspect}, city: #{@city.inspect}, state: #{@state.inspect}, zip_code:"\
  " #{@zip_code.inspect}, zip_plus4: #{@zip_plus4.inspect}, urbanization:"\
  " #{@urbanization.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



155
156
157
158
159
160
161
# File 'lib/usps_api/models/pmod_domestic_address.rb', line 155

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} street_address: #{@street_address}, secondary_address:"\
  " #{@secondary_address}, city: #{@city}, state: #{@state}, zip_code: #{@zip_code},"\
  " zip_plus4: #{@zip_plus4}, urbanization: #{@urbanization}, additional_properties:"\
  " #{@additional_properties}>"
end