graticule 0.2.12 → 1.0.0.pre
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/.autotest +13 -0
- data/.gitignore +2 -1
- data/CHANGELOG.txt +2 -0
- data/README.txt +5 -1
- data/Rakefile +31 -51
- data/VERSION +1 -1
- data/graticule.gemspec +102 -53
- data/lib/graticule/geocoder/base.rb +1 -1
- data/lib/graticule/geocoder/bogus.rb +8 -6
- data/lib/graticule/geocoder/freethepostcode.rb +38 -0
- data/lib/graticule/geocoder/geocoder_ca.rb +45 -20
- data/lib/graticule/geocoder/geocoder_us.rb +26 -14
- data/lib/graticule/geocoder/geonames.rb +51 -0
- data/lib/graticule/geocoder/google.rb +71 -44
- data/lib/graticule/geocoder/local_search_maps.rb +8 -7
- data/lib/graticule/geocoder/mapquest.rb +47 -27
- data/lib/graticule/geocoder/multi.rb +68 -8
- data/lib/graticule/geocoder/multimap.rb +49 -24
- data/lib/graticule/geocoder/yahoo.rb +57 -28
- data/lib/graticule/geocoder.rb +1 -0
- data/lib/graticule/location.rb +4 -0
- data/lib/graticule.rb +2 -4
- data/test/config.yml +32 -0
- data/test/config.yml.default +9 -12
- data/test/fixtures/responses/freethepostcode/not_found.txt +3 -0
- data/test/fixtures/responses/freethepostcode/success.txt +2 -0
- data/test/fixtures/responses/geocoder_ca/success.xml +12 -0
- data/test/fixtures/responses/geocoder_us/success.xml +3 -13
- data/test/fixtures/responses/geonames/missing.xml +4 -0
- data/test/fixtures/responses/geonames/success.xml +14 -0
- data/test/fixtures/responses/geonames/unknown.xml +4 -0
- data/test/fixtures/responses/google/partial.xml +16 -1
- data/test/fixtures/responses/google/success.xml +16 -1
- data/test/fixtures/responses/google/unknown_address.xml +8 -1
- data/test/fixtures/responses/yahoo/success.xml +2 -2
- data/test/fixtures/responses/yahoo/unknown_address.xml +1 -1
- data/test/{unit/graticule → graticule}/distance_test.rb +1 -1
- data/test/graticule/geocoder/freethepostcode_test.rb +36 -0
- data/test/graticule/geocoder/geocoder_ca_test.rb +41 -0
- data/test/{unit/graticule → graticule}/geocoder/geocoder_us_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/geocoders.rb +1 -2
- data/test/graticule/geocoder/geonames_test.rb +48 -0
- data/test/{unit/graticule → graticule}/geocoder/google_test.rb +21 -26
- data/test/{unit/graticule → graticule}/geocoder/host_ip_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/local_search_maps_test.rb +1 -1
- data/test/{unit/graticule → graticule}/geocoder/mapquest_test.rb +4 -2
- data/test/{unit/graticule → graticule}/geocoder/multi_test.rb +10 -2
- data/test/{unit/graticule → graticule}/geocoder/multimap_test.rb +2 -2
- data/test/{unit/graticule → graticule}/geocoder/yahoo_test.rb +6 -5
- data/test/{unit/graticule → graticule}/geocoder_test.rb +1 -5
- data/test/{unit/graticule → graticule}/location_test.rb +9 -1
- data/test/test_helper.rb +1 -2
- metadata +88 -47
- data/Manifest.txt +0 -84
- data/lib/graticule/geocoder/meta_carta.rb +0 -33
- data/lib/graticule/geocoder/postcode_anywhere.rb +0 -63
- data/lib/graticule/geocoder/rest.rb +0 -18
- data/lib/graticule/version.rb +0 -9
- data/test/fixtures/responses/meta_carta/bad_address.xml +0 -17
- data/test/fixtures/responses/meta_carta/multiple.xml +0 -33
- data/test/fixtures/responses/meta_carta/success.xml +0 -31
- data/test/fixtures/responses/postcode_anywhere/badkey.xml +0 -9
- data/test/fixtures/responses/postcode_anywhere/canada.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/empty.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/success.xml +0 -16
- data/test/fixtures/responses/postcode_anywhere/uk.xml +0 -18
- data/test/unit/graticule/geocoder/meta_carta_test.rb +0 -44
- data/test/unit/graticule/geocoder/postcode_anywhere_test.rb +0 -50
data/.autotest
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Autotest.add_hook :initialize do |at|
|
|
2
|
+
at.clear_mappings
|
|
3
|
+
|
|
4
|
+
at.add_mapping %r%^lib/(.*)\.rb$% do |_, m|
|
|
5
|
+
at.files_matching %r%^test/#{m[1]}_test.rb$%
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
at.add_mapping(%r%^test/.*\.rb$%) {|filename, _| filename }
|
|
9
|
+
|
|
10
|
+
at.add_mapping %r%^test/fixtures/(.*)s.yml% do |_, _|
|
|
11
|
+
at.files_matching %r%^test/.*\.rb$%
|
|
12
|
+
end
|
|
13
|
+
end
|
data/.gitignore
CHANGED
data/CHANGELOG.txt
CHANGED
data/README.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= Graticule
|
|
2
2
|
|
|
3
|
-
Graticule is a geocoding API for looking up address coordinates. It supports many popular APIs, including Yahoo, Google, Geocoder.ca
|
|
3
|
+
Graticule is a geocoding API for looking up address coordinates. It supports many popular APIs, including Yahoo, Google, Geocoder.ca and Geocoder.us.
|
|
4
4
|
|
|
5
5
|
= Usage
|
|
6
6
|
|
|
@@ -24,6 +24,10 @@ Graticule includes a command line interface (CLI).
|
|
|
24
24
|
Washington, DC US
|
|
25
25
|
latitude: 38.895222, longitude: -77.036758
|
|
26
26
|
|
|
27
|
+
= Mailing List
|
|
28
|
+
|
|
29
|
+
Join us on the mailing list at http://groups.google.com/group/graticule
|
|
30
|
+
|
|
27
31
|
= How to contribute
|
|
28
32
|
|
|
29
33
|
If you find what you might think is a bug:
|
data/Rakefile
CHANGED
|
@@ -4,23 +4,26 @@ rescue LoadError
|
|
|
4
4
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
|
5
5
|
exit 1
|
|
6
6
|
end
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'activesupport'
|
|
7
9
|
require 'rake/testtask'
|
|
8
10
|
require 'rake/rdoctask'
|
|
9
11
|
require 'rcov/rcovtask'
|
|
10
12
|
|
|
11
13
|
Jeweler::Tasks.new do |s|
|
|
12
|
-
s.name
|
|
14
|
+
s.name = "graticule"
|
|
13
15
|
s.rubyforge_project = "graticule"
|
|
14
|
-
s.author
|
|
15
|
-
s.email
|
|
16
|
-
s.summary
|
|
17
|
-
s.description
|
|
18
|
-
s.homepage
|
|
19
|
-
s.add_dependency
|
|
20
|
-
s.
|
|
21
|
-
s.
|
|
22
|
-
s.
|
|
23
|
-
s.
|
|
16
|
+
s.author = 'Brandon Keepers'
|
|
17
|
+
s.email = 'brandon@opensoul.org'
|
|
18
|
+
s.summary = "API for using all the popular geocoding services."
|
|
19
|
+
s.description = 'Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.'
|
|
20
|
+
s.homepage = "http://github.com/collectiveidea/graticule"
|
|
21
|
+
s.add_dependency "activesupport"
|
|
22
|
+
s.add_dependency 'happymapper', '>=0.3.0'
|
|
23
|
+
s.has_rdoc = true
|
|
24
|
+
s.extra_rdoc_files = ["README.txt"]
|
|
25
|
+
s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
|
|
26
|
+
s.test_files = Dir['test/**/*']
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
desc 'Default: run unit tests.'
|
|
@@ -28,7 +31,7 @@ task :default => :test
|
|
|
28
31
|
|
|
29
32
|
desc 'Run the unit tests'
|
|
30
33
|
Rake::TestTask.new(:test) do |t|
|
|
31
|
-
t.libs << 'lib'
|
|
34
|
+
t.libs << 'lib' << 'test'
|
|
32
35
|
t.pattern = 'test/**/*_test.rb'
|
|
33
36
|
t.verbose = true
|
|
34
37
|
end
|
|
@@ -75,44 +78,6 @@ namespace :rubyforge do
|
|
|
75
78
|
end
|
|
76
79
|
end
|
|
77
80
|
|
|
78
|
-
namespace :test do
|
|
79
|
-
namespace :cache do
|
|
80
|
-
desc 'Cache test responses from all the free geocoders'
|
|
81
|
-
task :free => [:google, :geocoder_us, :host_ip, :local_search_maps, :meta_carta, :yahoo]
|
|
82
|
-
|
|
83
|
-
desc 'Cache test responses from Google'
|
|
84
|
-
task :google do
|
|
85
|
-
cache_responses('google')
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
desc 'Cache test responses from Geocoder.us'
|
|
89
|
-
task :geocoder_us do
|
|
90
|
-
cache_responses('geocoder_us')
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
desc 'Cache test responses from HostIP'
|
|
94
|
-
task :host_ip do
|
|
95
|
-
cache_responses('host_ip')
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
desc 'Cache test responses from Local Search Maps'
|
|
99
|
-
task :local_search_maps do
|
|
100
|
-
cache_responses('local_search_maps')
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
desc 'Cache test responses from Meta Carta'
|
|
104
|
-
task :meta_carta do
|
|
105
|
-
cache_responses('meta_carta')
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
desc 'Cache test responses from Yahoo'
|
|
109
|
-
task :yahoo do
|
|
110
|
-
cache_responses('yahoo')
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
81
|
require 'active_support'
|
|
117
82
|
require 'net/http'
|
|
118
83
|
require 'uri'
|
|
@@ -140,4 +105,19 @@ def update_placeholders!(config, thing)
|
|
|
140
105
|
config.each do |option, value|
|
|
141
106
|
thing.gsub!(":#{option}", value) if value.is_a?(String)
|
|
142
107
|
end
|
|
143
|
-
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
namespace :test do
|
|
111
|
+
namespace :cache do
|
|
112
|
+
desc 'Cache test responses from all the geocoders'
|
|
113
|
+
task :all => test_config.keys
|
|
114
|
+
|
|
115
|
+
test_config.keys.each do |service|
|
|
116
|
+
desc "Cache test responses for #{service}"
|
|
117
|
+
task service do
|
|
118
|
+
cache_responses(service)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
1.0.0.pre
|
data/graticule.gemspec
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{graticule}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "1.0.0.pre"
|
|
9
9
|
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Brandon Keepers"]
|
|
12
|
-
s.date = %q{2009-
|
|
12
|
+
s.date = %q{2009-12-05}
|
|
13
13
|
s.default_executable = %q{geocode}
|
|
14
14
|
s.description = %q{Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.}
|
|
15
15
|
s.email = %q{brandon@opensoul.org}
|
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
"README.txt"
|
|
19
19
|
]
|
|
20
20
|
s.files = [
|
|
21
|
-
".
|
|
21
|
+
".autotest",
|
|
22
|
+
".gitignore",
|
|
22
23
|
"CHANGELOG.txt",
|
|
23
24
|
"LICENSE.txt",
|
|
24
|
-
"Manifest.txt",
|
|
25
25
|
"README.txt",
|
|
26
26
|
"Rakefile",
|
|
27
27
|
"VERSION",
|
|
@@ -38,26 +38,30 @@ Gem::Specification.new do |s|
|
|
|
38
38
|
"lib/graticule/geocoder.rb",
|
|
39
39
|
"lib/graticule/geocoder/base.rb",
|
|
40
40
|
"lib/graticule/geocoder/bogus.rb",
|
|
41
|
+
"lib/graticule/geocoder/freethepostcode.rb",
|
|
41
42
|
"lib/graticule/geocoder/geocoder_ca.rb",
|
|
42
43
|
"lib/graticule/geocoder/geocoder_us.rb",
|
|
44
|
+
"lib/graticule/geocoder/geonames.rb",
|
|
43
45
|
"lib/graticule/geocoder/google.rb",
|
|
44
46
|
"lib/graticule/geocoder/host_ip.rb",
|
|
45
47
|
"lib/graticule/geocoder/local_search_maps.rb",
|
|
46
48
|
"lib/graticule/geocoder/mapquest.rb",
|
|
47
|
-
"lib/graticule/geocoder/meta_carta.rb",
|
|
48
49
|
"lib/graticule/geocoder/multi.rb",
|
|
49
50
|
"lib/graticule/geocoder/multimap.rb",
|
|
50
|
-
"lib/graticule/geocoder/postcode_anywhere.rb",
|
|
51
|
-
"lib/graticule/geocoder/rest.rb",
|
|
52
51
|
"lib/graticule/geocoder/yahoo.rb",
|
|
53
52
|
"lib/graticule/location.rb",
|
|
54
|
-
"lib/graticule/version.rb",
|
|
55
53
|
"site/index.html",
|
|
56
54
|
"site/plugin.html",
|
|
57
55
|
"site/stylesheets/style.css",
|
|
58
56
|
"test/config.yml.default",
|
|
57
|
+
"test/fixtures/responses/freethepostcode/not_found.txt",
|
|
58
|
+
"test/fixtures/responses/freethepostcode/success.txt",
|
|
59
|
+
"test/fixtures/responses/geocoder_ca/success.xml",
|
|
59
60
|
"test/fixtures/responses/geocoder_us/success.xml",
|
|
60
61
|
"test/fixtures/responses/geocoder_us/unknown.xml",
|
|
62
|
+
"test/fixtures/responses/geonames/missing.xml",
|
|
63
|
+
"test/fixtures/responses/geonames/success.xml",
|
|
64
|
+
"test/fixtures/responses/geonames/unknown.xml",
|
|
61
65
|
"test/fixtures/responses/google/badkey.xml",
|
|
62
66
|
"test/fixtures/responses/google/limit.xml",
|
|
63
67
|
"test/fixtures/responses/google/missing_address.xml",
|
|
@@ -76,72 +80,117 @@ Gem::Specification.new do |s|
|
|
|
76
80
|
"test/fixtures/responses/local_search_maps/success.txt",
|
|
77
81
|
"test/fixtures/responses/mapquest/multi_result.xml",
|
|
78
82
|
"test/fixtures/responses/mapquest/success.xml",
|
|
79
|
-
"test/fixtures/responses/meta_carta/bad_address.xml",
|
|
80
|
-
"test/fixtures/responses/meta_carta/multiple.xml",
|
|
81
|
-
"test/fixtures/responses/meta_carta/success.xml",
|
|
82
83
|
"test/fixtures/responses/multimap/missing_params.xml",
|
|
83
84
|
"test/fixtures/responses/multimap/no_matches.xml",
|
|
84
85
|
"test/fixtures/responses/multimap/success.xml",
|
|
85
|
-
"test/fixtures/responses/postcode_anywhere/badkey.xml",
|
|
86
|
-
"test/fixtures/responses/postcode_anywhere/canada.xml",
|
|
87
|
-
"test/fixtures/responses/postcode_anywhere/empty.xml",
|
|
88
|
-
"test/fixtures/responses/postcode_anywhere/success.xml",
|
|
89
|
-
"test/fixtures/responses/postcode_anywhere/uk.xml",
|
|
90
86
|
"test/fixtures/responses/yahoo/success.xml",
|
|
91
87
|
"test/fixtures/responses/yahoo/unknown_address.xml",
|
|
88
|
+
"test/graticule/distance_test.rb",
|
|
89
|
+
"test/graticule/geocoder/freethepostcode_test.rb",
|
|
90
|
+
"test/graticule/geocoder/geocoder_ca_test.rb",
|
|
91
|
+
"test/graticule/geocoder/geocoder_us_test.rb",
|
|
92
|
+
"test/graticule/geocoder/geocoders.rb",
|
|
93
|
+
"test/graticule/geocoder/geonames_test.rb",
|
|
94
|
+
"test/graticule/geocoder/google_test.rb",
|
|
95
|
+
"test/graticule/geocoder/host_ip_test.rb",
|
|
96
|
+
"test/graticule/geocoder/local_search_maps_test.rb",
|
|
97
|
+
"test/graticule/geocoder/mapquest_test.rb",
|
|
98
|
+
"test/graticule/geocoder/multi_test.rb",
|
|
99
|
+
"test/graticule/geocoder/multimap_test.rb",
|
|
100
|
+
"test/graticule/geocoder/yahoo_test.rb",
|
|
101
|
+
"test/graticule/geocoder_test.rb",
|
|
102
|
+
"test/graticule/location_test.rb",
|
|
92
103
|
"test/mocks/uri.rb",
|
|
93
|
-
"test/test_helper.rb"
|
|
94
|
-
"test/unit/graticule/distance_test.rb",
|
|
95
|
-
"test/unit/graticule/geocoder/geocoder_us_test.rb",
|
|
96
|
-
"test/unit/graticule/geocoder/geocoders.rb",
|
|
97
|
-
"test/unit/graticule/geocoder/google_test.rb",
|
|
98
|
-
"test/unit/graticule/geocoder/host_ip_test.rb",
|
|
99
|
-
"test/unit/graticule/geocoder/local_search_maps_test.rb",
|
|
100
|
-
"test/unit/graticule/geocoder/mapquest_test.rb",
|
|
101
|
-
"test/unit/graticule/geocoder/meta_carta_test.rb",
|
|
102
|
-
"test/unit/graticule/geocoder/multi_test.rb",
|
|
103
|
-
"test/unit/graticule/geocoder/multimap_test.rb",
|
|
104
|
-
"test/unit/graticule/geocoder/postcode_anywhere_test.rb",
|
|
105
|
-
"test/unit/graticule/geocoder/yahoo_test.rb",
|
|
106
|
-
"test/unit/graticule/geocoder_test.rb",
|
|
107
|
-
"test/unit/graticule/location_test.rb"
|
|
104
|
+
"test/test_helper.rb"
|
|
108
105
|
]
|
|
109
|
-
s.has_rdoc = true
|
|
110
106
|
s.homepage = %q{http://github.com/collectiveidea/graticule}
|
|
111
107
|
s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
|
|
112
108
|
s.require_paths = ["lib"]
|
|
113
109
|
s.rubyforge_project = %q{graticule}
|
|
114
|
-
s.rubygems_version = %q{1.3.
|
|
110
|
+
s.rubygems_version = %q{1.3.5}
|
|
115
111
|
s.summary = %q{API for using all the popular geocoding services.}
|
|
116
112
|
s.test_files = [
|
|
117
|
-
"test/
|
|
118
|
-
"test/
|
|
119
|
-
"test/
|
|
120
|
-
"test/
|
|
121
|
-
"test/
|
|
122
|
-
"test/
|
|
123
|
-
"test/
|
|
124
|
-
"test/
|
|
125
|
-
"test/
|
|
126
|
-
"test/
|
|
127
|
-
"test/
|
|
128
|
-
"test/
|
|
129
|
-
"test/
|
|
130
|
-
"test/
|
|
131
|
-
"test/
|
|
132
|
-
"test/
|
|
113
|
+
"test/config.yml",
|
|
114
|
+
"test/config.yml.default",
|
|
115
|
+
"test/fixtures",
|
|
116
|
+
"test/fixtures/responses",
|
|
117
|
+
"test/fixtures/responses/freethepostcode",
|
|
118
|
+
"test/fixtures/responses/freethepostcode/not_found.txt",
|
|
119
|
+
"test/fixtures/responses/freethepostcode/success.txt",
|
|
120
|
+
"test/fixtures/responses/geocoder_ca",
|
|
121
|
+
"test/fixtures/responses/geocoder_ca/success.xml",
|
|
122
|
+
"test/fixtures/responses/geocoder_us",
|
|
123
|
+
"test/fixtures/responses/geocoder_us/success.xml",
|
|
124
|
+
"test/fixtures/responses/geocoder_us/unknown.xml",
|
|
125
|
+
"test/fixtures/responses/geonames",
|
|
126
|
+
"test/fixtures/responses/geonames/missing.xml",
|
|
127
|
+
"test/fixtures/responses/geonames/success.xml",
|
|
128
|
+
"test/fixtures/responses/geonames/unknown.xml",
|
|
129
|
+
"test/fixtures/responses/google",
|
|
130
|
+
"test/fixtures/responses/google/badkey.xml",
|
|
131
|
+
"test/fixtures/responses/google/limit.xml",
|
|
132
|
+
"test/fixtures/responses/google/missing_address.xml",
|
|
133
|
+
"test/fixtures/responses/google/only_coordinates.xml",
|
|
134
|
+
"test/fixtures/responses/google/partial.xml",
|
|
135
|
+
"test/fixtures/responses/google/server_error.xml",
|
|
136
|
+
"test/fixtures/responses/google/success.xml",
|
|
137
|
+
"test/fixtures/responses/google/success_multiple_results.xml",
|
|
138
|
+
"test/fixtures/responses/google/unavailable.xml",
|
|
139
|
+
"test/fixtures/responses/google/unknown_address.xml",
|
|
140
|
+
"test/fixtures/responses/host_ip",
|
|
141
|
+
"test/fixtures/responses/host_ip/private.txt",
|
|
142
|
+
"test/fixtures/responses/host_ip/success.txt",
|
|
143
|
+
"test/fixtures/responses/host_ip/unknown.txt",
|
|
144
|
+
"test/fixtures/responses/local_search_maps",
|
|
145
|
+
"test/fixtures/responses/local_search_maps/empty.txt",
|
|
146
|
+
"test/fixtures/responses/local_search_maps/not_found.txt",
|
|
147
|
+
"test/fixtures/responses/local_search_maps/success.txt",
|
|
148
|
+
"test/fixtures/responses/mapquest",
|
|
149
|
+
"test/fixtures/responses/mapquest/multi_result.xml",
|
|
150
|
+
"test/fixtures/responses/mapquest/success.xml",
|
|
151
|
+
"test/fixtures/responses/multimap",
|
|
152
|
+
"test/fixtures/responses/multimap/missing_params.xml",
|
|
153
|
+
"test/fixtures/responses/multimap/no_matches.xml",
|
|
154
|
+
"test/fixtures/responses/multimap/success.xml",
|
|
155
|
+
"test/fixtures/responses/yahoo",
|
|
156
|
+
"test/fixtures/responses/yahoo/success.xml",
|
|
157
|
+
"test/fixtures/responses/yahoo/unknown_address.xml",
|
|
158
|
+
"test/graticule",
|
|
159
|
+
"test/graticule/distance_test.rb",
|
|
160
|
+
"test/graticule/geocoder",
|
|
161
|
+
"test/graticule/geocoder/freethepostcode_test.rb",
|
|
162
|
+
"test/graticule/geocoder/geocoder_ca_test.rb",
|
|
163
|
+
"test/graticule/geocoder/geocoder_us_test.rb",
|
|
164
|
+
"test/graticule/geocoder/geocoders.rb",
|
|
165
|
+
"test/graticule/geocoder/geonames_test.rb",
|
|
166
|
+
"test/graticule/geocoder/google_test.rb",
|
|
167
|
+
"test/graticule/geocoder/host_ip_test.rb",
|
|
168
|
+
"test/graticule/geocoder/local_search_maps_test.rb",
|
|
169
|
+
"test/graticule/geocoder/mapquest_test.rb",
|
|
170
|
+
"test/graticule/geocoder/multi_test.rb",
|
|
171
|
+
"test/graticule/geocoder/multimap_test.rb",
|
|
172
|
+
"test/graticule/geocoder/yahoo_test.rb",
|
|
173
|
+
"test/graticule/geocoder_test.rb",
|
|
174
|
+
"test/graticule/location_test.rb",
|
|
175
|
+
"test/mocks",
|
|
176
|
+
"test/mocks/uri.rb",
|
|
177
|
+
"test/test_helper.rb"
|
|
133
178
|
]
|
|
134
179
|
|
|
135
180
|
if s.respond_to? :specification_version then
|
|
136
181
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
137
|
-
s.specification_version =
|
|
182
|
+
s.specification_version = 3
|
|
138
183
|
|
|
139
184
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
140
185
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
|
186
|
+
s.add_runtime_dependency(%q<happymapper>, [">= 0.3.0"])
|
|
141
187
|
else
|
|
142
188
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
|
189
|
+
s.add_dependency(%q<happymapper>, [">= 0.3.0"])
|
|
143
190
|
end
|
|
144
191
|
else
|
|
145
192
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
|
193
|
+
s.add_dependency(%q<happymapper>, [">= 0.3.0"])
|
|
146
194
|
end
|
|
147
195
|
end
|
|
196
|
+
|
|
@@ -50,7 +50,7 @@ module Graticule #:nodoc:
|
|
|
50
50
|
# end
|
|
51
51
|
#
|
|
52
52
|
class Base
|
|
53
|
-
USER_AGENT = "Mozilla/5.0 (compatible; Graticule
|
|
53
|
+
USER_AGENT = "Mozilla/5.0 (compatible; Graticule; http://graticule.rubyforge.org)"
|
|
54
54
|
|
|
55
55
|
def initialize
|
|
56
56
|
raise NotImplementedError
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
module Graticule #:nodoc:
|
|
2
2
|
module Geocoder #:nodoc:
|
|
3
|
-
|
|
4
3
|
# Bogus geocoder that can be used for test purposes
|
|
5
4
|
class Bogus
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
# A queue of canned responses
|
|
6
|
+
class_inheritable_accessor :responses
|
|
7
|
+
self.responses = []
|
|
8
|
+
|
|
9
|
+
# A default location to use if the responses queue is empty
|
|
10
|
+
class_inheritable_accessor :default
|
|
11
|
+
|
|
8
12
|
def locate(address)
|
|
9
|
-
Location.new
|
|
13
|
+
responses.shift || default || Location.new(:street => address)
|
|
10
14
|
end
|
|
11
|
-
|
|
12
15
|
end
|
|
13
|
-
|
|
14
16
|
end
|
|
15
17
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Graticule #:nodoc:
|
|
2
|
+
module Geocoder #:nodoc:
|
|
3
|
+
|
|
4
|
+
# freethepostcode.org (http://www.freethepostcode.org/) is a
|
|
5
|
+
# free service to convert UK postcodes into geolocation data.
|
|
6
|
+
#
|
|
7
|
+
# gg = Graticule.service(:FreeThePostcode).new
|
|
8
|
+
# location = gg.locate 'W1A 1AA'
|
|
9
|
+
# location.coordinates
|
|
10
|
+
# #=> [51.52093, -0.13714]
|
|
11
|
+
class FreeThePostcode < Base
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@url = URI.parse 'http://www.freethepostcode.org/geocode'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def locate(postcode)
|
|
18
|
+
get :postcode => postcode
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def prepare_response(response)
|
|
24
|
+
response.split("\n")[1]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def parse_response(response)
|
|
28
|
+
data = response.split
|
|
29
|
+
Location.new(:latitude => data[0].to_f, :longitude => data[1].to_f, :precision => :unknown)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def check_error(response)
|
|
33
|
+
raise AddressError, 'unknown address' if response.blank?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -2,7 +2,7 @@ module Graticule #:nodoc:
|
|
|
2
2
|
module Geocoder #:nodoc:
|
|
3
3
|
|
|
4
4
|
# TODO: Reverse Geocoding
|
|
5
|
-
class GeocoderCa <
|
|
5
|
+
class GeocoderCa < Base
|
|
6
6
|
|
|
7
7
|
def initialize(auth = nil)
|
|
8
8
|
@url = URI.parse 'http://geocoder.ca/'
|
|
@@ -14,29 +14,54 @@ module Graticule #:nodoc:
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
|
|
18
|
+
class Response
|
|
19
|
+
include HappyMapper
|
|
20
|
+
tag 'geodata'
|
|
21
|
+
element :latitude, Float, :tag => 'latt'
|
|
22
|
+
element :longitude, Float, :tag => 'longt'
|
|
23
|
+
element :street_number, String, :deep => true, :tag => 'stnumber'
|
|
24
|
+
element :street_name, String, :deep => true, :tag => 'staddress'
|
|
25
|
+
element :locality, String, :deep => true, :tag => 'city'
|
|
26
|
+
element :postal_code, String, :tag => 'postal'
|
|
27
|
+
element :region, String, :deep => true, :tag => 'prov'
|
|
28
|
+
|
|
29
|
+
class Error
|
|
30
|
+
include HappyMapper
|
|
31
|
+
tag 'error'
|
|
32
|
+
element :code, Integer
|
|
33
|
+
element :description, String
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
has_one :error, Error
|
|
37
|
+
|
|
38
|
+
def street
|
|
39
|
+
[street_number, street_name].join(' ')
|
|
25
40
|
end
|
|
26
41
|
end
|
|
42
|
+
|
|
43
|
+
def prepare_response(xml)
|
|
44
|
+
Response.parse(xml, :single => true)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def parse_response(response) #:nodoc:
|
|
48
|
+
Location.new(
|
|
49
|
+
:latitude => response.latitude,
|
|
50
|
+
:longitude => response.longitude,
|
|
51
|
+
:street => response.street,
|
|
52
|
+
:locality => response.locality,
|
|
53
|
+
:region => response.region
|
|
54
|
+
)
|
|
55
|
+
end
|
|
27
56
|
|
|
28
|
-
def check_error(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
raise CredentialsError, message
|
|
35
|
-
elsif (4..8).include?(code)
|
|
36
|
-
raise AddressError, message
|
|
37
|
-
else
|
|
38
|
-
raise Error, message
|
|
57
|
+
def check_error(response) #:nodoc:
|
|
58
|
+
if response.error
|
|
59
|
+
exception = case response.error.code
|
|
60
|
+
when 1..3; CredentialsError
|
|
61
|
+
when 4..8; AddressError
|
|
62
|
+
else; Error
|
|
39
63
|
end
|
|
64
|
+
raise exception, response.error.message
|
|
40
65
|
end
|
|
41
66
|
end
|
|
42
67
|
|
|
@@ -4,7 +4,7 @@ module Graticule #:nodoc:
|
|
|
4
4
|
# A library for lookup up coordinates with geocoder.us' API.
|
|
5
5
|
#
|
|
6
6
|
# http://geocoder.us/help/
|
|
7
|
-
class GeocoderUs <
|
|
7
|
+
class GeocoderUs < Base
|
|
8
8
|
|
|
9
9
|
# Creates a new GeocoderUs object optionally using +username+ and
|
|
10
10
|
# +password+.
|
|
@@ -13,7 +13,7 @@ module Graticule #:nodoc:
|
|
|
13
13
|
#
|
|
14
14
|
# http://geocoder.us/user/signup
|
|
15
15
|
def initialize(user = nil, password = nil)
|
|
16
|
-
if user
|
|
16
|
+
if user && password
|
|
17
17
|
@url = URI.parse 'http://geocoder.us/member/service/rest/geocode'
|
|
18
18
|
@url.user = user
|
|
19
19
|
@url.password = password
|
|
@@ -29,22 +29,34 @@ module Graticule #:nodoc:
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
private
|
|
32
|
+
class Point
|
|
33
|
+
include HappyMapper
|
|
34
|
+
tag 'Point'
|
|
35
|
+
namespace 'http://www.w3.org/2003/01/geo/wgs84_pos#'
|
|
36
|
+
|
|
37
|
+
element :description, String, :namespace => 'http://purl.org/dc/elements/1.1/'
|
|
38
|
+
element :longitude, Float, :tag => 'long'
|
|
39
|
+
element :latitude, Float, :tag => 'lat'
|
|
40
|
+
end
|
|
32
41
|
|
|
33
42
|
def parse_response(xml) #:nodoc:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return location
|
|
43
|
+
point = Point.parse(xml, :single => true)
|
|
44
|
+
Location.new(
|
|
45
|
+
:street => point.description,
|
|
46
|
+
:latitude => point.latitude,
|
|
47
|
+
:longitude => point.longitude
|
|
48
|
+
)
|
|
41
49
|
end
|
|
42
50
|
|
|
43
|
-
def check_error(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
def check_error(response) #:nodoc:
|
|
52
|
+
case response
|
|
53
|
+
when /geo:Point/
|
|
54
|
+
# success
|
|
55
|
+
when /couldn't find this address! sorry/
|
|
56
|
+
raise AddressError, response
|
|
57
|
+
else
|
|
58
|
+
raise Error, response
|
|
59
|
+
end
|
|
48
60
|
end
|
|
49
61
|
|
|
50
62
|
end
|