google_places_autocomplete 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,8 +12,34 @@ module GooglePlacesAutocomplete
12
12
  end
13
13
 
14
14
  def autocomplete(options={})
15
- query = options.merge(self.default_options)
16
- mashup(self.class.get("/json", :query => query))
15
+ sensor = options.delete(:sensor) || false
16
+ types = options.delete(:types)
17
+ input = options.delete(:input)
18
+ offset = options.delete(:offset) || nil
19
+ radius = options.delete(:radius) || nil
20
+ lat = options.delete(:lat) || nil
21
+ lng = options.delete(:lng) || nil
22
+ location = [lat,lng].join(',') if lat && lng
23
+ sw_bounds = [options[:sw_bounds].delete(:lat),options[:sw_bounds].delete(:lng)].join(',') if options[:sw_bounds] && options[:sw_bounds][:lat] && options[:sw_bounds][:lng]
24
+ ne_bounds = [options[:ne_bounds].delete(:lat),options[:ne_bounds].delete(:lng)].join(',') if options[:ne_bounds] && options[:ne_bounds][:lat] && options[:ne_bounds][:lng]
25
+ bounds = [sw_bounds,ne_bounds].join('|') if sw_bounds && ne_bounds
26
+
27
+ options = {
28
+ :location => location,
29
+ :radius => radius,
30
+ :sensor => sensor,
31
+ :input => input,
32
+ :offset => offset,
33
+ :bounds => bounds
34
+ }
35
+
36
+ if types
37
+ types = (types.is_a?(Array) ? types.join('|') : types)
38
+ options.merge!(:types => types)
39
+ end
40
+
41
+ options = options.delete_if {|key, value| value.nil?}
42
+ mashup(self.class.get("/json", :query => options.merge(self.default_options)))
17
43
  end
18
44
 
19
45
  protected
@@ -1,3 +1,3 @@
1
1
  module GooglePlacesAutocomplete
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GooglePlacesAutocomplete::Client do
4
- use_vcr_cassette 'autocomplete'
5
4
 
6
5
  it 'should not initialize without an api_key' do
7
6
  lambda { GooglePlacesAutocomplete::Client.new }.should raise_error
@@ -11,11 +10,28 @@ describe GooglePlacesAutocomplete::Client do
11
10
  @client = GooglePlacesAutocomplete::Client.new(:api_key => "foobar")
12
11
  @client.api_key.should == "foobar"
13
12
  end
13
+
14
+ context "request an autocomplete" do
15
+ use_vcr_cassette 'autocomplete'
14
16
 
15
- it 'should request autocomplete' do
16
- @client = GooglePlacesAutocomplete::Client.new(:api_key => "foobar")
17
- @autocomplete = @client.autocomplete(:input => "Paris", :types => "geocode")
18
- @autocomplete.predictions.size.should == 5
19
- @autocomplete.predictions.first.description.should == 'Paris, France'
17
+ it 'should request autocomplete' do
18
+ @client = GooglePlacesAutocomplete::Client.new(:api_key => "foobar")
19
+ @autocomplete = @client.autocomplete(:input => "Paris", :types => "geocode")
20
+ @autocomplete.predictions.size.should == 5
21
+ @autocomplete.predictions.first.description.should == 'Paris, France'
22
+ end
23
+ end
24
+
25
+ context "request an autocomplete with bounds" do
26
+ use_vcr_cassette 'with_bounds'
27
+
28
+ it 'should request autocomplete with bounds parameter' do
29
+ @client = GooglePlacesAutocomplete::Client.new(:api_key => "AIzaSyA8TtA11BlJ1XWlMisoboZvjk24xHgHwX0")
30
+ @autocomplete = @client.autocomplete(:input => "Peter Luger", :types => "establishment",
31
+ :sw_bounds => {:lat => 40.606654, :lng => -74.036865},
32
+ :ne_bounds => {:lat => 40.744655, :lng => -73.831558})
33
+
34
+ @autocomplete.predictions.size.should == 0
35
+ end
20
36
  end
21
37
  end
@@ -12,16 +12,16 @@
12
12
  headers:
13
13
  content-type:
14
14
  - application/json; charset=UTF-8
15
- date:
16
- - Thu, 02 Jun 2011 08:17:49 GMT
17
- server:
18
- - mafe
19
15
  x-xss-protection:
20
16
  - 1; mode=block
21
- vary:
22
- - Accept-Language
17
+ server:
18
+ - mafe
19
+ date:
20
+ - Thu, 02 Jun 2011 08:17:49 GMT
23
21
  cache-control:
