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, sensor = false, options = {}) ⇒ Client

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

Parameters:

  • api_key (String)

    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

  • :sensor (Boolean)

    Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request.

  • :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:



46
47
48
49
50
# File 'lib/google_places/client.rb', line 46

def initialize(api_key, sensor = false, options = {})
  @api_key = api_key
  @sensor = sensor
  @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

#sensorObject (readonly)

Returns the value of attribute sensor.



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

def sensor
  @sensor
end

Instance Method Details

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

Search for a Spot with a reference key

Parameters:

  • reference (String)

    the reference of the spot

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

Options Hash (options):

  • :sensor (Boolean) — default: false

    Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. Note that this is a mandatory parameter

  • :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:



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

def spot(reference, options = {})
  Spot.find(reference, @api_key, @sensor, @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. 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.

  • :sensor (Boolean) — default: false

    Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. 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.

  • :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

Returns:

See Also:



98
99
100
# File 'lib/google_places/client.rb', line 98

def spots(lat, lng, options = {})
  Spot.list(lat, lng, @api_key, @sensor, @options.merge(options))
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

Returns:

See Also:



179
180
181
# File 'lib/google_places/client.rb', line 179

def spots_by_pagetoken(pagetoken, options = {})
  Spot.list_by_pagetoken(pagetoken, @api_key, @sensor, @options.merge(options))
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.

  • :sensor (Boolean) — default: false

    Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. 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.

  • :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

Returns:

See Also:



161
162
163
# File 'lib/google_places/client.rb', line 161

def spots_by_query(query, options = {})
  Spot.list_by_query(query, @api_key, @sensor, @options.merge(options))
end