google_places 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 749f35ddb5c9ce15000ca1d2b3aecb6154d2c227
4
- data.tar.gz: dc73e83a3d8d21d9fa11e61c155e5aae827f80dc
2
+ SHA256:
3
+ metadata.gz: 7ef64d115e171e95f7bfb5d9fbc65a7ad8a70055e341e618dd9289d7bec31254
4
+ data.tar.gz: fef848705c73ccf177f7c97400436c9ca20f3dfec579cfa05f25c583fd0ec6fe
5
5
  SHA512:
6
- metadata.gz: 2b3f62a1f9298f31581e3590f69593160cc5e4ef7841014f1b91ab2a5957e1a16b6451b900cc02cd7c573f09e8a8599e5625966e37db923c2fa8da6261496085
7
- data.tar.gz: 1f701b72843382e71d22f39b1f32761232d0b6ed0b5541c01177b2a88f6ec827c1f19ed3addf78c94f0592afc498dadb87ce1f788b02675469db69a632d96f70
6
+ metadata.gz: 7b558547b58dc4d26a8cfc306694c2b9e94a8b3bb9be8f1d908c6daa00aaf130e8df5bde7711b2555719bbb0bad0781709b2394168a157e6e785f6b8551a1e9b
7
+ data.tar.gz: ec44110e4b2bdd04fa86a24ab34d947dd400c3f4d507333ee20704b8c000ef2a841e6cb34baa10c1e67fafa203f5dd7e1252fedcb91ac8b3e59cd8646b91427f
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.3
4
- - 2.2.5
5
- - 2.3.1
3
+ - 2.4.6
4
+ - 2.5.5
5
+ - 2.6.3
6
6
  script: bundle exec rspec
7
7
  before_script: cp spec/api_key.travis.rb spec/api_key.rb
8
8
  after_script: rm spec/api_key.rb
9
9
  before_install:
10
- - gem install bundler -v 1.14.6
10
+ - gem install bundler -v 1.17
@@ -1,3 +1,11 @@
1
+ ## 2.0.0
2
+ ### Breaking Changes for 2.0.0:
3
+ - Removed the `spots_by_radar` method
4
+ - Remove support for all unsupported versions of Ruby (< 2.4)
5
+
6
+ ### Added
7
+ - Expose the `json_result_object` field on a Spot object
8
+
1
9
  ## 1.2.0
2
10
  ### Added
3
11
  - Add a region option to the `spots` and `spots_by_query` methods
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_places (1.2.0)
4
+ google_places (2.0.0)
5
5
  httparty (>= 0.13.1)
6
6
 
7
7
  GEM
@@ -46,4 +46,4 @@ DEPENDENCIES
46
46
  webmock (~> 1.18)
47
47
 
48
48
  BUNDLED WITH
49
- 1.14.6
49
+ 1.17.2
@@ -7,9 +7,7 @@ not support OAuth authentication and will only work with an API key.
7
7
  == Obtaining an API key
8
8
 
9
9
  To be able to use this gem, you'll need a Google Places API key. To request an API key, point your browser to
10
- https://code.google.com/apis/console and follow the instructions there. You'll find your API key on the
11
- *API Access* tab under *Simple API Access*.
12
-
10
+ https://developers.google.com/places/web-service/get-api-key and follow the instructions there.
13
11
 
14
12
  == Installing the gem
15
13
 
@@ -44,6 +42,8 @@ However <tt>address_components</tt>, <tt>city</tt>, <tt>country</tt>, <tt>format
44
42
 
45
43
  * To get these values: You can use <tt>@client.spot(place_id)</tt>. This returns the complete information for the spot by making an extra API call per returned spot.
46
44
  * To get a collection of these detailed spots: You can use <tt>@client.spots(lat, lng, detail: true)</tt>. This makes an extra call per each spot and returns a collection of the detailed spots.
45
+ * To only retrieve specific fields for an individual spot, use a comma delimited string of acceptable fields <tt>@client.spot(place_id, fields:'place_id,name')</tt>
46
+
47
47
 
48
48
  === Retrieving a list of spots
49
49
 
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'google_places'
6
- s.version = '1.2.0'
6
+ s.version = '2.0.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Marcel de Graaf']
9
9
  s.email = ['mail@marceldegraaf.net']
@@ -235,7 +235,6 @@ module GooglePlaces
235
235
  )
236
236
  end
237
237
 
