mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-11 18:38:50 -04:00
Set User-Agent in Geocoder requests; delete custom nominatim lib.
Nominatim-the-service's license requires that we identify ourselves. The custom nominatim lib is no longer required since Geocoder is now Fast Enough.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
Geocoder.configure(
|
||||
:units => :km
|
||||
:units => :km,
|
||||
:http_headers => {
|
||||
"User-Agent" =>
|
||||
"#{Growstuff::Application.config.user_agent} #{Growstuff::Application.config.user_agent_email}",
|
||||
"From" => Growstuff::Application.config.user_agent_email
|
||||
}
|
||||
)
|
||||
# This configuration takes precedence over environment/test.rb
|
||||
# Reported as https://github.com/alexreisner/geocoder/issues/509
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
require 'nominatim'
|
||||
|
||||
Nominatim.user_agent = Growstuff::Application.config.user_agent
|
||||
Nominatim.user_agent_email = Growstuff::Application.config.user_agent_email
|
||||
@@ -1,43 +0,0 @@
|
||||
require 'open-uri'
|
||||
require 'json'
|
||||
|
||||
class Nominatim
|
||||
|
||||
# class-level instance variable, see
|
||||
# http://www.railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/
|
||||
class << self
|
||||
attr_accessor :in_testing
|
||||
attr_accessor :user_agent
|
||||
attr_accessor :user_agent_email
|
||||
end
|
||||
@in_testing = false
|
||||
|
||||
def self.geocode(place)
|
||||
if self.in_testing
|
||||
return stubs[place]
|
||||
end
|
||||
json = open(
|
||||
URI.escape("http://nominatim.openstreetmap.org/search/#{place}?format=json&limit=1"),
|
||||
"User-Agent" => user_agent,
|
||||
"From" => user_agent_email
|
||||
).read()
|
||||
location = JSON.parse(json)
|
||||
if location && location[0]
|
||||
return {
|
||||
:latitude => location[0]['lat'],
|
||||
:longitude => location[0]['lon'],
|
||||
:boundingbox => location[0]['boundingbox'],
|
||||
}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.stubs
|
||||
@stubs ||= {}
|
||||
end
|
||||
|
||||
def self.add_stub(query_text, results)
|
||||
stubs[query_text] = results
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user