Skip to content

Commit

Permalink
Merge commit '222efc9ba28afdc0f368568bd493695f593cc095'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simple Geebus committed Jun 8, 2011
2 parents c383790 + 222efc9 commit 00ed7f1
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions lib/geocoder/us/rest.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
require 'sinatra'
require 'geocoder/us/database'
require 'json'
require 'timeout'

@@db = Geocoder::US::Database.new(ENV["GEOCODER_DB"] || ARGV[0])

set :port, 8081
get '/geocode' do
if params[:q]
results = []
begin
# TODO: remove this Timeout call?
# Read this blog post to see why Timeout is very dangerous:
# http://blog.headius.com/2008/02/ruby-threadraise-threadkill-timeoutrb.html
Timeout.timeout(1.0) do
results = @@db.geocode params[:q]
end
rescue Timeout::Error
$stderr.print "Timed out on '#{params[:q]}'\n"
end
results = @@db.geocode params[:q]
features = []
results.each do |result|
coords = [result.delete(:lon), result.delete(:lat)]
Expand Down

0 comments on commit 00ed7f1

Please sign in to comment.