gcoder 0.8.0 → 0.9.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/Gemfile +1 -0
- data/LICENSE +1 -1
- data/gcoder.gemspec +1 -0
- data/lib/gcoder/geocoder.rb +14 -12
- data/lib/gcoder/resolver.rb +6 -4
- data/lib/gcoder/version.rb +1 -1
- data/lib/gcoder.rb +1 -1
- metadata +16 -3
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/gcoder.gemspec
CHANGED
data/lib/gcoder/geocoder.rb
CHANGED
@@ -79,7 +79,10 @@ module GCoder
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def http_get
|
82
|
-
|
82
|
+
Yajl::Parser.parse(
|
83
|
+
(self.class.stubs[uri] || Net::HTTP.get(HOST, path)),
|
84
|
+
:symbolize_keys => true
|
85
|
+
)
|
83
86
|
end
|
84
87
|
|
85
88
|
def latlng
|
@@ -97,36 +100,35 @@ module GCoder
|
|
97
100
|
|
98
101
|
|
99
102
|
class Response
|
100
|
-
attr_reader :
|
103
|
+
attr_reader :uri, :data
|
101
104
|
|
102
|
-
def initialize(uri,
|
103
|
-
@uri
|
104
|
-
@
|
105
|
-
@response = Hashie::Mash.new(JSON.parse(@body))
|
105
|
+
def initialize(uri, data)
|
106
|
+
@uri = uri
|
107
|
+
@data = Hashie::Mash.new(data)
|
106
108
|
validate_status!
|
107
109
|
end
|
108
110
|
|
109
111
|
def as_mash
|
110
|
-
|
112
|
+
data
|
111
113
|
end
|
112
114
|
|
113
115
|
private
|
114
116
|
|
115
117
|
def validate_status!
|
116
|
-
case
|
118
|
+
case data.status
|
117
119
|
when 'OK'
|
118
120
|
# All is well!
|
119
121
|
when 'ZERO_RESULTS'
|
120
|
-
raise NoResultsError, "Geocoding API returned no results: (#{
|
122
|
+
raise NoResultsError, "Geocoding API returned no results: (#{uri})"
|
121
123
|
when 'OVER_QUERY_LIMIT'
|
122
124
|
raise OverLimitError, 'Rate limit for Geocoding API exceeded!'
|
123
125
|
when 'REQUEST_DENIED'
|
124
|
-
raise GeocoderError, "Request denied by the Geocoding API: (#{
|
126
|
+
raise GeocoderError, "Request denied by the Geocoding API: (#{uri})"
|
125
127
|
when 'INVALID_REQUEST'
|
126
|
-
raise GeocoderError, "An invalid request was made: (#{
|
128
|
+
raise GeocoderError, "An invalid request was made: (#{uri})"
|
127
129
|
else
|
128
130
|
raise GeocoderError, 'No status in Geocoding API response: ' \
|
129
|
-
"(#{
|
131
|
+
"(#{uri})\n\n#{data.inspect}"
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
data/lib/gcoder/resolver.rb
CHANGED
@@ -15,14 +15,16 @@ module GCoder
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def geocode(query, opts = {})
|
18
|
-
fetch([query, opts].join)
|
18
|
+
fetch([query, opts].join) {
|
19
19
|
Geocoder::Request.new(query, opts).get.as_mash
|
20
|
-
|
20
|
+
}.results
|
21
21
|
end
|
22
22
|
|
23
23
|
def fetch(key)
|
24
24
|
raise ArgumentError, 'block required' unless block_given?
|
25
|
-
Hashie::Mash.new(
|
25
|
+
Hashie::Mash.new(
|
26
|
+
(val = get(key)) ? Yajl::Parser.parse(val) : set(key, yield)
|
27
|
+
)
|
26
28
|
end
|
27
29
|
|
28
30
|
private
|
@@ -34,7 +36,7 @@ module GCoder
|
|
34
36
|
|
35
37
|
def set(key, value)
|
36
38
|
return value unless @conn
|
37
|
-
@conn.set(key, value
|
39
|
+
@conn.set(key, Yajl::Encoder.encode(value))
|
38
40
|
value
|
39
41
|
end
|
40
42
|
|
data/lib/gcoder/version.rb
CHANGED
data/lib/gcoder.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 9
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.9.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Carsten Nielsen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-02 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -30,6 +30,19 @@ dependencies:
|
|
30
30
|
version: "0"
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: yajl-ruby
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
33
46
|
description: Uses Google Geocoder API to geocode stuff and optionally caches the results somewhere
|
34
47
|
email:
|
35
48
|
- heycarsten@gmail.com
|