Skip to content

Commit

Permalink
Merge pull request #88 from ghbooth12/create-detailed-spots
Browse files Browse the repository at this point in the history
64 creating detailed spots
  • Loading branch information
edwinwills authored Feb 13, 2017
2 parents 1a0fe17 + 0c16c05 commit 1e38243
Show file tree
Hide file tree
Showing 17 changed files with 6,989 additions and 52,288 deletions.
9 changes: 9 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ objects has these attributes:
* *rating*: the rating of this spot on Google Places
* *url*: the url of this spot on Google Places

However <tt>address_components</tt>, <tt>city</tt>, <tt>country</tt>, <tt>formatted_address</tt>, <tt>region</tt> and <tt>url</tt> are <tt>nil</tt>.

* 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.
* 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.

=== Retrieving a list of spots

First register a new Client:
Expand Down Expand Up @@ -82,6 +87,10 @@ Get results in specific language:

@client.spots(-33.8670522, 151.1957362, :language => 'en')

Get detailed spots(This makes an extra call for each spot and returns a collection of the detailed spots.):

@client.spots(-33.8670522, 151.1957362, :detail => true)

=== Retrieving spots based on query

@client.spots_by_query('Pizza near Miami Florida')
Expand Down
15 changes: 13 additions & 2 deletions lib/google_places/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initialize(api_key = @api_key, options = {})
# the number of check-ins from your application, global popularity, and other factors.
# - distance. This option sorts results in ascending order by their distance from the specified location.
# Ranking results by distance will set a fixed search radius of 50km.
# One or more of keyword, name, or types is required. distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required.
# One or more of keyword, name, or types is required.
# @option options [String,Array] :types
# Restricts the results to Spots matching at least one of the specified types
# @option options [String] :name
Expand All @@ -86,10 +86,21 @@ def initialize(api_key = @api_key, options = {})
# @option options [Integer] :retry_options[:max] (0) the maximum retries
# @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
#
# @option options [Boolean] :detail
# A boolean to return spots with full detail information(its complete address, phone number, user rating, reviews, etc)
# Note) This makes an extra call for each spot for more information.
#
# @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
# @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
def spots(lat, lng, options = {})
Spot.list(lat, lng, @api_key, @options.merge(options))
detail_spot = options.delete(:detail)
spots = Spot.list(lat, lng, @api_key, @options.merge(options))

if detail_spot
spots.map {|spot| Spot.find(spot.place_id, @api_key, @options.merge(options))}
else
spots
end
end

# Search for a Spot with a reference key
Expand Down
19 changes: 19 additions & 0 deletions spec/google_places/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,23 @@

@client.predictions_by_input(input)
end

context 'List detailed spots', vcr: { cassette_name: 'list_spots_with_detail' } do
it 'should return spots with detail information' do
lat, lng = '28.3852377', '-81.566068'
@client = GooglePlaces::Client.new(api_key)

spots = @client.spots(lat, lng, detail: true)
expect(spots).to_not be_nil

for spot in spots
expect(spot.address_components).not_to be_nil
expect(spot.city).not_to be_nil
expect(spot.country).not_to be_nil
expect(spot.formatted_address).not_to be_nil
expect(spot.region).not_to be_nil
expect(spot.url).not_to be_nil
end
end
end
end
Loading

0 comments on commit 1e38243

Please sign in to comment.