rails-geocoder 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-geocoder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 8
10
- version: 0.9.8
9
+ - 9
10
+ version: 0.9.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Reisner
@@ -15,11 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-08 00:00:00 -05:00
18
+ date: 2011-03-09 00:00:00 -05:00
19
19
  default_executable:
20
- dependencies: []
21
-
22
- description: Geocoder adds object geocoding and distance calculations to ActiveRecord models. It does not rely on proprietary database functions so finding geocoded objects in a given area is easily done using out-of-the-box MySQL, PostgreSQL, or SQLite.
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance calculations for geocoded objects. Designed for Rails but works with other frameworks too.
23
38
  email:
24
39
  - alex@alexreisner.com
25
40
  executables: []
@@ -29,20 +44,39 @@ extensions: []
29
44
  extra_rdoc_files: []
30
45
 
31
46
  files:
47
+ - .gitignore
48
+ - CHANGELOG.rdoc
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
32
53
  - lib/geocoder.rb
33
- - lib/geocoder/lookup.rb
34
54
  - lib/geocoder/calculations.rb
35
- - lib/geocoder/railtie.rb
36
- - lib/geocoder/result.rb
37
55
  - lib/geocoder/configuration.rb
38
- - lib/geocoder/active_record.rb
56
+ - lib/geocoder/lookups/base.rb
57
+ - lib/geocoder/lookups/freegeoip.rb
58
+ - lib/geocoder/lookups/google.rb
59
+ - lib/geocoder/lookups/yahoo.rb
60
+ - lib/geocoder/orms/active_record.rb
61
+ - lib/geocoder/orms/active_record_legacy.rb
62
+ - lib/geocoder/orms/base.rb
63
+ - lib/geocoder/railtie.rb
64
+ - lib/geocoder/request.rb
65
+ - lib/geocoder/results/base.rb
66
+ - lib/geocoder/results/freegeoip.rb
67
+ - lib/geocoder/results/google.rb
68
+ - lib/geocoder/results/yahoo.rb
39
69
  - lib/tasks/geocoder.rake
40
- - test/test_helper.rb
70
+ - rails-geocoder.gemspec
71
+ - test/fixtures/freegeoip_74_200_247_59.json
72
+ - test/fixtures/google_garbage.json
73
+ - test/fixtures/google_madison_square_garden.json
74
+ - test/fixtures/google_no_results.json
75
+ - test/fixtures/yahoo_garbage.json
76
+ - test/fixtures/yahoo_madison_square_garden.json
77
+ - test/fixtures/yahoo_no_results.json
41
78
  - test/geocoder_test.rb
42
- - CHANGELOG.rdoc
43
- - Rakefile
44
- - README.rdoc
45
- - LICENSE
79
+ - test/test_helper.rb
46
80
  has_rdoc: true
47
81
  homepage: http://github.com/alexreisner/geocoder
48
82
  licenses: []
@@ -76,6 +110,6 @@ rubyforge_project:
76
110
  rubygems_version: 1.3.7
77
111
  signing_key:
78
112
  specification_version: 3
79
- summary: Simple, database-agnostic geocoding and distance calculations for Rails.
113
+ summary: Complete geocoding solution for Ruby.
80
114
  test_files: []
81
115
 
@@ -1,90 +0,0 @@
1
- require 'net/http'
2
-
3
- module Geocoder
4
- module Lookup
5
- extend self
6
-
7
- ##
8
- # Query Google for the coordinates of the given address.
9
- #
10
- def coordinates(address)
11
- if (results = search(address)).size > 0
12
- place = results.first.geometry['location']
13
- ['lat', 'lng'].map{ |i| place[i] }
14
- end
15
- end
16
-
17
- ##
18
- # Query Google for the address of the given coordinates.
19
- #
20
- def address(latitude, longitude)
21
- if (results = search(latitude, longitude)).size > 0
22
- results.first.formatted_address
23
- end
24
- end
25
-
26
- ##
27
- # Takes a search string (eg: "Mississippi Coast Coliseumf, Biloxi, MS") for
28
- # geocoding, or coordinates (latitude, longitude) for reverse geocoding.
29
- # Returns an array of Geocoder::Result objects,
30
- # or nil if not found or if network error.
31
- #
32
- def search(*args)
33
- return nil if args[0].blank?
34
- doc = parsed_response(args.join(","), args.size == 2)
35
- [].tap do |results|
36
- if doc
37
- doc['results'].each{ |r| results << Result.new(r) }
38
- end
39
- end
40
- end
41
-
42
-
43
- private # ---------------------------------------------------------------
44
-
45
- ##
46
- # Returns a parsed Google geocoder search result (hash).
47
- # Returns nil if non-200 HTTP response, timeout, or other error.
48
- #
49
- def parsed_response(query, reverse = false)
50
- begin
51
- doc = ActiveSupport::JSON.decode(fetch_data(query, reverse))
52
- rescue SocketError
53
- warn "Google Geocoding API connection cannot be established."
54
- rescue TimeoutError
55
- warn "Google Geocoding API not responding fast enough " +
56
- "(see Geocoder::Configuration.timeout to set limit)."
57
- end
58
-
59
- case doc['status']; when "OK"
60
- doc
61
- when "OVER_QUERY_LIMIT"
62
- warn "Google Geocoding API error: over query limit."
63
- when "REQUEST_DENIED"
64
- warn "Google Geocoding API error: request denied."
65
- when "INVALID_REQUEST"
66
- warn "Google Geocoding API error: invalid request."
67
- end
68
- end
69
-
70
- ##
71
- # Fetches a raw Google geocoder search result (JSON string).
72
- #
73
- def fetch_data(query, reverse = false)
74
- return nil if query.blank?
75
- url = query_url(query, reverse)
76
- timeout(Geocoder::Configuration.timeout) do
77
- Net::HTTP.get_response(URI.parse(url)).body
78
- end
79
- end
80
-
81
- def query_url(query, reverse = false)
82
- params = {
83
- (reverse ? :latlng : :address) => query,
84
- :sensor => "false"
85
- }
86
- "http://maps.google.com/maps/api/geocode/json?" + params.to_query
87
- end
88
- end
89
- end
90
-