238
- # Radar Search Service allows you to search for up to 200 Places at once, but with less detail than is typically returned from a Text Search or Nearby Search request. The search response will include up to 200 Places, identified only by their geographic coordinates and reference. You can send a Place Details request for more information about any of them.
239
238
  #
240
239
  # @return [Array<Spot>]
241
240
  # @param [String,Integer] lat the latitude for the search
@@ -270,15 +269,6 @@ module GooglePlaces
270
269
  # A boolean to return spots with full detail information(its complete address, phone number, user rating, reviews, etc)
271
270
  # Note) This makes an extra call for each spot for more information.
272
271
  #
273
- # @see https://developers.google.com/places/documentation/search#RadarSearchRequests
274
- def spots_by_radar(lat, lng, options = {})
275
- options = @options.merge(options)
276
- detail = options.delete(:detail)
277
- collection_detail_level(
278
- Spot.list_by_radar(lat, lng, @api_key, options),
279
- detail
280
- )
281
- end
282
272
 
283
273
  # Query for Place Predictions
284
274
  #
@@ -318,8 +318,6 @@ module GooglePlaces
318
318
  retry_options[:status] = [retry_options[:status]] unless retry_options[:status].is_a?(Array)
319
319
  @response = self.class.get(url, :query => options, :follow_redirects => follow_redirects)
320
320
 
321
- # puts @response.request.last_uri.to_s
322
-
323
321
  return unless retry_options[:max] > 0 && retry_options[:status].include?(@response.parsed_response['status'])
324
322
 
325
323
  retry_request = proc do
@@ -1,7 +1,11 @@
1
1
  require 'google_places/review'
2
2
  module GooglePlaces
3
3
  class Spot
4
- attr_accessor :lat, :lng, :viewport, :name, :icon, :reference, :vicinity, :types, :id, :formatted_phone_number, :international_phone_number, :formatted_address, :address_components, :street_number, :street, :city, :region, :postal_code, :country, :rating, :url, :cid, :website, :reviews, :aspects, :zagat_selected, :zagat_reviewed, :photos, :review_summary, :nextpagetoken, :price_level, :opening_hours, :events, :utc_offset, :place_id, :permanently_closed
4
+ attr_accessor :lat, :lng, :viewport, :name, :icon, :reference, :vicinity, :types, :id, :formatted_phone_number,
5
+ :international_phone_number, :formatted_address, :address_components, :street_number, :street, :city, :region,
6
+ :postal_code, :country, :rating, :url, :cid, :website, :reviews, :aspects, :zagat_selected, :zagat_reviewed,
7
+ :photos, :review_summary, :nextpagetoken, :price_level, :opening_hours, :events, :utc_offset, :place_id, :permanently_closed,
8
+ :json_result_object
5
9
 
6
10
  # Search for Spots at the provided location
7
11
  #
@@ -249,6 +253,7 @@ module GooglePlaces
249
253
  # @option options [Integer] :retry_options[:max] (0) the maximum retries
250
254
  # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
251
255
  def self.find(place_id, api_key, options = {})
256
+ fields = options.delete(:fields)
252
257
  language = options.delete(:language)
253
258
  region = options.delete(:region)
254
259
  retry_options = options.delete(:retry_options) || {}
@@ -259,7 +264,8 @@ module GooglePlaces
259
264
  :key => api_key,
260
265
  :language => language,
261
266
  :extensions => extensions,
262
- :retry_options => retry_options
267
+ :retry_options => retry_options,
268
+ :fields => fields
263
269
  }
264
270
  request_options[:region] = region unless region.nil?
265
271
  response = Request.spot(request_options)
@@ -423,12 +429,13 @@ module GooglePlaces
423
429
  # @param [JSON] json_result_object a JSON object to create a Spot from
424
430
  # @return [Spot] a newly created spot
425
431
  def initialize(json_result_object, api_key)
432
+ @json_result_object = json_result_object
426
433
  @reference = json_result_object['reference']
427
434
  @place_id = json_result_object['place_id']
428
435
  @vicinity = json_result_object['vicinity']
429
- @lat = json_result_object['geometry']['location']['lat']
430
- @lng = json_result_object['geometry']['location']['lng']
431
- @viewport = json_result_object['geometry']['viewport']
436
+ @lat = json_result_object['geometry'] ? json_result_object['geometry']['location']['lat'] : nil
437
+ @lng = json_result_object['geometry'] ? json_result_object['geometry']['location']['lng'] : nil
438
+ @viewport = json_result_object['geometry'] ? json_result_object['geometry']['viewport'] : nil
432
439
  @name = json_result_object['name']
