Class: USPS::Request::AddressStandardization

Inherits:
Base
  • Object
show all
Defined in:
lib/usps/request/address_standardization.rb

Overview

TODO: #send! could be made smarter to send lookup batches

Instance Method Summary collapse

Methods inherited from Base

#api, config, #secure?, #send!

Constructor Details

#initialize(*addresses) ⇒ AddressStandardization

At most 5 addresses can be verified



12
13
14
15
16
17
18
# File 'lib/usps/request/address_standardization.rb', line 12

def initialize(*addresses)
  @addresses = addresses.flatten

  if @addresses.size > 5
    raise ArgumentError, 'at most 5 addresses can be verified at a time'
  end
end

Instance Method Details

#buildObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/usps/request/address_standardization.rb', line 24

def build
  super do |builder|
    @addresses.each_with_index do |addy, i|
      builder.tag!('Address', :ID => i) do
        builder.tag!('FirmName', addy.firm)

        # Address fields are swapped in the USPS API
        builder.tag!('Address1', addy.extra_address)
        builder.tag!('Address2', addy.address)

        builder.tag!('City', addy.city)
        builder.tag!('State', addy.state)

        builder.tag!('Zip5', addy.zip5)
        builder.tag!('Zip4', addy.zip4)
      end
    end
  end
end

#response_for(xml) ⇒ Object



20
21
22
# File 'lib/usps/request/address_standardization.rb', line 20

def response_for(xml)
  self.class.response.new(@addresses, xml)
end