24
22
  - private
23
+ vary:
24
+ - Accept-Language
25
25
  body: |
26
26
  {
27
27
  "predictions" : [
@@ -156,33 +156,3 @@
156
156
  }
157
157
 
158
158
  http_version: "1.1"
159
- - !ruby/struct:VCR::HTTPInteraction
160
- request: !ruby/struct:VCR::Request
161
- method: :get
162
- uri: https://maps.googleapis.com:443/maps/api/place/autocomplete/json?types=geocode&input=Paris&sensor=false&key=foobar
163
- body:
164
- headers:
165
- response: !ruby/struct:VCR::Response
166
- status: !ruby/struct:VCR::ResponseStatus
167
- code: 200
168
- message: OK
169
- headers:
170
- content-type:
171
- - application/json; charset=UTF-8
172
- x-xss-protection:
173
- - 1; mode=block
174
- server:
175
- - mafe
176
- date:
177
- - Fri, 03 Jun 2011 01:41:55 GMT
178
- cache-control:
179
- - private
180
- vary:
181
- - Accept-Language
182
- body: |
183
- {
184
- "predictions" : [],
185
- "status" : "REQUEST_DENIED"
186
- }
187
-
188
- http_version: "1.1"
@@ -0,0 +1,65 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://maps.googleapis.com:443/maps/api/place/autocomplete/json?bounds=40.606654%2C-74.036865%7C40.744655%2C-73.831558&input=Peter%20Luger&location=%2C&sensor=false&types=establishment&key=AIzaSyA8TtA11BlJ1XWlMisoboZvjk24xHgHwX0
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ expires:
14
+ - Mon, 06 Jun 2011 02:44:11 GMT
15
+ content-type:
16
+ - application/json; charset=UTF-8
17
+ date:
18
+ - Mon, 06 Jun 2011 02:39:11 GMT
19
+ server:
20
+ - mafe
21
+ x-xss-protection:
22
+ - 1; mode=block
23
+ cache-control:
24
+ - public, max-age=300
25
+ vary:
26
+ - Accept-Language
27
+ body: |
28
+ {
29
+ "predictions" : [],
30
+ "status" : "ZERO_RESULTS"
31
+ }
32
+
33
+ http_version: "1.1"
34
+ - !ruby/struct:VCR::HTTPInteraction
35
+ request: !ruby/struct:VCR::Request
36
+ method: :get
37
+ uri: https://maps.googleapis.com:443/maps/api/place/autocomplete/json?bounds=40.606654%2C-74.036865%7C40.744655%2C-73.831558&input=Peter%20Luger&sensor=false&types=establishment&key=AIzaSyA8TtA11BlJ1XWlMisoboZvjk24xHgHwX0
38
+ body:
39
+ headers:
40
+ response: !ruby/struct:VCR::Response
41
+ status: !ruby/struct:VCR::ResponseStatus
42
+ code: 200
43
+ message: OK
44
+ headers:
45
+ expires:
46
+ - Mon, 06 Jun 2011 02:57:39 GMT
47
+ content-type:
48
+ - application/json; charset=UTF-8
49
+ x-xss-protection:
50
+ - 1; mode=block
51
+ server:
52
+ - mafe
53
+ date:
54
+ - Mon, 06 Jun 2011 02:52:39 GMT
55
+ vary:
56
+ - Accept-Language
57
+ cache-control:
58
+ - public, max-age=300
59
+ body: |
60
+ {
61
+ "predictions" : [],
62
+ "status" : "ZERO_RESULTS"
63
+ }
64
+
65
+ http_version: "1.1"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_places_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Johnny Khai Nguyen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-02 00:00:00 -05:00
18
+ date: 2011-06-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -108,6 +108,7 @@ files:
108
108
  - spec/google_places_autocomplete/client_spec.rb
109
109
  - spec/spec_helper.rb
110
110
  - spec/vcr_cassettes/autocomplete.yml
111
+ - spec/vcr_cassettes/with_bounds.yml
111
112
  - spec/vcr_setup.rb
112
113
  has_rdoc: true
113
114
  homepage: http://github.com/phuphighter/google_places_autocomplete
@@ -147,4 +148,5 @@ test_files:
147
148
  - spec/google_places_autocomplete/client_spec.rb
148
149
  - spec/spec_helper.rb
149
150
  - spec/vcr_cassettes/autocomplete.yml
151
+ - spec/vcr_cassettes/with_bounds.yml
150
152
  - spec/vcr_setup.rb