module UspsCounties::CityStateInfo
Constants
- USPS_URL
Public Class Methods
city_from(usps_id, zip)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 30 def self.city_from(usps_id, zip) city_state_abbrv(usps_id, zip)[0] end
city_state_abbrv(usps_id, zip)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 22 def self.city_state_abbrv(usps_id, zip) city_state ||= get_city_state_abbrv(usps_id, zip) end
counties_and_population_from(state_name)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 38 def self.counties_and_population_from(state_name) CountiesAndPopulation.counties_and_population_from(state_name) end
get_city_state_abbrv(usps_id, zip)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 10 def self.get_city_state_abbrv(usps_id, zip) api_url = url(zip, usps_id) xml_response = RestClient.get(api_url) parsed_response = Nokogiri::XML(xml_response) state_abbrv = parsed_response.xpath("//State").inner_html city = parsed_response.xpath("//City").inner_html [city, state_abbrv] rescue => ex { error: ex.message } end
query_xml(zip, usps_id)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 46 def self.query_xml(zip, usps_id) "XML=<CityStateLookupRequest USERID='#{usps_id}'><ZipCode ID='0'><Zip5>#{zip}</Zip5></ZipCode></CityStateLookupRequest>" end
state_abbrv_from(usps_id, zip)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 26 def self.state_abbrv_from(usps_id, zip) city_state_abbrv(usps_id, zip)[1] end
state_name_from(state_abbrv)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 34 def self.state_name_from(state_abbrv) Constants::STATES[state_abbrv.to_sym] end
url(zip, usps_id)
click to toggle source
# File lib/usps_counties/city_state_info.rb, line 42 def self.url(zip, usps_id) [USPS_URL, query_xml(zip, usps_id)].join('&') end