Skip to content
Snippets Groups Projects
Commit 881b8eb7 authored by Eugene Russkikh's avatar Eugene Russkikh
Browse files

http basic auth and geocoder.us

parent d780da88
No related branches found
No related tags found
No related merge requests found
...@@ -372,6 +372,18 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of ...@@ -372,6 +372,18 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
* **Terms of Service**: http://geocoder.ca/?terms=1 * **Terms of Service**: http://geocoder.ca/?terms=1
* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." * **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission."
#### Geocoder.us (`:geocoder_us`)
* **API key**: HTTP Basic Auth
* **Sign up**: http://geocoder.us/user/signup
* **Quota**: You can purchase 20,000 credits at a time for $50
* **Region**: US
* **SSL support**: no
* **Languages**: English
* **Documentation**: http://geocoder.us/help/
* **Terms of Service**: http://geocoder.us/terms.shtml
* **Limitations**: ?
#### Mapquest (`:mapquest`) #### Mapquest (`:mapquest`)
* **API key**: required * **API key**: required
...@@ -538,7 +550,7 @@ For example: ...@@ -538,7 +550,7 @@ For example:
after_validation :reverse_geocode, :if => :has_coordinates after_validation :reverse_geocode, :if => :has_coordinates
after_validation :geocode, :if => :has_location, :unless => :has_coordinates after_validation :geocode, :if => :has_location, :unless => :has_coordinates
end end
Use Outside of Rails Use Outside of Rails
-------------------- --------------------
...@@ -641,7 +653,7 @@ Notes on Non-Rails Frameworks ...@@ -641,7 +653,7 @@ Notes on Non-Rails Frameworks
If you are using Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino) you will need to add this in your model before calling Geocoder methods: If you are using Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino) you will need to add this in your model before calling Geocoder methods:
extend Geocoder::Model::ActiveRecord extend Geocoder::Model::ActiveRecord
Optimisation of Distance Queries Optimisation of Distance Queries
-------------------------------- --------------------------------
...@@ -740,7 +752,7 @@ When reporting an issue, please list the version of Geocoder you are using and a ...@@ -740,7 +752,7 @@ When reporting an issue, please list the version of Geocoder you are using and a
Known Issue Known Issue
----------- -----------
You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa). You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa).
Instead of using `includes` to reduce the number of database queries, try using `joins` with either the `:select` option or a call to `preload`. For example: Instead of using `includes` to reduce the number of database queries, try using `joins` with either the `:select` option or a call to `preload`. For example:
......
...@@ -28,6 +28,7 @@ module Geocoder ...@@ -28,6 +28,7 @@ module Geocoder
:yahoo, :yahoo,
:bing, :bing,
:geocoder_ca, :geocoder_ca,
:geocoder_us,
:yandex, :yandex,
:nominatim, :nominatim,
:mapquest, :mapquest,
......
...@@ -72,7 +72,7 @@ module Geocoder ...@@ -72,7 +72,7 @@ module Geocoder
def query_url(query) def query_url(query)
fail fail
end end
## ##
# The working Cache object. # The working Cache object.
# #
...@@ -227,9 +227,16 @@ module Geocoder ...@@ -227,9 +227,16 @@ module Geocoder
def make_api_request(query) def make_api_request(query)
timeout(configuration.timeout) do timeout(configuration.timeout) do
uri = URI.parse(query_url(query)) uri = URI.parse(query_url(query))
client = http_client.new(uri.host, uri.port) # client = http_client.new(uri.host, uri.port)
client.use_ssl = true if configuration.use_https # client.use_ssl = true if configuration.use_https
client.get(uri.request_uri, configuration.http_headers) # client.get(uri.request_uri, configuration.http_headers)
http_client.start(uri.host, uri.port) do |client|
client.use_ssl = true if configuration.use_https
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
req.basic_auth(uri.user, uri.password) if uri.user and uri.password
client.request(req)
end
end end
end end
......
require 'geocoder/lookups/base'
require "geocoder/results/geocoder_us"
module Geocoder::Lookup
class GeocoderUs < Base
def name
"Geocoder.us"
end
def query_url(query)
if configuration.api_key
"http://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query)
else
"http://geocoder.us/service/csv/geocode?" + url_query_string(query)
end
end
private
def results(query)
return [] unless doc = fetch_data(query)
if doc.to_s =~ /^(\d+)\:/
return []
else
return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc]
end
end
def query_url_params(query)
(query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super)
end
def parse_raw_data(raw_data)
raw_data.chomp.split(',')
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class GeocoderUs < Base
def coordinates
[@data[0].to_f, @data[1].to_f]
end
def address(format = :full)
"#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def street_address
@data[2]
end
def city
@data[3]
end
def state
@data[4]
end
alias_method :state_code, :state
def postal_code
@data[5]
end
def country
'United States'
end
def country_code
'US'
end
end
end
40.678107, -73.897460, 4 Pennsylvania Ave, New York, NY, 11207
\ No newline at end of file
2: couldn't find this address! sorry
\ No newline at end of file
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