Class: TaxCloud::Address

Inherits:
Record
  • Object
show all
Defined in:
lib/tax_cloud/address.rb

Overview

An Address defines an address in the United States.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#initialize

Constructor Details

This class inherits a constructor from TaxCloud::Record

Instance Attribute Details

#address1Object

First line of address.



5
6
7
# File 'lib/tax_cloud/address.rb', line 5

def address1
  @address1
end

#address2Object

Second line of adress.



7
8
9
# File 'lib/tax_cloud/address.rb', line 7

def address2
  @address2
end

#cityObject

City.



9
10
11
# File 'lib/tax_cloud/address.rb', line 9

def city
  @city
end

#stateObject

State.



11
12
13
# File 'lib/tax_cloud/address.rb', line 11

def state
  @state
end

#zip4Object

4-digit Zip Code.



15
16
17
# File 'lib/tax_cloud/address.rb', line 15

def zip4
  @zip4
end

#zip5Object

5-digit Zip Code.



13
14
15
# File 'lib/tax_cloud/address.rb', line 13

def zip5
  @zip5
end

Instance Method Details

#to_hashObject

Convert the object to a usable hash for SOAP requests



37
38
39
40
41
42
43
44
45
46
# File 'lib/tax_cloud/address.rb', line 37

def to_hash
  {
    'Address1' => address1,
    'Address2' => address2,
    'City' => city,
    'State' => state,
    'Zip5' => zip5,
    'Zip4' => zip4
  }
end

#verifyObject

Verify this address.

Returns a verified TaxCloud::Address.



20
21
22
23
24
25
26
27
# File 'lib/tax_cloud/address.rb', line 20

def verify
  params = to_hash.downcase_keys
  params = params.merge(
    'uspsUserID' => TaxCloud.configuration.usps_username
  ) if TaxCloud.configuration.usps_username
  response = TaxCloud.client.request(:verify_address, params)
  TaxCloud::Responses::VerifyAddress.parse(response)
end

#zipObject

Complete zip code. Returns a 9-digit Zip Code, when available.



31
32
33
34
# File 'lib/tax_cloud/address.rb', line 31

def zip
  return nil unless zip5 && zip5.length > 0
  [zip5, zip4].select { |z| z && z.length > 0 }.join('-')
end