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:



292
293
294
# File 'lib/google_places/client.rb', line 292

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:



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

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
102
# File 'lib/google_places/client.rb', line 95

def spots(lat, lng, options = {})
  options = @options.merge(options)
  detail = 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:



204
205
206
207
208
209
210
211
# File 'lib/google_places/client.rb', line 204

def spots_by_bounds(bounds, options = {})
  options = @options.merge(options)
  detail = 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:



229
230
231
232
233
234
235
236
# File 'lib/google_places/client.rb', line 229

def spots_by_pagetoken(pagetoken, options = {})
  options = @options.merge(options)
  detail = 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:



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

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