google-geocode 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,3 @@ README
4
4
  Rakefile
5
5
  lib/google_geocode.rb
6
6
  test/test_google_geocode.rb
7
- test/uri_stub.rb
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.1.0'
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 << 'test'
28
+ t.libs << '../rc-rest/lib'
27
29
  t.pattern = 'test/test_*.rb'
28
30
  t.verbose = true
29
31
  end
@@ -1,17 +1,16 @@
1
- require 'open-uri'
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 < RuntimeError; end
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
- private
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
- def check_error(obj)
63
- obj = REXML::Document.new obj.read unless REXML::Document === obj
62
+ ##
63
+ # Extracts and raises an error from +xml+, if any.
64
64
 
65
- status = obj.elements['/kml/Response/Status/code'].text.to_i
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
- def get(params)
86
- url = make_url params
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
- escaped_params = params.sort_by { |k,v| k.to_s }.map do |k,v|
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
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'test/uri_stub'
2
+ require 'rc_rest/uri_stub'
3
3
 
4
4
  require 'google_geocode'
5
5
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11.15
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.1.0
7
- date: 2006-06-12 00:00:00 -07:00
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:
@@ -1,17 +0,0 @@
1
- require 'open-uri'
2
-
3
- class URI::HTTP
4
-
5
- class << self
6
- attr_accessor :responses, :uris
7
- end
8
-
9
- alias original_open open
10
-
11
- def open
12
- self.class.uris << self.to_s
13
- yield StringIO.new(self.class.responses.shift)
14
- end
15
-
16
- end
17
-