google-geocode 1.1.0 → 1.2.0
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/Manifest.txt +0 -1
- data/Rakefile +4 -2
- data/lib/google_geocode.rb +13 -28
- data/test/test_google_geocode.rb +1 -1
- metadata +13 -6
- data/test/uri_stub.rb +0 -17
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ $VERBOSE = nil
|
|
8
8
|
|
9
9
|
spec = Gem::Specification.new do |s|
|
10
10
|
s.name = 'google-geocode'
|
11
|
-
s.version = '1.
|
11
|
+
s.version = '1.2.0'
|
12
12
|
s.summary = 'Google Geocoder API Library'
|
13
13
|
s.description = 'Map addresses to latitude and longitude with Google\'s Geocoder.'
|
14
14
|
s.author = 'Eric Hodel'
|
@@ -17,13 +17,15 @@ spec = Gem::Specification.new do |s|
|
|
17
17
|
s.has_rdoc = true
|
18
18
|
s.files = File.read('Manifest.txt').split($/)
|
19
19
|
s.require_path = 'lib'
|
20
|
+
|
21
|
+
s.add_dependency 'rc-rest', '>= 1.0.0'
|
20
22
|
end
|
21
23
|
|
22
24
|
desc 'Run tests'
|
23
25
|
task :default => [ :test ]
|
24
26
|
|
25
27
|
Rake::TestTask.new('test') do |t|
|
26
|
-
t.libs << '
|
28
|
+
t.libs << '../rc-rest/lib'
|
27
29
|
t.pattern = 'test/test_*.rb'
|
28
30
|
t.verbose = true
|
29
31
|
end
|
data/lib/google_geocode.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require '
|
2
|
-
require 'rexml/document'
|
1
|
+
require 'rc_rest'
|
3
2
|
|
4
3
|
##
|
5
4
|
# Library for looking up coordinates with Google's Geocoding API.
|
6
5
|
#
|
7
6
|
# http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request
|
8
7
|
|
9
|
-
class GoogleGeocode
|
8
|
+
class GoogleGeocode < RCRest
|
10
9
|
|
11
10
|
##
|
12
11
|
# Base error class
|
13
12
|
|
14
|
-
class Error <
|
13
|
+
class Error < RCRest::Error; end
|
15
14
|
|
16
15
|
##
|
17
16
|
# Raised when you try to locate an invalid address.
|
@@ -46,7 +45,8 @@ class GoogleGeocode
|
|
46
45
|
get :q => address
|
47
46
|
end
|
48
47
|
|
49
|
-
|
48
|
+
##
|
49
|
+
# Extracts a Location from +xml+.
|
50
50
|
|
51
51
|
def parse_response(xml)
|
52
52
|
l = Location.new
|
@@ -59,10 +59,11 @@ class GoogleGeocode
|
|
59
59
|
return l
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
##
|
63
|
+
# Extracts and raises an error from +xml+, if any.
|
64
64
|
|
65
|
-
|
65
|
+
def check_error(xml)
|
66
|
+
status = xml.elements['/kml/Response/Status/code'].text.to_i
|
66
67
|
case status
|
67
68
|
when 200 then # ignore, ok
|
68
69
|
when 500 then
|
@@ -82,31 +83,15 @@ class GoogleGeocode
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
url.open do |xml|
|
89
|
-
res = REXML::Document.new xml.read
|
90
|
-
|
91
|
-
check_error res
|
92
|
-
return parse_response(res)
|
93
|
-
end
|
94
|
-
rescue OpenURI::HTTPError => e
|
95
|
-
check_error e.io
|
96
|
-
raise
|
97
|
-
end
|
86
|
+
##
|
87
|
+
# Creates a URL from the Hash +params+. Automatically adds the key and
|
88
|
+
# sets the output type to 'xml'.
|
98
89
|
|
99
90
|
def make_url(params)
|
100
91
|
params[:key] = @key
|
101
92
|
params[:output] = 'xml'
|
102
93
|
|
103
|
-
|
104
|
-
"#{URI.escape k.to_s}=#{URI.escape v.to_s}"
|
105
|
-
end
|
106
|
-
|
107
|
-
url = @url.dup
|
108
|
-
url.query = escaped_params.join '&'
|
109
|
-
return url
|
94
|
+
super params
|
110
95
|
end
|
111
96
|
|
112
97
|
end
|
data/test/test_google_geocode.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.99
|
3
3
|
specification_version: 1
|
4
4
|
name: google-geocode
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2006-06-
|
6
|
+
version: 1.2.0
|
7
|
+
date: 2006-06-16 00:00:00 -07:00
|
8
8
|
summary: Google Geocoder API Library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- lib/google_geocode.rb
|
37
37
|
- test/test_google_geocode.rb
|
38
|
-
- test/uri_stub.rb
|
39
38
|
test_files: []
|
40
39
|
|
41
40
|
rdoc_options: []
|
@@ -48,5 +47,13 @@ extensions: []
|
|
48
47
|
|
49
48
|
requirements: []
|
50
49
|
|
51
|
-
dependencies:
|
52
|
-
|
50
|
+
dependencies:
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rc-rest
|
53
|
+
version_requirement:
|
54
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.0.0
|
59
|
+
version:
|
data/test/uri_stub.rb
DELETED