gcoder 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source :rubygems
2
2
 
3
3
  gem 'hashie'
4
+ gem 'yajl-ruby'
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Carsten Nielsen
1
+ Copyright (c) 2011 Carsten Nielsen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/gcoder.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = 'gcoder'
16
16
 
17
17
  s.add_dependency 'hashie'
18
+ s.add_dependency 'yajl-ruby'
18
19
 
19
20
  s.files = `git ls-files`.split(?\n)
20
21
  s.test_files = `git ls-files -- {test,spec}/*`.split(?\n)
@@ -79,7 +79,10 @@ module GCoder
79
79
  end
80
80
 
81
81
  def http_get
82
- self.class.stubs[uri] || Net::HTTP.get(HOST, path)
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 :body, :uri
103
+ attr_reader :uri, :data
101
104
 
102
- def initialize(uri, body)
103
- @uri = uri
104
- @body = body
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
- @response
112
+ data
111
113
  end
112
114
 
113
115
  private
114
116
 
115
117
  def validate_status!
116
- case @response.status
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: (#{@uri})"
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: (#{@uri})"
126
+ raise GeocoderError, "Request denied by the Geocoding API: (#{uri})"
125
127
  when 'INVALID_REQUEST'
126
- raise GeocoderError, "An invalid request was made: (#{@uri})"
128
+ raise GeocoderError, "An invalid request was made: (#{uri})"
127
129
  else
128
130
  raise GeocoderError, 'No status in Geocoding API response: ' \
129
- "(#{@uri})\n\n#{@body}"
131
+ "(#{uri})\n\n#{data.inspect}"
130
132
  end
131
133
  end
132
134
  end
@@ -15,14 +15,16 @@ module GCoder
15
15
  end
16
16
 
17
17
  def geocode(query, opts = {})
18
- fetch([query, opts].join) do
18
+ fetch([query, opts].join) {
19
19
  Geocoder::Request.new(query, opts).get.as_mash
20
- end.results
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((val = get(key)) ? JSON.parse(val) : set(key, yield))
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.to_json)
39
+ @conn.set(key, Yajl::Encoder.encode(value))
38
40
  value
39
41
  end
40
42
 
@@ -1,3 +1,3 @@
1
1
  module GCoder
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
data/lib/gcoder.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'yajl'
2
2
  require 'hashie'
3
3
  require 'net/http'
4
4
  require 'timeout'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 8
7
+ - 9
8
8
  - 0
9
- version: 0.8.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: 2010-12-08 00:00:00 -05:00
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