gcoder 0.12.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Carsten Nielsen
1
+ Copyright (c) 2012 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/README.md CHANGED
@@ -161,9 +161,4 @@ G = GCoder.connect \
161
161
  * Carsten Nielsen
162
162
  * Christos Pappas (Added support for Google Maps API Premier and Rails.cache
163
163
  adapter.)
164
-
165
- ## Notes
166
-
167
- Tested with Ruby 1.9.2 (MRI) and nothing else, fork it. See
168
- [LICENSE](http://github.com/heycarsten/gcoder/blob/master/LICENSE) for details
169
- about that jazz.
164
+ * [GUI](http://github.com/GUI) (Ruby 1.8.7 compatibility, URI encoding fixes.)
@@ -5,9 +5,10 @@ module GCoder
5
5
  PATH = '/maps/api/geocode/json'
6
6
 
7
7
  class Request
8
-
9
8
  def self.to_query(params)
10
- URI.escape(params.map { |key, val| "#{key}=#{val}" }.join('&'))
9
+ params.map { |key, val|
10
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}"
11
+ }.join('&')
11
12
  end
12
13
 
13
14
  def self.stubs
@@ -25,17 +26,19 @@ module GCoder
25
26
 
26
27
  def params
27
28
  p = { :sensor => 'false' }
28
- p[:address] = address if @address
29
- p[:latlng] = latlng if @latlng
30
- p[:language] = @config[:language] if @config[:language]
31
- p[:region] = @config[:region] if @config[:region]
32
- p[:bounds] = bounds if @config[:bounds]
33
- 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]
34
35
  p
35
36
  end
36
37
 
37
38
  def path
38
- "#{PATH}?#{self.class.to_query(params)}#{"&signature=#{sign_key(@config[:key])}" if @config[:key]}"
39
+ str = "#{PATH}?#{self.class.to_query(params)}"
40
+ str << "&signature=#{sign_key(@config[:key])}" if @config[:key]
41
+ str
39
42
  end
40
43
 
41
44
  def uri
@@ -92,7 +95,7 @@ module GCoder
92
95
  def address
93
96
  @config[:append] ? "#{@address} #{@config[:append]}" : @address
94
97
  end
95
-
98
+
96
99
  def url_safe_base64_decode(string)
97
100
  return Base64.decode64(string.tr('-_','+/')).gsub(/\n/,'')
98
101
  end
@@ -100,13 +103,12 @@ module GCoder
100
103
  def url_safe_base64_encode(raw)
101
104
  return Base64.encode64(raw).tr('+/','-_').gsub(/\n/,'')
102
105
  end
103
-
106
+
104
107
  def sign_key(key)
105
108
  sha1 = HMAC::SHA1.new(url_safe_base64_decode(key))
106
109
  sha1 << "#{PATH}?#{self.class.to_query(params)}"
107
110
  raw_signature = sha1.digest()
108
-
109
- url_safe_base64_encode(raw_signature)
111
+ url_safe_base64_encode(raw_signature)
110
112
  end
111
113
  end
112
114
 
@@ -1,3 +1,3 @@
1
1
  module GCoder
2
- VERSION = '0.12.1'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/gcoder.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'yajl'
2
2
  require 'hashie'
3
3
  require 'net/http'
4
- require 'uri'
4
+ require 'cgi'
5
5
  require 'base64'
6
6
  require 'timeout'
7
7
  require 'digest/sha1'
@@ -25,7 +25,12 @@ describe GCoder::Geocoder::Request do
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%20world&a=test'
28
+ q.must_equal 'q=hello+world&a=test'
29
+ end
30
+
31
+ it 'should URI encode a string with ampersands' do
32
+ q = GCoder::Geocoder::Request.to_query(:q => 'hello & world', :a => 'test')
33
+ q.must_equal 'q=hello+%26+world&a=test'
29
34
  end
30
35
 
31
36
  it 'should URI encode a UTF-8 string' do
@@ -35,7 +40,7 @@ describe GCoder::Geocoder::Request do
35
40
 
36
41
  it 'should create a query string' do
37
42
  q = GCoder::Geocoder::Request.to_query(:q => 'hello world', :a => 'test')
38
- q.must_equal 'q=hello%20world&a=test'
43
+ q.must_equal 'q=hello+world&a=test'
39
44
  end
40
45
 
41
46
  it '(when passed a bounds option) should generate correct query params' do
@@ -60,7 +65,7 @@ describe GCoder::Geocoder::Request do
60
65
 
61
66
  it "(when passed a premier client and key) should generate correct query params" do
62
67
  q = GCoder::Geocoder::Request.new('los angeles', :client => "gme-test", :key => "zNf23lb-YIoD4kEFN34C6324cww=").path
63
- q.must_equal '/maps/api/geocode/json?sensor=false&address=los%20angeles&client=gme-test&signature=p0EiRD298eLhlGTqlBA5RKxv448='
68
+ q.must_equal '/maps/api/geocode/json?sensor=false&address=los+angeles&client=gme-test&signature=owxOUlItGsYUp-iEPw6n1S06TSc='
64
69
  end
65
70
 
66
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-04 00:00:00.000000000Z
13
+ date: 2012-02-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hashie
17
- requirement: &70147457520440 !ruby/object:Gem::Requirement
17
+ requirement: &70138928847000 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70147457520440
25
+ version_requirements: *70138928847000
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: yajl-ruby
28
- requirement: &70147457519540 !ruby/object:Gem::Requirement
28
+ requirement: &70138928846580 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70147457519540
36
+ version_requirements: *70138928846580
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: ruby-hmac
39
- requirement: &70147457518700 !ruby/object:Gem::Requirement
39
+ requirement: &70138928846160 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70147457518700
47
+ version_requirements: *70138928846160
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &70147457455060 !ruby/object:Gem::Requirement
50
+ requirement: &70138928845660 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.14
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70147457455060
58
+ version_requirements: *70138928845660
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: redis
61
- requirement: &70147457454080 !ruby/object:Gem::Requirement
61
+ requirement: &70138928845240 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70147457454080
69
+ version_requirements: *70138928845240
70
70
  description: ! 'Uses Google Maps Geocoding API (V3) to geocode stuff and optionally
71
71
  caches the
72
72
 
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: 3722071626544291887
118
+ hash: -1108805213569123765
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements:
@@ -124,10 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: 3722071626544291887
127
+ hash: -1108805213569123765
128
128
  requirements: []
129
129
  rubyforge_project: gcoder
130
- rubygems_version: 1.8.6
130
+ rubygems_version: 1.8.10
131
131
  signing_key:
132
132
  specification_version: 3
133
133
  summary: A nice library for geocoding stuff with Google Maps API V3