Skip to content
Snippets Groups Projects
Commit d9419f07 authored by Aleem Uddin's avatar Aleem Uddin Committed by GitHub
Browse files

Merge pull request #1 from glsignal/master

Add test coverage for LocationIQ lookup
parents 086de4f9 d9c2c7a5
No related branches found
No related tags found
No related merge requests found
...@@ -16,5 +16,17 @@ module Geocoder::Lookup ...@@ -16,5 +16,17 @@ module Geocoder::Lookup
host = configuration[:host] || "locationiq.org/v1" host = configuration[:host] || "locationiq.org/v1"
"#{protocol}://#{host}/#{method}?key=#{configuration.api_key}&" + url_query_string(query) "#{protocol}://#{host}/#{method}?key=#{configuration.api_key}&" + url_query_string(query)
end end
private
def results(query)
return [] unless doc = fetch_data(query)
if !doc.is_a?(Array) && doc['error'] =~ /Invalid\skey/
raise_error(Geocoder::InvalidApiKey, doc['error'])
end
doc.is_a?(Array) ? doc : [doc]
end
end end
end end
{
"error": "Invalid key"
}
[
{
"place_id": "30632629",
"licence": "Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.",
"osm_type": "way",
"osm_id": "24801588",
"boundingbox": [
"40.749828338623",
"40.7511596679688",
"-73.9943389892578",
"-73.9926528930664"
],
"polygonpoints": [
[
"-73.9943346",
"40.7503638"
],
[
"-73.9942745",
"40.7504158"
],
[
"-73.9942593",
"40.750629"
],
[
"-73.9941343",
"40.7508432"
],
[
"-73.9939794",
"40.7509703"
],
[
"-73.9938042",
"40.7510532"
],
[
"-73.9938025",
"40.7511311"
],
[
"-73.9936051",
"40.7511571"
],
[
"-73.9935673",
"40.751105"
],
[
"-73.9934095",
"40.7511089"
],
[
"-73.9931235",
"40.7510548"
],
[
"-73.9928863",
"40.7509311"
],
[
"-73.9928068",
"40.750949"
],
[
"-73.992721",
"40.7508515"
],
[
"-73.9927444",
"40.7507889"
],
[
"-73.9926693",
"40.7506457"
],
[
"-73.9926597",
"40.7503657"
],
[
"-73.9928305",
"40.7500953"
],
[
"-73.9929757",
"40.7499911"
],
[
"-73.9931281",
"40.7499238"
],
[
"-73.993133",
"40.7498631"
],
[
"-73.9932961",
"40.7498306"
],
[
"-73.9933664",
"40.7498742"
],
[
"-73.993471",
"40.7498701"
],
[
"-73.9938023",
"40.7499263"
],
[
"-73.9940703",
"40.7500756"
],
[
"-73.9941876",
"40.7502038"
],
[
"-73.9942831",
"40.7502142"
],
[
"-73.9943346",
"40.7503638"
]
],
"lat": "40.7504928941818",
"lon": "-73.993466492276",
"display_name": "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
"class": "leisure",
"type": "stadium",
"address": {
"stadium": "Madison Square Garden",
"road": "West 31st Street",
"suburb": "Long Island City",
"city": "New York City",
"county": "New York",
"state": "New York",
"postcode": "10001",
"country": "United States of America",
"country_code": "us"
}
}
]
[ ]
<html>\n<head>\n<title>Bandwidth limit exceeded</title>\n</head>\n<body>\n<h1>Bandwidth limit exceeded</h1>\n\n<p>You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.</p>\n\n<p>For more information, consult the <a href=\"http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy\">usage policy</a> for the OSM Nominatim server.\n</body>\n</head>\n
...@@ -176,6 +176,14 @@ module Geocoder ...@@ -176,6 +176,14 @@ module Geocoder
end end
end end
require 'geocoder/lookups/locationiq'
class Locationiq
private
def fixture_prefix
"locationiq"
end
end
require 'geocoder/lookups/yandex' require 'geocoder/lookups/yandex'
class Yandex class Yandex
private private
......
# encoding: utf-8
require 'unit/lookups/nominatim_test'
require 'test_helper'
class LocationIq < NominatimTest
def setup
Geocoder.configure(lookup: :locationiq)
set_api_key!(:locationiq)
end
def test_url_contains_api_key
Geocoder.configure(locationiq: {api_key: "abc123"})
query = Geocoder::Query.new("Leadville, CO")
assert_equal "http://locationiq.org/v1/search.php?key=abc123&accept-language=en&addressdetails=1&format=json&q=Leadville%2C+CO", query.url
end
def test_raises_exception_with_invalid_api_key
Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
assert_raises Geocoder::InvalidApiKey do
Geocoder.search("invalid api key")
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment