class Geocoder::Lookup::Yahoo
def base_url
def base_url "#{protocol}://yboss.yahooapis.com/geo/placefinder?" end
def cache_key(query)
def cache_key(query) raw_url(query) end
def map_link_url(coordinates)
def map_link_url(coordinates) "http://maps.yahoo.com/#lat=#{coordinates[0]}&lon=#{coordinates[1]}" end
def name
def name "Yahoo BOSS" end
def parse_raw_data(raw_data)
to warning message.
Yahoo auth errors can also be cryptic, so add raw error desc
(which would add unnecessary complexity).
Handle that here, without parsing the XML
Yahoo returns errors as XML even when JSON format is specified.
#
def parse_raw_data(raw_data) if raw_data.match(/^<\?xml/) if raw_data.include?("Rate Limit Exceeded") raise_error(Geocoder::OverQueryLimitError) || Geocoder.log(:warn, "Over API query limit.") elsif raw_data =~ /<yahoo:description>(Please provide valid credentials.*)<\/yahoo:description>/i raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key. Error response: #{$1}") end else super(raw_data) end end
def query_url(query)
def query_url(query) parsed_url = URI.parse(raw_url(query)) o = OauthUtil.new o.consumer_key = configuration.api_key[0] o.consumer_secret = configuration.api_key[1] base_url + o.sign(parsed_url).query_string end
def query_url_params(query)
def query_url_params(query) lang = (query.language || configuration.language).to_s lang += '_US' if lang == 'en' { :location => query.sanitized_text, :flags => "JXTSR", :gflags => "AC#{'R' if query.reverse_geocode?}", :locale => lang, :appid => configuration.api_key }.merge(super) end
def raw_url(query)
def raw_url(query) base_url + url_query_string(query) end
def required_api_key_parts
def required_api_key_parts ["consumer key", "consumer secret"] end
def results(query)
def results(query) return [] unless doc = fetch_data(query) doc = doc['bossresponse'] if doc['responsecode'].to_i == 200 if doc['placefinder']['count'].to_i > 0 return doc['placefinder']['results'] else return [] end else Geocoder.log(:warn, "Yahoo Geocoding API error: #{doc['responsecode']} (#{doc['reason']}).") return [] end end