Class: USPS::Request::ZipCodeLookup

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

Overview

This class is essentially identical to AddressStandardization but do to how #build inheritance is being done it’s easier just to reimplement it for now.

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) ⇒ ZipCodeLookup

At most 5 zip codes can be retrieved at once



15
16
17
18
19
20
21
# File 'lib/usps/request/zip_code_lookup.rb', line 15

def initialize(*addresses)
  @addresses = addresses

  if @addresses.size > 5
    raise ArgumentError, 'at most 5 lookups can be performed per request'
  end
end

Instance Method Details

#buildObject



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

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

        # Address 1 and 2 are backwards compared to how they appear on an
        # envelope.
        builder.tag!('Address1', addy.extra_address)
        builder.tag!('Address2', addy.address)

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

#response_for(xml) ⇒ Object



23
24
25
# File 'lib/usps/request/zip_code_lookup.rb', line 23

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