Skip to content
Snippets Groups Projects
Commit 3375c03f authored by Alex Reisner's avatar Alex Reisner
Browse files

Remove :okf lookup.

Appears to be defunct.
parent bf87abe7
No related branches found
No related tags found
No related merge requests found
......@@ -265,18 +265,6 @@ Data Science Toolkit provides an API whose response format is like Google's but
* **Terms of Service**: http://smartystreets.com/legal/terms-of-service
* **Limitations**: No reverse geocoding.
### OKF Geocoder (`:okf`)
* **API key**: none
* **Quota**: none
* **Region**: FI
* **SSL support**: no
* **Languages**: fi
* **Documentation**: http://books.okf.fi/geocoder/_full/
* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf
* **Limitations**: ?
### Geoportail.lu (`:geoportail_lu`)
* **API key**: none
......
......@@ -45,7 +45,6 @@ module Geocoder
:baidu,
:geocodio,
:smarty_streets,
:okf,
:postcode_anywhere_uk,
:postcodes_io,
:geoportail_lu,
......
require 'geocoder/lookups/base'
require "geocoder/results/okf"
module Geocoder::Lookup
class Okf < Base
def name
"Okf"
end
def query_url(query)
"#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query)
end
private # ---------------------------------------------------------------
def valid_response?(response)
json = parse_json(response.body)
status = json["status"] if json
super(response) and ['OK', 'ZERO_RESULTS'].include?(status)
end
def results(query)
return [] unless doc = fetch_data(query)
case doc['status']; when "OK" # OK status implies >0 results
return doc['results']
end
return []
end
def query_url_okf_params(query)
params = {
(query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
:sensor => "false",
:language => (query.language || configuration.language)
}
params
end
def query_url_params(query)
query_url_okf_params(query).merge(super)
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class Okf < Base
def coordinates
['lat', 'lng'].map{ |i| geometry['location'][i] }
end
def address(format = :full)
formatted_address
end
def city
fields = [:locality, :sublocality,
:administrative_area_level_3,
:administrative_area_level_2]
fields.each do |f|
if entity = address_components_of_type(f).first
return entity['long_name']
end
end
return nil # no appropriate components found
end
def state
""
end
def sub_state
""
end
def state_code
""
end
def country
if country = address_components_of_type(:country).first
country['long_name']
end
end
def country_code
if country = address_components_of_type(:country).first
country['short_name']
end
end
def postal_code
if postal = address_components_of_type(:postal_code).first
postal['long_name']
end
end
def route
if route = address_components_of_type(:route).first
route['long_name']
end
end
def street_number
if street_number = address_components_of_type(:street_number).first
street_number['long_name']
end
end
def street_address
[route, street_number].compact.join(' ')
end
def types
@data['types']
end
def formatted_address
@data['formatted_address']
end
def address_components
@data['address_components']
end
##
# Get address components of a given type. Valid types are defined in
# Google's Geocoding API documentation and include (among others):
#
# :street_number
# :locality
# :neighborhood
# :route
# :postal_code
#
def address_components_of_type(type)
address_components.select{ |c| c['types'].include?(type.to_s) }
end
def geometry
@data['geometry']
end
def precision
geometry['location_type'] if geometry
end
end
end
{
"status" : "OK",
"results" : [
{
"formatted_address" : "Kirstinmäki 1, 02760 Espoo, Suomi",
"sources" : [
{
"name" : "National Land Survey of Finland - Topographic Dataset (2013-03-08)",
"terms_of_use" : "National Land Survey open data licence - version 1.0 - 1 May 2012\nhttp://www.maanmittauslaitos.fi/en/NLS_open_data_licence_version1_20120501"
},
{
"name" : "Itella perusosoitteisto (2014-02-01)",
"terms_of_use" : "http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf"
}
],
"types" : [
"street_address"
],
"address_components" : [
{
"types" : [
"street_number"
],
"short_name" : "1",
"long_name" : "1"
},
{
"types" : [
"route"
],
"short_name" : "Kirstinmäki",
"long_name" : "Kirstinmäki"
},
{
"types" : [
"administrative_area_level_3",
"political"
],
"short_name" : "Espoo",
"long_name" : "Espoo"
},
{
"types" : [
"postal_code"
],
"short_name" : "02760",
"long_name" : "02760"
},
{
"types" : [
"country",
"political"
],
"short_name" : "FI",
"long_name" : "Suomi"
}
],
"geometry" : {
"location" : {
"lat" : 60.2015185792087,
"lng" : 24.6667520050026
},
"location_type" : "RANGE_INTERPOLATED"
}
}
]
}
{
"status" : "ZERO_RESULTS",
"results" : []
}
......@@ -318,14 +318,6 @@ module Geocoder
end
end
require 'geocoder/lookups/okf'
class Okf
private
def default_fixture_filename
"okf_kirstinmaki"
end
end
require 'geocoder/lookups/postcode_anywhere_uk'
class PostcodeAnywhereUk
private
......
......@@ -19,7 +19,7 @@ class ErrorHandlingTest < GeocoderTestCase
def test_always_raise_response_parse_error
Geocoder.configure(:always_raise => [Geocoder::ResponseParseError])
[:freegeoip, :google, :ipdata_co, :okf].each do |l|
[:freegeoip, :google, :ipdata_co].each do |l|
lookup = Geocoder::Lookup.get(l)
set_api_key!(l)
assert_raises Geocoder::ResponseParseError do
......@@ -29,7 +29,7 @@ class ErrorHandlingTest < GeocoderTestCase
end
def test_never_raise_response_parse_error
[:freegeoip, :google, :ipdata_co, :okf].each do |l|
[:freegeoip, :google, :ipdata_co].each do |l|
lookup = Geocoder::Lookup.get(l)
set_api_key!(l)
silence_warnings do
......
# encoding: utf-8
require 'test_helper'
class OkfTest < GeocoderTestCase
def setup
Geocoder.configure(lookup: :okf)
end
def test_okf_result_components
result = Geocoder.search("Kirstinmäki 11b28").first
assert_equal "Espoo",
result.address_components_of_type(:administrative_area_level_3).first['long_name']
end
def test_okf_result_components_contains_route
result = Geocoder.search("Kirstinmäki 11b28").first
assert_equal "Kirstinmäki",
result.address_components_of_type(:route).first['long_name']
end
def test_okf_result_components_contains_street_number
result = Geocoder.search("Kirstinmäki 11b28").first
assert_equal "1",
result.address_components_of_type(:street_number).first['long_name']
end
def test_okf_street_address_returns_formatted_street_address
result = Geocoder.search("Kirstinmäki 11b28").first
assert_equal "Kirstinmäki 1", result.street_address
end
def test_okf_precision
result = Geocoder.search("Kirstinmäki 11b28").first
assert_equal "RANGE_INTERPOLATED", result.precision
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