Class: Verizon::Address

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/models/address.rb

Overview

The customer address for the line’s primary place of use, for line usage taxation.

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(address_line1:, city:, state:, zip:, country:, address_line2: SKIP, zip4: SKIP, phone: SKIP, phone_type: SKIP, email_address: SKIP, additional_properties: nil) ⇒ Address

Returns a new instance of Address.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/verizon/models/address.rb', line 86

def initialize(address_line1:, city:, state:, zip:, country:,
               address_line2: SKIP, zip4: SKIP, phone: SKIP,
               phone_type: SKIP, email_address: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @address_line1 = address_line1
  @address_line2 = address_line2 unless address_line2 == SKIP
  @city = city
  @state = state
  @zip = zip
  @zip4 = zip4 unless zip4 == SKIP
  @country = country
  @phone = phone unless phone == SKIP
  @phone_type = phone_type unless phone_type == SKIP
  @email_address = email_address unless email_address == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#address_line1String

The street address for the line’s primary place of use. This must be a physical address for taxation; it cannot be a P.O. box.

Returns:

  • (String)


16
17
18
# File 'lib/verizon/models/address.rb', line 16

def address_line1
  @address_line1
end

#address_line2String

Optional additional street address information.

Returns:

  • (String)


20
21
22
# File 'lib/verizon/models/address.rb', line 20

def address_line2
  @address_line2
end

#cityString

The city for the line’s primary place of use.

Returns:

  • (String)


24
25
26
# File 'lib/verizon/models/address.rb', line 24

def city
  @city
end

#countryString

Either “US” or “USA” for the country of the line’s primary place of use.

Returns:

  • (String)


40
41
42
# File 'lib/verizon/models/address.rb', line 40

def country
  @country
end

#email_addressString

An email address for the customer.

Returns:

  • (String)


52
53
54
# File 'lib/verizon/models/address.rb', line 52

def email_address
  @email_address
end

#phoneString

A phone number where the customer can be reached.

Returns:

  • (String)


44
45
46
# File 'lib/verizon/models/address.rb', line 44

def phone
  @phone
end

#phone_typeString

A single letter to indicate the customer phone type.

Returns:

  • (String)


48
49
50
# File 'lib/verizon/models/address.rb', line 48

def phone_type
  @phone_type
end

#stateString

The state for the line’s primary place of use.

Returns:

  • (String)


28
29
30
# File 'lib/verizon/models/address.rb', line 28

def state
  @state
end

#zipString

The ZIP code for the line’s primary place of use.

Returns:

  • (String)


32
33
34
# File 'lib/verizon/models/address.rb', line 32

def zip
  @zip
end

#zip4String

The ZIP+4 for the line’s primary place of use.

Returns:

  • (String)


36
37
38
# File 'lib/verizon/models/address.rb', line 36

def zip4
  @zip4
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/verizon/models/address.rb', line 107

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  address_line1 = hash.key?('addressLine1') ? hash['addressLine1'] : nil
  city = hash.key?('city') ? hash['city'] : nil
  state = hash.key?('state') ? hash['state'] : nil
  zip = hash.key?('zip') ? hash['zip'] : nil
  country = hash.key?('country') ? hash['country'] : nil
  address_line2 = hash.key?('addressLine2') ? hash['addressLine2'] : SKIP
  zip4 = hash.key?('zip4') ? hash['zip4'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  phone_type = hash.key?('phoneType') ? hash['phoneType'] : SKIP
  email_address = hash.key?('emailAddress') ? hash['emailAddress'] : 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.
  Address.new(address_line1: address_line1,
              city: city,
              state: state,
              zip: zip,
              country: country,
              address_line2: address_line2,
              zip4: zip4,
              phone: phone,
              phone_type: phone_type,
              email_address: email_address,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/verizon/models/address.rb', line 55

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['address_line1'] = 'addressLine1'
  @_hash['address_line2'] = 'addressLine2'
  @_hash['city'] = 'city'
  @_hash['state'] = 'state'
  @_hash['zip'] = 'zip'
  @_hash['zip4'] = 'zip4'
  @_hash['country'] = 'country'
  @_hash['phone'] = 'phone'
  @_hash['phone_type'] = 'phoneType'
  @_hash['email_address'] = 'emailAddress'
  @_hash
end

.nullablesObject

An array for nullable fields



82
83
84
# File 'lib/verizon/models/address.rb', line 82

def self.nullables
  []
end

.optionalsObject

An array for optional fields



71
72
73
74
75
76
77
78
79
# File 'lib/verizon/models/address.rb', line 71

def self.optionals
  %w[
    address_line2
    zip4
    phone
    phone_type
    email_address
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Address | Hash)

    value against the validation is performed.



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
175
# File 'lib/verizon/models/address.rb', line 145

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.address_line1,
                            ->(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,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.country,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['addressLine1'],
                          ->(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'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['country'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



187
188
189
190
191
192
193
194
# File 'lib/verizon/models/address.rb', line 187

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line1: #{@address_line1.inspect}, address_line2:"\
  " #{@address_line2.inspect}, city: #{@city.inspect}, state: #{@state.inspect}, zip:"\
  " #{@zip.inspect}, zip4: #{@zip4.inspect}, country: #{@country.inspect}, phone:"\
  " #{@phone.inspect}, phone_type: #{@phone_type.inspect}, email_address:"\
  " #{@email_address.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



178
179
180
181
182
183
184
# File 'lib/verizon/models/address.rb', line 178

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line1: #{@address_line1}, address_line2: #{@address_line2}, city:"\
  " #{@city}, state: #{@state}, zip: #{@zip}, zip4: #{@zip4}, country: #{@country}, phone:"\
  " #{@phone}, phone_type: #{@phone_type}, email_address: #{@email_address},"\
  " additional_properties: #{@additional_properties}>"
end