google_places_autocomplete 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -2
- data/lib/google_places_autocomplete/client.rb +29 -4
- data/lib/google_places_autocomplete/version.rb +1 -1
- data/spec/google_places_autocomplete/client_spec.rb +12 -1
- data/spec/vcr_cassettes/location_bias.yml +94 -0
- data/spec/vcr_cassettes/with_bounds.yml +1 -33
- metadata +80 -99
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1153f39abf06e25482df161fabbdddd972a457a3
|
4
|
+
data.tar.gz: 744cd51a0752a0fe36e1842dc6a42bfa7a823265
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6432c5874085254f78d7bb259e2c998c63edee6d2581a099d6598c2e65ec23955f6539921c9bef6a0e51c20015971f9bfe01cd50450dfe3306109455b0bfbe7
|
7
|
+
data.tar.gz: 731a60077967cb2f2d801a3dc4e3d991578fd8fa73340adac254e12e35cb5a9c39fa73ccda1d911d2261d7c846827106c5b7bfb9447dd6de0eaa31656b398136
|
data/README.md
CHANGED
@@ -4,12 +4,13 @@ Ruby wrapper for the [Google Places Autocomplete API](http://code.google.com/api
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Inside your Gemfile:
|
7
|
+
Inside your Gemfile:
|
8
8
|
gem 'google_places_autocomplete'
|
9
9
|
|
10
10
|
## Get Google Places API credentials
|
11
11
|
|
12
|
-
Go here and activate it:
|
12
|
+
Go here and activate it:
|
13
|
+
[https://code.google.com/apis/console](https://code.google.com/apis/console)
|
13
14
|
|
14
15
|
## Usage
|
15
16
|
|
@@ -2,7 +2,7 @@ module GooglePlacesAutocomplete
|
|
2
2
|
|
3
3
|
class Client
|
4
4
|
include HTTParty
|
5
|
-
base_uri "https://maps.googleapis.com/maps/api/place
|
5
|
+
base_uri "https://maps.googleapis.com/maps/api/place"
|
6
6
|
format :json
|
7
7
|
|
8
8
|
attr_reader :api_key
|
@@ -14,6 +14,7 @@ module GooglePlacesAutocomplete
|
|
14
14
|
def autocomplete(options={})
|
15
15
|
sensor = options.delete(:sensor) || false
|
16
16
|
types = options.delete(:types)
|
17
|
+
language = options.delete(:language) || nil
|
17
18
|
input = options.delete(:input)
|
18
19
|
offset = options.delete(:offset) || nil
|
19
20
|
radius = options.delete(:radius) || nil
|
@@ -23,14 +24,21 @@ module GooglePlacesAutocomplete
|
|
23
24
|
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
25
|
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
26
|
bounds = [sw_bounds,ne_bounds].join('|') if sw_bounds && ne_bounds
|
26
|
-
|
27
|
+
components = options.delete(:components) || nil
|
28
|
+
user_ip = options.delete(:user_ip) || nil
|
29
|
+
quota_user = options.delete(:quota_user) || nil
|
30
|
+
|
27
31
|
options = {
|
28
32
|
:location => location,
|
29
33
|
:radius => radius,
|
34
|
+
:language => language,
|
30
35
|
:sensor => sensor,
|
31
36
|
:input => input,
|
32
37
|
:offset => offset,
|
33
|
-
:bounds => bounds
|
38
|
+
:bounds => bounds,
|
39
|
+
:components => components,
|
40
|
+
:userIp => user_ip,
|
41
|
+
:quotaUser => quota_user
|
34
42
|
}
|
35
43
|
|
36
44
|
if types
|
@@ -39,7 +47,24 @@ module GooglePlacesAutocomplete
|
|
39
47
|
end
|
40
48
|
|
41
49
|
options = options.delete_if {|key, value| value.nil?}
|
42
|
-
mashup(self.class.get("/json", :query => options.merge(self.default_options)))
|
50
|
+
mashup(self.class.get("/autocomplete/json", :query => options.merge(self.default_options)))
|
51
|
+
end
|
52
|
+
|
53
|
+
def details(options={})
|
54
|
+
placeid = options.delete(:placeid)
|
55
|
+
reference = options.delete(:reference)
|
56
|
+
|
57
|
+
if placeid
|
58
|
+
options = {
|
59
|
+
placeid: placeid
|
60
|
+
}
|
61
|
+
else
|
62
|
+
options = {
|
63
|
+
reference: reference
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
mashup(self.class.get("/details/json", :query => options.merge(self.default_options)))
|
43
68
|
end
|
44
69
|
|
45
70
|
protected
|
@@ -11,6 +11,17 @@ describe GooglePlacesAutocomplete::Client do
|
|
11
11
|
@client.api_key.should == "foobar"
|
12
12
|
end
|
13
13
|
|
14
|
+
context "request an autocomplete with location bias" do
|
15
|
+
use_vcr_cassette 'location_bias'
|
16
|
+
|
17
|
+
it 'should request autocomplete' do
|
18
|
+
@client = GooglePlacesAutocomplete::Client.new(:api_key => "foobar")
|
19
|
+
@autocomplete = @client.autocomplete(:lat => 40.606654, :lng => -74.036865, :input => "coffee", :types => "establishment", :radius => 50)
|
20
|
+
@autocomplete.predictions.size.should == 2
|
21
|
+
@autocomplete.predictions.first.description.should == "Narrows Coffee Shop, 4th Avenue, NY, United States"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
14
25
|
context "request an autocomplete" do
|
15
26
|
use_vcr_cassette 'autocomplete'
|
16
27
|
|
@@ -26,7 +37,7 @@ describe GooglePlacesAutocomplete::Client do
|
|
26
37
|
use_vcr_cassette 'with_bounds'
|
27
38
|
|
28
39
|
it 'should request autocomplete with bounds parameter' do
|
29
|
-
@client = GooglePlacesAutocomplete::Client.new(:api_key => "
|
40
|
+
@client = GooglePlacesAutocomplete::Client.new(:api_key => "foobar")
|
30
41
|
@autocomplete = @client.autocomplete(:input => "Peter Luger", :types => "establishment",
|
31
42
|
:sw_bounds => {:lat => 40.606654, :lng => -74.036865},
|
32
43
|
:ne_bounds => {:lat => 40.744655, :lng => -73.831558})
|
@@ -0,0 +1,94 @@
|
|
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?types=establishment&radius=50&input=coffee&location=40.606654%2C-74.036865&sensor=false&key=foobar
|
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
|
+
- Wed, 03 Aug 2011 15:22:32 GMT
|
15
|
+
content-type:
|
16
|
+
- application/json; charset=UTF-8
|
17
|
+
x-xss-protection:
|
18
|
+
- 1; mode=block
|
19
|
+
server:
|
20
|
+
- mafe
|
21
|
+
date:
|
22
|
+
- Wed, 03 Aug 2011 15:17:32 GMT
|
23
|
+
vary:
|
24
|
+
- Accept-Language
|
25
|
+
cache-control:
|
26
|
+
- public, max-age=300
|
27
|
+
body: |
|
28
|
+
{
|
29
|
+
"predictions" : [
|
30
|
+
{
|
31
|
+
"description" : "Narrows Coffee Shop, 4th Avenue, NY, United States",
|
32
|
+
"id" : "6f8e40d1101da10ec5c5499e3c068bd1d7288fb5",
|
33
|
+
"matched_substrings" : [
|
34
|
+
{
|
35
|
+
"length" : 6,
|
36
|
+
"offset" : 8
|
37
|
+
}
|
38
|
+
],
|
39
|
+
"reference" : "CnRqAAAAtpnfY9G9cesdyJhP3NTXGYXeslzB5QGKjtaewFbySFZ1Msq2sBS-UQNe4eW7KzVh8ZumBH9GOFx50kcnhpDAVbz9REmBAlQP73WNQ_mQZ-B1RvPzsEt5Y0zlqnO11eiZRbiY59nM-wUs0p9CdpeuARIQgpgtDIXrt_fvQF8ECnZzpRoUKWo9ed41KsvHU8iiL6BLo8aOJec",
|
40
|
+
"terms" : [
|
41
|
+
{
|
42
|
+
"offset" : 0,
|
43
|
+
"value" : "Narrows Coffee Shop"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"offset" : 21,
|
47
|
+
"value" : "4th Avenue"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"offset" : 33,
|
51
|
+
"value" : "NY"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"offset" : 37,
|
55
|
+
"value" : "United States"
|
56
|
+
}
|
57
|
+
],
|
58
|
+
"types" : [ "establishment" ]
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"description" : "Best Coffee Shop, 5th Avenue, NY, United States",
|
62
|
+
"id" : "422aa675b71e6ed07132170b0132fd5a66e836ba",
|
63
|
+
"matched_substrings" : [
|
64
|
+
{
|
65
|
+
"length" : 6,
|
66
|
+
"offset" : 5
|
67
|
+
}
|
68
|
+
],
|
69
|
+
"reference" : "CnRnAAAAtLEJZvWFn4VgfohDDwjQtb3qTC8Q6tR7HnBKrb8ihonIrYItxP4Be9Em58rLwvDLV_3beNgeAw8Fpg-bbWbdmcQljuXTJwJ_6DIegAH_NqSF2ZbXtyBNasCzpbYulpryIo0YAHIbzlcdzsHtwUVu8hIQ33zYNA06DMb8_mu3s4i8OBoUpQz0fFevpg0CraJYRQ6FNAo5nCs",
|
70
|
+
"terms" : [
|
71
|
+
{
|
72
|
+
"offset" : 0,
|
73
|
+
"value" : "Best Coffee Shop"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"offset" : 18,
|
77
|
+
"value" : "5th Avenue"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"offset" : 30,
|
81
|
+
"value" : "NY"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"offset" : 34,
|
85
|
+
"value" : "United States"
|
86
|
+
}
|
87
|
+
],
|
88
|
+
"types" : [ "establishment" ]
|
89
|
+
}
|
90
|
+
],
|
91
|
+
"status" : "OK"
|
92
|
+
}
|
93
|
+
|
94
|
+
http_version: "1.1"
|
@@ -2,39 +2,7 @@
|
|
2
2
|
- !ruby/struct:VCR::HTTPInteraction
|
3
3
|
request: !ruby/struct:VCR::Request
|
4
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&
|
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
|
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&sensor=false&types=establishment&key=foobar
|
38
6
|
body:
|
39
7
|
headers:
|
40
8
|
response: !ruby/struct:VCR::Response
|
metadata
CHANGED
@@ -1,103 +1,93 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_places_autocomplete
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Johnny Khai Nguyen
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: httparty
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
33
20
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: hashie
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
47
34
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rspec
|
51
35
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
55
45
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
61
48
|
type: :development
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: fakeweb
|
65
49
|
prerelease: false
|
66
|
-
|
67
|
-
|
68
|
-
requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
69
52
|
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakeweb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
75
62
|
type: :development
|
76
|
-
version_requirements: *id004
|
77
|
-
- !ruby/object:Gem::Dependency
|
78
|
-
name: vcr
|
79
63
|
prerelease: false
|
80
|
-
|
81
|
-
|
82
|
-
requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
83
66
|
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
89
76
|
type: :development
|
90
|
-
|
91
|
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Use this gem to access the Google Places Autocomplete API from your Ruby
|
84
|
+
application
|
92
85
|
email: johnnyn@gmail.com
|
93
86
|
executables: []
|
94
|
-
|
95
87
|
extensions: []
|
96
|
-
|
97
88
|
extra_rdoc_files: []
|
98
|
-
|
99
|
-
|
100
|
-
- .gitignore
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
101
91
|
- Gemfile
|
102
92
|
- README.md
|
103
93
|
- Rakefile
|
@@ -108,45 +98,36 @@ files:
|
|
108
98
|
- spec/google_places_autocomplete/client_spec.rb
|
109
99
|
- spec/spec_helper.rb
|
110
100
|
- spec/vcr_cassettes/autocomplete.yml
|
101
|
+
- spec/vcr_cassettes/location_bias.yml
|
111
102
|
- spec/vcr_cassettes/with_bounds.yml
|
112
103
|
- spec/vcr_setup.rb
|
113
|
-
has_rdoc: true
|
114
104
|
homepage: http://github.com/phuphighter/google_places_autocomplete
|
115
105
|
licenses: []
|
116
|
-
|
106
|
+
metadata: {}
|
117
107
|
post_install_message:
|
118
108
|
rdoc_options: []
|
119
|
-
|
120
|
-
require_paths:
|
109
|
+
require_paths:
|
121
110
|
- lib
|
122
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
|
124
|
-
requirements:
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
125
113
|
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
version: "0"
|
131
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
|
-
requirements:
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
134
118
|
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
version: "0"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
140
121
|
requirements: []
|
141
|
-
|
142
122
|
rubyforge_project: google_places_autocomplete
|
143
|
-
rubygems_version:
|
123
|
+
rubygems_version: 2.2.2
|
144
124
|
signing_key:
|
145
|
-
specification_version:
|
125
|
+
specification_version: 4
|
146
126
|
summary: Ruby wrapper for the Google Places Autocomplete API
|
147
|
-
test_files:
|
127
|
+
test_files:
|
148
128
|
- spec/google_places_autocomplete/client_spec.rb
|
149
129
|
- spec/spec_helper.rb
|
150
130
|
- spec/vcr_cassettes/autocomplete.yml
|
131
|
+
- spec/vcr_cassettes/location_bias.yml
|
151
132
|
- spec/vcr_cassettes/with_bounds.yml
|
152
133
|
- spec/vcr_setup.rb
|