433
440
  @icon = json_result_object['icon']
434
441
  @types = json_result_object['types']
@@ -162,47 +162,6 @@ describe GooglePlaces::Client do
162
162
  end
163
163
  end
164
164
 
165
- describe '::spots_by_radar' do
166
- let(:keywords) { 'landmarks' }
167
- let(:lat) { '51.511627' }
168
- let(:lng) { '-0.183778' }
169
- let(:radius) { 5000 }
170
-
171
- it 'should request spots by radar' do
172
- expect(GooglePlaces::Spot).to receive(:list_by_radar).with(lat, lng, api_key, radius: radius, keyword: keywords)
173
- client.spots_by_radar(lat, lng, radius: radius, keyword: keywords)
174
- end
175
-
176
- it 'does not call find on GooglePlces::Spot' do
177
- allow(GooglePlaces::Spot).to receive(:list_by_radar) { [fake_spot] }
178
- expect(GooglePlaces::Spot).not_to receive(:find)
179
- client.spots_by_radar(lat, lng, radius: radius, keyword: keywords)
180
- end
181
-
182
- context 'with detail set to true' do
183
- it 'calls find on GooglePlaces::Spot' do
184
- allow(GooglePlaces::Spot).to receive(:list_by_radar) { [fake_spot] }
185
- expect(GooglePlaces::Spot).to receive(:find)
186
- client.spots_by_radar(
187
- lat,
188
- lng,
189
- radius: radius,
190
- keyword: keywords,
191
- detail: true
192
- )
193
- end
194
- end
195
-
196
- context 'with options' do
197
- let(:client_options) { {radius: 1000} }
198
- let(:method_options) { {radius: radius, keyword: keywords} }
199
- it 'preserves client options while merging with method options' do
200
- allow(GooglePlaces::Spot).to receive(:list_by_radar).with(lat, lng, api_key, method_options)
201
- expect { client.spots_by_radar(lat, lng, method_options) }.not_to change(client, :options)
202
- end
203
- end
204
- end
205
-
206
165
  describe '::predictions_by_input' do
207
166
  let(:input) { 'Atlanta' }
208
167
 
@@ -194,88 +194,6 @@ describe GooglePlaces::Request do
194
194
  end
195
195
  end
196
196
 
197
-
198
-
199
- context 'Listing spots by radar', vcr: { cassette_name: 'list_spots_by_radar' } do
200
-
201
- context 'with valid options' do
202
- context 'with keyword' do
203
- it do
204
- response = GooglePlaces::Request.spots_by_radar(
205
- :location => @location,
206
- :keyword => @keyword,
207
- :radius => @radius,
208
- :key => api_key
209
- )
210
- expect(response['results']).to_not be_empty
211
- end
212
- end
213
-
214
- context 'with name' do
215
- it do
216
- response = GooglePlaces::Request.spots_by_radar(
217
- :location => @location,
218
- :name => 'park',
219
- :radius => @radius,
220
- :key => api_key
221
- )
222
- expect(response['results']).to_not be_empty
223
- end
224
- end
225
- end
226
-
227
- context 'without keyword' do
228
- context 'without retry options' do
229
- it do
230
- expect(lambda {
231
- GooglePlaces::Request.spots_by_radar(
232
- :location => @location,
233
- :radius => @radius,
234
- :key => api_key
235
- )
236
- }).to raise_error GooglePlaces::InvalidRequestError
237
- end
238
- end
239
-
240
- context 'with retry options' do
241
- context 'without timeout' do
242
- it do
243
- expect(lambda {
244
- GooglePlaces::Request.spots_by_radar(
245
- :location => @location,
246
- :radius => @radius,
247
- :key => api_key,
248
- :retry_options => {
249
- :max => 3,
250
- :status => 'INVALID_REQUEST',
251
- :delay => 1
252
- }
253
- )
254
- }).to raise_error GooglePlaces::RetryError
255
- end
256
- end
257
-
258
- context 'with timeout' do
259
- it do
260
- expect(lambda {
261
- GooglePlaces::Request.spots_by_radar(
262
- :location => @location,
263
- :radius => @radius,
264
- :key => api_key,
265
- :retry_options => {
266
- :max => 3,
267
- :status => 'INVALID_REQUEST',
268
- :delay => 10,
269
- :timeout => 1
270
- }
271
- )
272
- }).to raise_error GooglePlaces::RetryTimeoutError
273
- end
274
- end
275
- end
276
- end
277
- end
278
-
279
197
  context 'with an API key not authorized to use the Places API' do
