Class: GooglePlaces::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_places/client.rb

Overview

This class acts as a proxy to the working classes when requesting data from the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = @api_key, options = {}) ⇒ Client

Creates a new Client instance which proxies the requests to the certain classes

Parameters:

  • api_key (String) (defaults to: @api_key)

    The api key to use for the requests

  • options (Hash) (defaults to: {})

    An options hash for requests. Is used as the query parameters on server requests

Options Hash (options):

  • lat (String, Integer)

    the latitude for the search

  • lng (String, Integer)

    the longitude for the search

  • :radius (Integer)

    Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50,000 meters. Note that radius must not be included if :rankby is specified

  • :types (String, Array)

    Restricts the results to Spots matching at least one of the specified types

  • :name (String)

    A term to be matched against the names of Places. Results will be restricted to those containing the passed name value.

  • :keyword (String)

    A term to be matched against all content that Google has indexed for this Spot, including but not limited to name, type, and address, as well as customer reviews and other third-party content.

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

  • :exclude (String, Array<String>)

    A String or an Array of types to exclude from results

  • :retry_options (Hash)

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object)
  • :retry_options[:max] (Integer)

    the maximum retries

  • :retry_options[:delay] (Integer)

    the delay between each retry in seconds

See Also:



44
45
46
47
# File 'lib/google_places/client.rb', line 44

def initialize(api_key = @api_key, options = {})
  api_key ? @api_key = api_key : @api_key = GooglePlaces.api_key
  @options = options
end

Instance Attribute Details

#api_keyString (readonly)

Returns the provided api key.

Returns:

  • (String)

    the provided api key



5
6
7
# File 'lib/google_places/client.rb', line 5

def api_key
  @api_key
end

#optionsHash (readonly)

Returns the provided options hash.

Returns:

  • (Hash)

    the provided options hash



7
8
9
# File 'lib/google_places/client.rb', line 7

def options
  @options
end

Instance Method Details

#predictions_by_input(input, options = {}) ⇒ Array<Prediction>

Query for Place Predictions

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • lat (String, Integer)

    the latitude for the search

  • lng (String, Integer)

    the longitude for the search

  • :radius (Integer) — default: 1000

    Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50,000 meters. Note that radius must not be included if :rankby => ‘distance’ (described below) is specified. Note that this is a mandatory parameter

  • :types (String, Array)

    Restricts the results to Spots matching at least one of the specified types

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

Returns:

See Also:



297
298
299
# File 'lib/google_places/client.rb', line 297

def predictions_by_input(input, options = {})
  Prediction.list_by_input(input, @api_key, @options.merge(options))
end

#spot(place_id, options = {}) ⇒ Spot

Search for a Spot with a reference key

Parameters:

  • place_id (String)

    the place_id of the spot

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

Returns:



116
117
118
# File 'lib/google_places/client.rb', line 116

def spot(place_id, options = {})
  Spot.find(place_id, @api_key, @options.merge(options))
end

#spots(lat, lng, options = {}) ⇒ Array<Spot>

Search for Spots at the provided location

Parameters:

  • lat (String, Integer)

    the latitude for the search

  • lng (String, Integer)

    the longitude for the search

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :radius (Integer) — default: 1000

    Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50,000 meters. Note that radius must not be included if :rankby => ‘distance’ (described below) is specified. Note that this is a mandatory parameter

  • :rankby (String)

    Specifies the order in which results are listed. Possible values are:

    • prominence (default). This option sorts results based on their importance. Ranking will favor prominent places within the specified area. Prominence can be affected by a Place’s ranking in Google’s index, 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.

  • :types (String, Array)

    Restricts the results to Spots matching at least one of the specified types

  • :name (String)

    A term to be matched against the names of Places. Results will be restricted to those containing the passed name value.

  • :keyword (String)

    A term to be matched against all content that Google has indexed for this Spot, including but not limited to name, type, and address, as well as customer reviews and other third-party content.

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

  • :exclude (String, Array<String>) — default: []

    A String or an Array of types to exclude from results

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

  • :detail (Boolean)

    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.

Returns:

See Also:



95
96
97
98
99
100
101
# File 'lib/google_places/client.rb', line 95

def spots(lat, lng, options = {})
  detail = @options.merge!(options).delete(:detail)
  collection_detail_level(
    Spot.list(lat, lng, @api_key, @options),
    detail
  )
end

#spots_by_bounds(bounds, options = {}) ⇒ Array<Spot>

Search for Spots within a give SW|NE bounds with query

Parameters:

  • bounds (Hash)
  • api_key (String)

    the provided api key

  • options (Hash) (defaults to: {})

