gcoder 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -158,7 +158,7 @@ G = GCoder.connect \
158
158
 
159
159
  ## Contributors
160
160
 
161
- * Carsten Nielsen
162
- * Christos Pappas (Added support for Google Maps API Premier and Rails.cache
163
- adapter.)
164
- * [GUI](http://github.com/GUI) (Ruby 1.8.7 compatibility, URI encoding fixes.)
161
+ * [Carsten Nielsen](http://github.com/heycarsten)
162
+ * [Christos Pappas](http://github.com/christospappas) - Added support for
163
+ Google Maps API Premier and Rails.cache adapter.
164
+ * [GUI](http://github.com/GUI) - Ruby 1.8.7 compatibility, URI encoding fixes.
data/gcoder.gemspec CHANGED
@@ -6,18 +6,19 @@ Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.date = Date.today.strftime('%F')
8
8
  s.homepage = 'http://github.com/heycarsten/gcoder'
9
- s.authors = ['Carsten Nielsen', 'Christos Pappas']
9
+ s.authors = ['Carsten Nielsen', 'Christos Pappas', 'GUI']
10
10
  s.email = 'heycarsten@gmail.com'
11
11
  s.summary = 'A nice library for geocoding stuff with Google Maps API V3'
12
12
  s.rubyforge_project = 'gcoder'
13
- s.files = `git ls-files`.split(?\n)
14
- s.test_files = `git ls-files -- {test,spec}/*`.split(?\n)
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
15
15
  s.require_paths = ['lib']
16
16
 
17
17
  s.add_dependency 'hashie'
18
- s.add_dependency 'yajl-ruby'
18
+ s.add_dependency 'multi_json'
19
19
  s.add_dependency 'ruby-hmac'
20
- s.add_development_dependency 'bundler', '>= 1.0.14'
20
+ s.add_development_dependency 'bundler'
21
+ s.add_development_dependency 'minitest'
21
22
  s.add_development_dependency 'redis'
22
23
 
23
24
  s.description = <<-END
@@ -6,7 +6,7 @@ module GCoder
6
6
 
7
7
  class Request
8
8
  def self.to_query(params)
9
- params.map { |key, val|
9
+ params.sort_by { |key, val| key.to_s }.map { |key, val|
10
10
  "#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}"
11
11
  }.join('&')
12
12
  end
@@ -26,12 +26,12 @@ module GCoder
26
26
 
27
27
  def params
28
28
  p = { :sensor => 'false' }
29
- p[:address] = address if @address
30
- p[:latlng] = latlng if @latlng
31
- p[:language] = @config[:language] if @config[:language]
32
- p[:region] = @config[:region] if @config[:region]
33
- p[:bounds] = bounds if @config[:bounds]
34
- p[:client] = @config[:client] if @config[:client]
29
+ p[:address] = address if @address
30
+ p[:latlng] = latlng if @latlng
31
+ p[:language] = @config[:language] if @config[:language]
32
+ p[:region] = @config[:region] if @config[:region]
33
+ p[:bounds] = bounds if @config[:bounds]
34
+ p[:client] = @config[:client] if @config[:client]
35
35
  p
36
36
  end
37
37
 
@@ -78,7 +78,7 @@ module GCoder
78
78
  end
79
79
 
80
80
  def http_get
81
- Yajl::Parser.parse(
81
+ MultiJson.load(
82
82
  (self.class.stubs[uri] || Net::HTTP.get(HOST, path)),
83
83
  :symbolize_keys => true
84
84
  )
@@ -23,7 +23,7 @@ module GCoder
23
23
  def fetch(key)
24
24
  raise ArgumentError, 'block required' unless block_given?
25
25
  Hashie::Mash.new(
26
- (val = get(key)) ? Yajl::Parser.parse(val) : set(key, yield)
26
+ (val = get(key)) ? MultiJson.load(val) : set(key, yield)
27
27
  )
28
28
  end
29
29
 
@@ -36,7 +36,7 @@ module GCoder
36
36
 
37
37
  def set(key, value)
38
38
  return value unless @conn
39
- @conn.set(key, Yajl::Encoder.encode(value))
39
+ @conn.set(key, MultiJson.dump(value))
40
40
  value
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module GCoder
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/gcoder.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'yajl'
1
+ require 'multi_json'
2
2
  require 'hashie'
3
3
  require 'net/http'
4
4
  require 'cgi'
@@ -16,12 +16,13 @@ require 'gcoder/storage'
16
16
  require 'gcoder/resolver'
17
17
 
18
18
  module GCoder
19
- class NoResultsError < StandardError; end
20
- class OverLimitError < StandardError; end
21
- class GeocoderError < StandardError; end
22
- class BadQueryError < StandardError; end
23
- class NotImplementedError < StandardError; end
24
- class TimeoutError < StandardError; end
19
+ class Error < StandardError; end
20
+ class NoResultsError < Error; end
21
+ class OverLimitError < Error; end
22
+ class GeocoderError < Error; end
23
+ class BadQueryError < Error; end
24
+ class NotImplementedError < Error; end
25
+ class TimeoutError < Error; end
25
26
 
26
27
  DEFAULT_CONFIG = {
27
28
  :timeout => 5,
@@ -3,44 +3,44 @@ require 'spec_helper'
3
3
 
4
4
  describe GCoder::Geocoder::Request do
5
5
  it 'should raise an error when passed nil' do
6
- -> {
6
+ lambda {
7
7
  GCoder::Geocoder::Request.new(nil)
8
8
  }.must_raise GCoder::BadQueryError
9
9
  end
10
10
 
11
11
  it 'should raise an error when passed a blank string' do
12
- -> {
12
+ lambda {
13
13
  GCoder::Geocoder::Request.new(' ')
14
14
  }.must_raise GCoder::BadQueryError
15
15
  end
16
16
 
17
17
  it 'should raise an error when passed incorrect lat/lng pair' do
18
18
  GCoder::Geocoder::Request.tap do |req|
19
- -> { req.new([]) }.must_raise GCoder::BadQueryError
20
- -> { req.new([43.64]) }.must_raise GCoder::BadQueryError
21
- -> { req.new([43.64, nil]) }.must_raise GCoder::BadQueryError
22
- -> { req.new(['', 43.64]) }.must_raise GCoder::BadQueryError
19
+ lambda { req.new([]) }.must_raise GCoder::BadQueryError
20
+ lambda { req.new([43.64]) }.must_raise GCoder::BadQueryError
21
+ lambda { req.new([43.64, nil]) }.must_raise GCoder::BadQueryError
22
+ lambda { req.new(['', 43.64]) }.must_raise GCoder::BadQueryError
23
23
  end
24
24
  end
25
25
 
26
26
  it 'should URI encode a string' do
27
27
  q = GCoder::Geocoder::Request.to_query(:q => 'hello world', :a => 'test')
28
- q.must_equal 'q=hello+world&a=test'
28
+ q.must_equal 'a=test&q=hello+world'
29
29
  end
30
30
 
31
31
  it 'should URI encode a string with ampersands' do
32
32
  q = GCoder::Geocoder::Request.to_query(:q => 'hello & world', :a => 'test')
33
- q.must_equal 'q=hello+%26+world&a=test'
33
+ q.must_equal 'a=test&q=hello+%26+world'
34
34
  end
35
35
 
36
36
  it 'should URI encode a UTF-8 string' do
37
37
  q = GCoder::Geocoder::Request.to_query(:q => 'मुंबई', :a => 'test')
38
- q.must_equal 'q=%E0%A4%AE%E0%A5%81%E0%A4%82%E0%A4%AC%E0%A4%88&a=test'
38
+ q.must_equal 'a=test&q=%E0%A4%AE%E0%A5%81%E0%A4%82%E0%A4%AC%E0%A4%88'
39
39
  end
40
40
 
41
41
  it 'should create a query string' do
42
42
  q = GCoder::Geocoder::Request.to_query(:q => 'hello world', :a => 'test')
43
- q.must_equal 'q=hello+world&a=test'
43
+ q.must_equal 'a=test&q=hello+world'
44
44
  end
45
45
 
46
46
  it '(when passed a bounds option) should generate correct query params' do
@@ -65,7 +65,7 @@ describe GCoder::Geocoder::Request do
65
65
 
66
66
  it "(when passed a premier client and key) should generate correct query params" do
67
67
  q = GCoder::Geocoder::Request.new('los angeles', :client => "gme-test", :key => "zNf23lb-YIoD4kEFN34C6324cww=").path
68
- q.must_equal '/maps/api/geocode/json?sensor=false&address=los+angeles&client=gme-test&signature=owxOUlItGsYUp-iEPw6n1S06TSc='
68
+ q.must_equal '/maps/api/geocode/json?address=los+angeles&client=gme-test&sensor=false&signature=vzm0saCgyMirMQJqFGHgGaoADhU='
69
69
  end
70
70
 
71
71
  end
@@ -22,26 +22,26 @@ describe 'GCoder::Resolver (with caching)' do
22
22
  end
23
23
 
24
24
  it 'should raise an error for queries with no results' do
25
- -> { @g['noresults', :region => nil] }.must_raise GCoder::NoResultsError
25
+ lambda { @g.geocode('noresults', :region => nil) }.must_raise GCoder::NoResultsError
26
26
  end
27
27
 
28
28
  it 'should raise an error for denied queries' do
29
- -> { @g['denied', :region => nil] }.must_raise GCoder::GeocoderError
29
+ lambda { @g.geocode('denied', :region => nil) }.must_raise GCoder::GeocoderError
30
30
  end
31
31
 
32
32
  it 'should raise an error when the query limit is exceeded' do
33
- -> { @g['overlimit', :region => nil] }.must_raise GCoder::OverLimitError
33
+ lambda { @g.geocode('overlimit', :region => nil) }.must_raise GCoder::OverLimitError
34
34
  end
35
35
 
36
36
  it 'should raise an error when the request is invalid' do
37
- -> { @g['denied', :region => nil] }.must_raise GCoder::GeocoderError
37
+ lambda { @g.geocode('denied', :region => nil) }.must_raise GCoder::GeocoderError
38
38
  end
39
39
  end
40
40
 
41
41
  describe 'GCoder::Resolver (without caching)' do
42
42
  it 'should resolve queries' do
43
43
  g = GCoder.connect(:storage => nil)
44
- r = g['queen and spadina', :region => :ca]
44
+ r = g.geocode('queen and spadina', :region => :ca)
45
45
  r.must_be_instance_of Array
46
46
  end
47
47
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe GCoder::Storage::Adapter do
4
4
  it 'shoyld raise an error if instantiated directly' do
5
- -> { GCoder::Storage::Adapter.new }.must_raise GCoder::NotImplementedError
5
+ lambda { GCoder::Storage::Adapter.new }.must_raise GCoder::NotImplementedError
6
6
  end
7
7
  end
8
8
 
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  - :file: 1.json
3
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=queen+and+spadina&region=ca
3
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?address=queen+and+spadina&region=ca&sensor=false
4
4
 
5
5
  - :file: 2.json
6
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=43.6487606%2C-79.3962415
6
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?latlng=43.6487606%2C-79.3962415&sensor=false
7
7
 
8
8
  - :file: 3.json
9
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=noresults
9
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?address=noresults&sensor=false
10
10
 
11
11
  - :file: 4.json
12
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=denied
12
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?address=denied&sensor=false
13
13
 
14
14
  - :file: 5.json
15
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=overlimit
15
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?address=overlimit&sensor=false
16
16
 
17
17
  - :file: 6.json
18
- :uri: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=invalid
18
+ :uri: http://maps.googleapis.com/maps/api/geocode/json?address=invalid&sensor=false
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Carsten Nielsen
9
9
  - Christos Pappas
10
+ - GUI
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2012-02-13 00:00:00.000000000 Z
14
+ date: 2012-10-23 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: hashie
17
- requirement: &70138928847000 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ! '>='
@@ -22,10 +23,15 @@ dependencies:
22
23
  version: '0'
23
24
  type: :runtime
24
25
  prerelease: false
25
- version_requirements: *70138928847000
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
26
32
  - !ruby/object:Gem::Dependency
27
- name: yajl-ruby
28
- requirement: &70138928846580 !ruby/object:Gem::Requirement
33
+ name: multi_json
34
+ requirement: !ruby/object:Gem::Requirement
29
35
  none: false
30
36
  requirements:
31
37
  - - ! '>='
@@ -33,10 +39,15 @@ dependencies:
33
39
  version: '0'
34
40
  type: :runtime
35
41
  prerelease: false
36
- version_requirements: *70138928846580
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: ruby-hmac
39
- requirement: &70138928846160 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,21 +55,47 @@ dependencies:
44
55
  version: '0'
45
56
  type: :runtime
46
57
  prerelease: false
47
- version_requirements: *70138928846160
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
48
64
  - !ruby/object:Gem::Dependency
49
65
  name: bundler
50
- requirement: &70138928845660 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
51
67
  none: false
52
68
  requirements:
53
69
  - - ! '>='
54
70
  - !ruby/object:Gem::Version
55
- version: 1.0.14
71
+ version: '0'
56
72
  type: :development
57
73
  prerelease: false
58
- version_requirements: *70138928845660
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: minitest
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
59
96
  - !ruby/object:Gem::Dependency
60
97
  name: redis
61
- requirement: &70138928845240 !ruby/object:Gem::Requirement
98
+ requirement: !ruby/object:Gem::Requirement
62
99
  none: false
63
100
  requirements:
64
101
  - - ! '>='
@@ -66,7 +103,12 @@ dependencies:
66
103
  version: '0'
67
104
  type: :development
68
105
  prerelease: false
69
- version_requirements: *70138928845240
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
70
112
  description: ! 'Uses Google Maps Geocoding API (V3) to geocode stuff and optionally
71
113
  caches the
72
114
 
@@ -115,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
157
  version: '0'
116
158
  segments:
117
159
  - 0
118
- hash: -1108805213569123765
160
+ hash: 629522719236126165
119
161
  required_rubygems_version: !ruby/object:Gem::Requirement
120
162
  none: false
121
163
  requirements:
@@ -124,10 +166,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
166
  version: '0'
125
167
  segments:
126
168
  - 0
127
- hash: -1108805213569123765
169
+ hash: 629522719236126165
128
170
  requirements: []
129
171
  rubyforge_project: gcoder
130
- rubygems_version: 1.8.10
172
+ rubygems_version: 1.8.24
131
173
  signing_key:
132
174
  specification_version: 3
133
175
  summary: A nice library for geocoding stuff with Google Maps API V3