280
198
  it 'includes the error_message in the exception' do
281
199
  stub_request(:get, "https://maps.googleapis.com/maps/api/place/details/json").
@@ -5,7 +5,7 @@ describe GooglePlaces::Spot do
5
5
  before :each do
6
6
  @lat = '-33.8670522'
7
7
  @lng = '151.1957362'
8
- @radius = 200
8
+ @radius = 500
9
9
  @pagetoken = 'CmRVAAAAqKK43TjXKnyEx4-XTWd4bC-iBq88Olspwga_JQbEpznYpfwXYbWBrxmb-1QYD4DMtq8gym5YruCEVjByOlKn8PWKQO5fHvuYD8rWKHUeBvMleM7k3oh9TUG8zqcyuhPmEhCG_C2XuypmkQ20hRvxro4sGhQN3nbWCjgpjyG_E_ayjVIoTGbViw'
10
10
  @place_id = 'ChIJN1t_tDeuEmsRUsoyG83frY4'
11
11
  end
@@ -21,7 +21,7 @@ describe GooglePlaces::Spot do
21
21
  false,
22
22
  {
23
23
  location: "-33.86705220,151.19573620",
24
- radius: 200,
24
+ radius: 500,
25
25
  rankby: "prominence",
26
26
  key: RSPEC_API_KEY,
27
27
  name: nil,
@@ -30,11 +30,9 @@ describe GooglePlaces::Spot do
30
30
  retry_options: {}
31
31
  })
32
32
  end
33
-
34
33
  end
35
34
 
36
35
  context 'List spots', vcr: { cassette_name: 'list_spots' } do
37
-
38
36
  after(:each) do
39
37
  expect(@collection.map(&:class).uniq).to eq [GooglePlaces::Spot]
40
38
  end
@@ -57,25 +55,12 @@ describe GooglePlaces::Spot do
57
55
 
58
56
  describe 'with multiple types', vcr: { cassette_name: 'list_spots_with_multiple_types' } do
59
57
  before(:each) do
60
- @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :types => ['food','establishment'])
58
+ @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :types => ["atm", "lodging"])
61
59
  end
62
60
 
63
61
  it 'should have Spots with specific types' do
64
62
  @collection.each do |spot|
65
- expect(spot.types & ['food', 'establishment']).to be_any
66
- end
67
- end
68
- end
69
-
70
- describe 'searching by name and types', vcr: { cassette_name: 'list_spots_with_name_and_types' } do
71
-
72
- before(:each) do
73
- @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :types => ['food','establishment'], :name => 'italian')
74
- end
75
-
76
- it 'should have Spots with specific types' do
77
- @collection.each do |spot|
78
- expect(spot.types & ['food', 'establishment']).to be_any
63
+ expect(spot.types & ['atm', 'lodging']).to be_any
79
64
  end
80
65
  end
81
66
  end
@@ -83,7 +68,7 @@ describe GooglePlaces::Spot do
83
68
  describe 'searching by types with exclusion', vcr: { cassette_name: 'list_spots_with_types_and_exclusion' } do
84
69
 
85
70
  it 'should exclude spots with type "restaurant"' do
86
- @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :types => ['food','establishment'], :exclude => 'restaurant')
71
+ @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :types => ['atm','lodging'], :exclude => 'restaurant')
87
72
 
88
73
  @collection.map(&:types).each do |types|
89
74
  expect(types).to_not include('restaurant')
@@ -143,29 +128,16 @@ describe GooglePlaces::Spot do
143
128
  it 'should include country in formatted address' do
144
129
  @collection = GooglePlaces::Spot.list_by_query('Statue of liberty, New York', api_key, region: 'ca')
145
130
  @collection.each do |spot|
146
- expect(spot.formatted_address).to end_with('United States')
131
+ expect(spot.formatted_address).to end_with('USA')
147
132
  end
148
133
  end
149
134
 
150
135
  it 'should not include country in formatted address' do
151
136
  @collection = GooglePlaces::Spot.list_by_query('Statue of liberty, New York', api_key, region: 'us')
152
137
  @collection.each do |spot|