Options Hash (bounds):

  • :start_point (String, Array)

    An array that contains the lat/lng pair for the first

    point in the bounds (rectangle)
    
  • [String, (:start_point)

    Integer] :lat The starting point coordinates latitude value

  • [String, (:start_point)

    Integer] :lng The starting point coordinates longitude value

  • :end_point (String, Array)

    An array that contains the lat/lng pair for the end

    point in the bounds (rectangle)
    
  • [String, (:end_point)

    Integer] :lat The end point coordinates latitude value

  • [String, (:end_point)

    Integer] :lng The end point coordinates longitude value

Options Hash (options):

  • :query (String, Array)

    Restricts the results to Spots matching term(s) in the specified query

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

  • :exclude (String, Array<String>) — default: []

    A String or an Array of types to exclude from results

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

  • :detail (Boolean)

    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.

Returns:

See Also:



202
203
204
205
206
207
208
# File 'lib/google_places/client.rb', line 202

def spots_by_bounds(bounds, options = {})
  detail = @options.merge!(options).delete(:detail)
  collection_detail_level(
    Spot.list_by_bounds(bounds, @api_key, @options),
    detail
  )
end

#spots_by_pagetoken(pagetoken, options = {}) ⇒ Array<Spot>

Search for Spots with a pagetoken

Parameters:

  • pagetoken (String)

    the next page token to search for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :exclude (String, Array<String>) — default: []

    A String or an Array of types to exclude from results

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

  • :detail (Boolean)

    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.

Returns:

See Also:



226
227
228
229
230
231
232
# File 'lib/google_places/client.rb', line 226

def spots_by_pagetoken(pagetoken, options = {})
  detail = @options.merge!(options).delete(:detail)
  collection_detail_level(
    Spot.list_by_pagetoken(pagetoken, @api_key, @options),
    detail
  )
end

#spots_by_query(query, options = {}) ⇒ Array<Spot>

Search for Spots with a query

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • lat (String, Integer)

    the latitude for the search

  • lng (String, Integer)

    the longitude for the search

  • :radius (Integer) — default: 1000

    Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50,000 meters. Note that radius must not be included if :rankby => ‘distance’ (described below) is specified. Note that this is a mandatory parameter

  • :rankby (String)

    Specifies the order in which results are listed. Possible values are:

    • prominence (default). This option sorts results based on their importance. Ranking will favor prominent places within the specified area. Prominence can be affected by a Place’s ranking in Google’s index, 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.

  • :types (String, Array)

    Restricts the results to Spots matching at least one of the specified types

  • :language (String)

    The language code, indicating in which language the results should be returned, if possible.

  • :exclude (String, Array<String>) — default: []

    A String or an Array of types to exclude from results

  • :retry_options (Hash) — default: {}

    A Hash containing parameters for search retries

  • :retry_options[:status] (Object) — default: []
  • :retry_options[:max] (Integer) — default: 0

    the maximum retries

  • :retry_options[:delay] (Integer) — default: 5

    the delay between each retry in seconds

  • :detail (Boolean)

    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.

Returns:

See Also:



159
160
161
162
163
164
165
# File 'lib/google_places/client.rb', line 159

def spots_by_query(query, options = {})
  detail = @options.merge!(options).delete(:detail)
  collection_detail_level(
    Spot.list_by_query(query, @api_key, @options),
    detail
  )
end

#spots_by_radar(lat, lng, options = {}) ⇒ Array<Spot>

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.

Parameters:

  • lat (String, Integer)

    the latitude for the search

  • lng (String, Integer)

    the longitude for the search

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :radius (Integer) — default: 1000

    Defines the distance (in meters) within which to return Place results. The maximum allowed radius is 50,000 meters. Note that this is a mandatory parameter

  • :types (String, Array)

    Restricts the results to Spots matching at least one of the specified types

  • :name (String)

    A term to be matched against the names of Places. Results will be restricted to those containing the passed name value.

  • :keyword (String)

    A term to be matched against all content that Google has indexed for this Spot, including but not limited to name, type, and address, as well as customer reviews and other third-party content.

  • :minprice (Integer)

    Restricts results to only those places within the specified price range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive.

  • :maxprice (Integer)

    Restricts results to only those places within the specified price range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive.

  • :opennow (Boolean)

    Retricts results to those Places that are open for business at the time the query is sent. Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query. Setting openNow to false has no effect.

  • :zagatselected (Boolean)

    Restrict your search to only those locations that are Zagat selected businesses. This parameter does not require a true or false value, simply including the parameter in the request is sufficient to restrict your search. The zagatselected parameter is experimental, and only available to Places API enterprise customers.

  • :detail (Boolean)

    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.

Returns:

See Also:



270
271
272
273
274
275
276
# File 'lib/google_places/client.rb', line 270

def spots_by_radar(lat, lng, options = {})
  detail = @options.merge!(options).delete(:detail)
  collection_detail_level(
    Spot.list_by_radar(lat, lng, @api_key, @options),
    detail
  )
end