2012-06-19 01:32:50 +00:00
|
|
|
require 'savon'
|
2012-06-19 02:14:15 +00:00
|
|
|
|
2012-06-19 01:32:50 +00:00
|
|
|
require 'pp'
|
2012-06-19 02:14:15 +00:00
|
|
|
require 'tmpdir'
|
2012-06-19 01:32:50 +00:00
|
|
|
|
|
|
|
WSDL = File.expand_path('./uszip.wsdl', File.dirname(__FILE__))
|
|
|
|
|
|
|
|
def main
|
2012-06-19 02:14:15 +00:00
|
|
|
logfile = File.join(Dir.tmpdir, 'uszip.log')
|
|
|
|
HTTPI.log = false
|
|
|
|
Savon.configure do |config|
|
|
|
|
config.log = true
|
|
|
|
config.log_level = :debug
|
|
|
|
config.logger = Logger.new(logfile)
|
|
|
|
end
|
|
|
|
r = get_info_by_zip((ARGV.first || 90210).to_i)
|
|
|
|
puts "#{r[:city]}, #{r[:state]} #{r[:zip]} " <<
|
|
|
|
"(#{r[:area_code]}) [#{r[:time_zone]}]"
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_info_by_zip(zipcode)
|
2012-06-19 01:32:50 +00:00
|
|
|
client = Savon.client(WSDL)
|
2012-06-19 02:14:15 +00:00
|
|
|
response = client.request(:get_info_by_zip) do
|
|
|
|
soap.body = {"USZip" => zipcode}
|
2012-06-19 01:32:50 +00:00
|
|
|
end
|
2012-06-19 02:14:15 +00:00
|
|
|
res = response.to_hash[:get_info_by_zip_response][:get_info_by_zip_result]
|
|
|
|
res[:new_data_set][:table]
|
2012-06-19 01:32:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if $0 == __FILE__
|
|
|
|
main
|
|
|
|
end
|