153
- expect(spot.formatted_address).to_not end_with('United States')
138
+ expect(spot.formatted_address).to_not end_with('USA')
154
139
  end
155
140
  end
156
-
157
- end
158
-
159
- context 'List spots by radar', vcr: { cassette_name: 'list_spots_by_radar' } do
160
-
161
- after(:each) do
162
- expect(@collection.map(&:class).uniq).to eq [GooglePlaces::Spot]
163
- end
164
-
165
- it 'should be a collection of Spots' do
166
- @collection = GooglePlaces::Spot.list_by_radar('48.8567', '2.3508', api_key, :radius => @radius, :keyword => 'attractions')
167
- end
168
-
169
141
  end
170
142
 
171
143
  context 'Find a single spot', vcr: { cassette_name: 'single_spot' } do
@@ -209,4 +181,20 @@ describe GooglePlaces::Spot do
209
181
  expect(@spot.formatted_address).to_not end_with('Australia')
210
182
  end
211
183
  end
184
+
185
+ context 'Find a single spot with specified params', vcr: { cassette_name: 'single_spot_with_specified_params' } do
186
+ it 'should include the specified params in the response' do
187
+ @spot = GooglePlaces::Spot.find(@place_id, api_key, fields:'place_id,name')
188
+ expect(@spot.place_id).to eq(@place_id)
189
+ expect(@spot.name).to eq('Google Australia')
190
+ end
191
+
192
+ it 'should not include unspecified fields' do
193
+ @spot = GooglePlaces::Spot.find(@place_id, api_key, region: 'place_id,name')
194
+ spot_instance_variable_return_values = (@spot.instance_variables - [@place_id, @name]).map do |iv|
195
+ @post.instance_variable_get(iv.to_sym)
196
+ end
197
+ expect(spot_instance_variable_return_values.compact).to eq([])
198
+ end
199
+ end
212
200
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: http://httpstat.us/502?key=AIzaSyAKeN0XMV5LqJmqBrZZ1K8qMipFW7-Eybg&reference=CnRsAAAASc4grenwL0h3X5VPNp5fkDNfqbjt3iQtWIPlKS-3ms9GbnCxR_FLHO0B0ZKCgJSg19qymkeHagjQFB4aUL87yhp4mhFTc17DopK1oiYDaeGthztSjERic8TmFNe-6zOpKSdiZWKE6xlQvcbSiWIJchIQOEYZqunSSZqNDoBSs77bWRoUJcMMVANtSlhy0llKI0MI6VcC7DU
5
+ uri: http://httpstat.us/502?key=<API_KEY>&reference=CnRsAAAASc4grenwL0h3X5VPNp5fkDNfqbjt3iQtWIPlKS-3ms9GbnCxR_FLHO0B0ZKCgJSg19qymkeHagjQFB4aUL87yhp4mhFTc17DopK1oiYDaeGthztSjERic8TmFNe-6zOpKSdiZWKE6xlQvcbSiWIJchIQOEYZqunSSZqNDoBSs77bWRoUJcMMVANtSlhy0llKI0MI6VcC7DU
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Content-Type:
26
26
  - text/plain; charset=utf-8
27
27
  Server:
28
- - Microsoft-IIS/8.0
28
+ - Microsoft-IIS/10.0
29
29
  X-Aspnetmvc-Version:
30
30
  - '5.1'
31
31
  Access-Control-Allow-Origin:
@@ -35,12 +35,12 @@ http_interactions:
35
35
  X-Powered-By:
36
36
  - ASP.NET
37
37
  Set-Cookie:
38
- - ARRAffinity=5f087fd6a40a6d05f0b0eb568d99070a0e7b27a443c43c64047aae88fa2e0bea;Path=/;HttpOnly;Domain=httpstat.us
38
+ - ARRAffinity=580ecdc04582a8c27680686941822edec8921fe0a4244b99f898ac1d3a4de89a;Path=/;HttpOnly;Domain=httpstat.us
39
39
  Date:
40
- - Tue, 07 Nov 2017 10:30:02 GMT
40
+ - Tue, 18 Jun 2019 10:51:49 GMT
41
41
  body:
42
42
  encoding: UTF-8
43
43
  string: 502 Bad Gateway
44
44
  http_version:
45
- recorded_at: Tue, 07 Nov 2017 10:30:03 GMT
45
+ recorded_at: Tue, 18 Jun 2019 10:51:49 GMT
46
46
  recorded_with: VCR 2.9.3