hacked0ff-reverse_geocode 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -2
- data/Rakefile +15 -14
- data/lib/reverse_geocode.rb +12 -1
- metadata +6 -5
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2009
|
1
|
+
Copyright (c) 2009 PRIMEDIA
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -3,13 +3,13 @@ require 'rake/gempackagetask'
|
|
3
3
|
require 'rubygems/specification'
|
4
4
|
require 'date'
|
5
5
|
require 'spec/rake/spectask'
|
6
|
+
require 'rake/rdoctask'
|
6
7
|
|
7
8
|
GEM = "reverse_geocode"
|
8
|
-
GEM_VERSION = "0.0.
|
9
|
-
|
10
|
-
EMAIL = "
|
11
|
-
|
12
|
-
SUMMARY = "A gem that provides..."
|
9
|
+
GEM_VERSION = "0.0.3"
|
10
|
+
AUTHORS = ["Tommy Campbell", "Rein Henrichs"]
|
11
|
+
EMAIL = "tommycampbell@mindspring.com"
|
12
|
+
SUMMARY = "A gem that provides Reverse Geocoding using the Google Maps API"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.name = GEM
|
@@ -19,26 +19,27 @@ spec = Gem::Specification.new do |s|
|
|
19
19
|
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
20
20
|
s.summary = SUMMARY
|
21
21
|
s.description = s.summary
|
22
|
-
s.
|
22
|
+
s.authors = AUTHORS
|
23
23
|
s.email = EMAIL
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# s.add_dependency "foo"
|
28
|
-
|
24
|
+
|
25
|
+
s.add_dependency('json', '>= 1.1.3')
|
26
|
+
|
29
27
|
s.require_path = 'lib'
|
30
28
|
s.autorequire = GEM
|
31
|
-
s.files = %w(LICENSE README Rakefile
|
29
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")
|
32
30
|
end
|
33
31
|
|
34
32
|
task :default => :spec
|
35
33
|
|
36
|
-
desc "Run specs"
|
37
34
|
Spec::Rake::SpecTask.new do |t|
|
38
35
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
39
36
|
t.spec_opts = %w(-fs --color)
|
40
37
|
end
|
41
38
|
|
39
|
+
Rake::RDocTask.new { |rdoc|
|
40
|
+
rdoc.rdoc_dir = 'doc'
|
41
|
+
rdoc.rdoc_files.include('lib/*.rb')
|
42
|
+
}
|
42
43
|
|
43
44
|
Rake::GemPackageTask.new(spec) do |pkg|
|
44
45
|
pkg.gem_spec = spec
|
@@ -54,4 +55,4 @@ task :make_spec do
|
|
54
55
|
File.open("#{GEM}.gemspec", "w") do |file|
|
55
56
|
file.puts spec.to_ruby
|
56
57
|
end
|
57
|
-
end
|
58
|
+
end
|
data/lib/reverse_geocode.rb
CHANGED
@@ -2,9 +2,15 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
# ReverseGeocode provides an simple API for accessing reverse geocode data for
|
6
|
+
# a given geocode using the google maps geocoding API.
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
# ReverseGeocode.new(30.0098974, -81.3876544).city # => "St Augustine"
|
5
10
|
class ReverseGeocode
|
6
11
|
GOOGLE_URI = "http://maps.google.com/maps/geo"
|
7
12
|
|
13
|
+
# Used to raise Google API errors
|
8
14
|
class GeocodeError < StandardError
|
9
15
|
ERRORS = {
|
10
16
|
400 => "Bad Request",
|
@@ -24,12 +30,14 @@ class ReverseGeocode
|
|
24
30
|
|
25
31
|
class << self; attr_accessor :api_key; end
|
26
32
|
|
27
|
-
|
33
|
+
# Creates a new reverse geocode object.
|
28
34
|
def initialize(lat, long)
|
29
35
|
raise ArgumentError, "Latitude and longitude required" unless lat && long
|
30
36
|
@lat, @long = lat, long
|
31
37
|
end
|
38
|
+
attr_reader :lat, :long
|
32
39
|
|
40
|
+
# The raw response hash from the reverse geocode request
|
33
41
|
def response
|
34
42
|
@response ||= handle_response
|
35
43
|
end
|
@@ -93,11 +101,14 @@ class ReverseGeocode
|
|
93
101
|
end
|
94
102
|
end
|
95
103
|
|
104
|
+
# Hash.[] is aliased to '/' to provide xpath-like access into the response
|
105
|
+
# hash
|
96
106
|
class Hash
|
97
107
|
alias_method :/, :[]
|
98
108
|
end
|
99
109
|
|
100
110
|
class NilClass
|
111
|
+
# Raises a more useful error when nil#/ is called.
|
101
112
|
def /(other)
|
102
113
|
raise ArgumentError, "Unknown method '/' called on nil with #{other.inspect}. Maybe you were looking for a Hash?"
|
103
114
|
end
|
metadata
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hacked0ff-reverse_geocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Tommy Campbell
|
8
|
-
|
7
|
+
- Tommy Campbell
|
8
|
+
- Rein Henrichs
|
9
|
+
autorequire: reverse_geocode
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
@@ -36,12 +37,12 @@ files:
|
|
36
37
|
- LICENSE
|
37
38
|
- README
|
38
39
|
- Rakefile
|
39
|
-
- TODO
|
40
40
|
- lib/reverse_geocode.rb
|
41
41
|
- spec/reverse_geocode_spec.rb
|
42
42
|
- spec/spec_helper.rb
|
43
|
+
- TODO
|
43
44
|
has_rdoc: true
|
44
|
-
homepage:
|
45
|
+
homepage:
|
45
46
|
post_install_message:
|
46
47
|
rdoc_options: []
|
47
48
|
|