rails-geocoder 0.9.10 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG.rdoc +15 -4
- data/LICENSE +1 -1
- data/README.rdoc +118 -31
- data/VERSION +1 -1
- data/lib/geocoder.rb +56 -14
- data/lib/geocoder/cache.rb +70 -0
- data/lib/geocoder/calculations.rb +162 -22
- data/lib/geocoder/configuration.rb +46 -9
- data/lib/geocoder/lookups/base.rb +40 -9
- data/lib/geocoder/lookups/freegeoip.rb +4 -6
- data/lib/geocoder/lookups/geocoder_ca.rb +44 -0
- data/lib/geocoder/lookups/google.rb +8 -5
- data/lib/geocoder/lookups/yahoo.rb +6 -4
- data/lib/geocoder/orms/active_record.rb +85 -39
- data/lib/geocoder/orms/active_record_legacy.rb +8 -4
- data/lib/geocoder/orms/base.rb +24 -21
- data/lib/geocoder/request.rb +1 -1
- data/lib/geocoder/results/base.rb +0 -14
- data/lib/geocoder/results/geocoder_ca.rb +58 -0
- data/lib/geocoder/results/google.rb +16 -4
- data/test/fixtures/geocoder_ca_madison_square_garden.json +1 -0
- data/test/fixtures/geocoder_ca_no_results.json +1 -0
- data/test/fixtures/geocoder_ca_reverse.json +34 -0
- data/test/fixtures/google_no_locality.json +51 -0
- data/test/geocoder_test.rb +220 -64
- data/test/test_helper.rb +48 -9
- metadata +15 -15
- data/rails-geocoder.gemspec +0 -14
data/test/test_helper.rb
CHANGED
@@ -38,6 +38,10 @@ module ActiveRecord
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# simulate Rails module so Railtie gets loaded
|
42
|
+
module Rails
|
43
|
+
end
|
44
|
+
|
41
45
|
# Require Geocoder after ActiveRecord simulator.
|
42
46
|
require 'geocoder'
|
43
47
|
require "geocoder/lookups/base"
|
@@ -47,26 +51,53 @@ require "geocoder/lookups/base"
|
|
47
51
|
#
|
48
52
|
module Geocoder
|
49
53
|
module Lookup
|
54
|
+
class Base
|
55
|
+
private #-----------------------------------------------------------------
|
56
|
+
def read_fixture(file)
|
57
|
+
File.read(File.join("test", "fixtures", file)).strip.gsub(/\n\s*/, "")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
50
61
|
class Google < Base
|
51
62
|
private #-----------------------------------------------------------------
|
52
63
|
def fetch_raw_data(query, reverse = false)
|
53
|
-
|
54
|
-
|
64
|
+
raise TimeoutError if query == "timeout"
|
65
|
+
file = case query
|
66
|
+
when "no results"; :no_results
|
67
|
+
when "no locality"; :no_locality
|
68
|
+
else :madison_square_garden
|
69
|
+
end
|
70
|
+
read_fixture "google_#{file}.json"
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
58
74
|
class Yahoo < Base
|
59
75
|
private #-----------------------------------------------------------------
|
60
76
|
def fetch_raw_data(query, reverse = false)
|
77
|
+
raise TimeoutError if query == "timeout"
|
61
78
|
file = query == "no results" ? :no_results : :madison_square_garden
|
62
|
-
|
79
|
+
read_fixture "yahoo_#{file}.json"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class GeocoderCa < Base
|
84
|
+
private #-----------------------------------------------------------------
|
85
|
+
def fetch_raw_data(query, reverse = false)
|
86
|
+
raise TimeoutError if query == "timeout"
|
87
|
+
if reverse
|
88
|
+
read_fixture "geocoder_ca_reverse.json"
|
89
|
+
else
|
90
|
+
file = query == "no results" ? :no_results : :madison_square_garden
|
91
|
+
read_fixture "geocoder_ca_#{file}.json"
|
92
|
+
end
|
63
93
|
end
|
64
94
|
end
|
65
95
|
|
66
96
|
class Freegeoip < Base
|
67
97
|
private #-----------------------------------------------------------------
|
68
98
|
def fetch_raw_data(query, reverse = false)
|
69
|
-
|
99
|
+
raise TimeoutError if query == "timeout"
|
100
|
+
read_fixture "freegeoip_74_200_247_59.json"
|
70
101
|
end
|
71
102
|
end
|
72
103
|
end
|
@@ -103,9 +134,9 @@ end
|
|
103
134
|
# Geocoded model with block.
|
104
135
|
#
|
105
136
|
class Event < ActiveRecord::Base
|
106
|
-
geocoded_by :address do |obj,
|
107
|
-
if result
|
108
|
-
obj.
|
137
|
+
geocoded_by :address do |obj,results|
|
138
|
+
if result = results.first
|
139
|
+
obj.coords_string = "#{result.latitude},#{result.longitude}"
|
109
140
|
end
|
110
141
|
end
|
111
142
|
|
@@ -120,8 +151,8 @@ end
|
|
120
151
|
# Reverse geocoded model with block.
|
121
152
|
#
|
122
153
|
class Party < ActiveRecord::Base
|
123
|
-
reverse_geocoded_by :latitude, :longitude do |obj,
|
124
|
-
if result
|
154
|
+
reverse_geocoded_by :latitude, :longitude do |obj,results|
|
155
|
+
if result = results.first
|
125
156
|
obj.country = result.country_code
|
126
157
|
end
|
127
158
|
end
|
@@ -161,4 +192,12 @@ class Test::Unit::TestCase
|
|
161
192
|
:msg => ["Madison Square Garden", 40.750354, -73.993371]
|
162
193
|
}[abbrev]
|
163
194
|
end
|
195
|
+
|
196
|
+
def all_lookups
|
197
|
+
Geocoder.send(:valid_lookups)
|
198
|
+
end
|
199
|
+
|
200
|
+
def street_lookups
|
201
|
+
all_lookups - [:freegeoip]
|
202
|
+
end
|
164
203
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 9
|
8
|
-
- 10
|
9
|
-
version: 0.9.10
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.11
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Alex Reisner
|
@@ -14,11 +10,11 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-25 00:00:00 -04:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
21
|
-
description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance calculations
|
17
|
+
description: "THIS GEM HAS BEEN RENAMED: please use 'geocoder' instead. Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance calculations. Designed for Rails but works with other frameworks too."
|
22
18
|
email:
|
23
19
|
- alex@alexreisner.com
|
24
20
|
executables: []
|
@@ -35,10 +31,12 @@ files:
|
|
35
31
|
- Rakefile
|
36
32
|
- VERSION
|
37
33
|
- lib/geocoder.rb
|
34
|
+
- lib/geocoder/cache.rb
|
38
35
|
- lib/geocoder/calculations.rb
|
39
36
|
- lib/geocoder/configuration.rb
|
40
37
|
- lib/geocoder/lookups/base.rb
|
41
38
|
- lib/geocoder/lookups/freegeoip.rb
|
39
|
+
- lib/geocoder/lookups/geocoder_ca.rb
|
42
40
|
- lib/geocoder/lookups/google.rb
|
43
41
|
- lib/geocoder/lookups/yahoo.rb
|
44
42
|
- lib/geocoder/orms/active_record.rb
|
@@ -48,13 +46,17 @@ files:
|
|
48
46
|
- lib/geocoder/request.rb
|
49
47
|
- lib/geocoder/results/base.rb
|
50
48
|
- lib/geocoder/results/freegeoip.rb
|
49
|
+
- lib/geocoder/results/geocoder_ca.rb
|
51
50
|
- lib/geocoder/results/google.rb
|
52
51
|
- lib/geocoder/results/yahoo.rb
|
53
52
|
- lib/tasks/geocoder.rake
|
54
|
-
- rails-geocoder.gemspec
|
55
53
|
- test/fixtures/freegeoip_74_200_247_59.json
|
54
|
+
- test/fixtures/geocoder_ca_madison_square_garden.json
|
55
|
+
- test/fixtures/geocoder_ca_no_results.json
|
56
|
+
- test/fixtures/geocoder_ca_reverse.json
|
56
57
|
- test/fixtures/google_garbage.json
|
57
58
|
- test/fixtures/google_madison_square_garden.json
|
59
|
+
- test/fixtures/google_no_locality.json
|
58
60
|
- test/fixtures/google_no_results.json
|
59
61
|
- test/fixtures/yahoo_garbage.json
|
60
62
|
- test/fixtures/yahoo_madison_square_garden.json
|
@@ -62,7 +64,7 @@ files:
|
|
62
64
|
- test/geocoder_test.rb
|
63
65
|
- test/test_helper.rb
|
64
66
|
has_rdoc: true
|
65
|
-
homepage: http://
|
67
|
+
homepage: http://www.rubygeocoder.com
|
66
68
|
licenses: []
|
67
69
|
|
68
70
|
post_install_message:
|
@@ -71,23 +73,21 @@ rdoc_options: []
|
|
71
73
|
require_paths:
|
72
74
|
- lib
|
73
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
74
77
|
requirements:
|
75
78
|
- - ">="
|
76
79
|
- !ruby/object:Gem::Version
|
77
|
-
segments:
|
78
|
-
- 0
|
79
80
|
version: "0"
|
80
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
81
83
|
requirements:
|
82
84
|
- - ">="
|
83
85
|
- !ruby/object:Gem::Version
|
84
|
-
segments:
|
85
|
-
- 0
|
86
86
|
version: "0"
|
87
87
|
requirements: []
|
88
88
|
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.5.1
|
91
91
|
signing_key:
|
92
92
|
specification_version: 3
|
93
93
|
summary: Complete geocoding solution for Ruby.
|
data/rails-geocoder.gemspec
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
Gem::Specification.new do |s|
|
3
|
-
s.name = "rails-geocoder"
|
4
|
-
s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
5
|
-
s.platform = Gem::Platform::RUBY
|
6
|
-
s.authors = ["Alex Reisner"]
|
7
|
-
s.email = ["alex@alexreisner.com"]
|
8
|
-
s.homepage = "http://github.com/alexreisner/geocoder"
|
9
|
-
s.date = Date.today.to_s
|
10
|
-
s.summary = "Complete geocoding solution for Ruby."
|
11
|
-
s.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."
|
12
|
-
s.files = `git ls-files`.split("\n") - %w[geocoder.gemspec Gemfile init.rb]
|
13
|
-
s.require_paths = ["lib"]
|
14
|
-
end
|