Sha256: cda832059f1b92aa646e54c664557d54157ad69eb7c8e36573e2010899ccf3a0

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

# This file was auto-generated by lib/tasks/api.rake

module Usps
	module Api
		module Endpoints
			module CityStateLookup
				# City/State Lookup API
				# returns the city and state corresponding to the given ZIP Code. The CityStateLookup API processes up to five lookups per request.
				# @param [Hash] options
				# @option options [required, Hash] city_state_lookup_request API= CityStateLookupRequest
				#  * *:zip_code* (required, Hash) — 
				#    * *:zip5* (required, Integer) — 
def city_state_lookup(options = {})
					throw ArgumentError.new('Required arguments :city_state_lookup_request missing') if options[:city_state_lookup_request].nil?
					throw ArgumentError.new('Required arguments :city_state_lookup_request, :zip_code missing') if options[:city_state_lookup_request][:zip_code].nil?
					throw ArgumentError.new('Required arguments :city_state_lookup_request, :zip_code, :zip5 missing') if options[:city_state_lookup_request][:zip_code][:zip5].nil?

					request = build_request(:city_state_lookup, options)
					get('https://secure.shippingapis.com/ShippingAPI.dll', {
						API: 'CityStateLookup',
						XML: request,
					})
				end

				private

				def tag_unless_blank(xml, tag_name, data)
					xml.tag!(tag_name, data) unless data.blank? || data.nil?
				end

				def build_city_state_lookup_request(xml, options = {})
					xml.tag!('ZipCode') do
						xml.tag!('Zip5', options[:city_state_lookup_request][:zip_code][:zip5])
					end 
					xml.target!
				end

			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usps-ruby-client-0.1.3 lib/usps/api/endpoints/city_state_lookup.rb
usps-ruby-client-0.1.2 lib/usps/api/endpoints/city_state_lookup.rb
usps-ruby-client-0.1.1 lib/usps/api/endpoints/city_state_lookup.rb