google_places 0.24.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71b0c22f8ff5d7f4126d7d99bdfe4ba4e02f3ca7
4
- data.tar.gz: a9743dff330d99c2d3bebc70cbb2e30373469aff
3
+ metadata.gz: aa3d60080776cfdf41db6e889d93a4a867cbb21c
4
+ data.tar.gz: d9bc8d18548afecb8a3cf811c605db6c005b0591
5
5
  SHA512:
6
- metadata.gz: cefe8b2f0f204e88538d1cf963dd5f7deff967304f7f0933c1fccfbfcdb73efbf9123300d3d63a4adafed95ed69156ed502934f3eb633d84b9c49d2545c1b5d6
7
- data.tar.gz: 8cdfd49cb2ae7db142f5543f11e868e2cfeb94de49aa2397d11fa10005da9b3629238ca47a4c17b79b0d53f03ad95c8e5a849c5616a869efe27f128707e4b36a
6
+ metadata.gz: 11d260b9b3a91ed0866a85b20236fd2d8bd10957972e2a482c06bc2d42ea261792622eb167877add3ade9e4b7474db3a24799f6a76da47f195b5b18ca44f732c
7
+ data.tar.gz: f5f368bf9522fe018179a2c7c52bc3aa4ad512da3c4b3678c2e9bc432dc554623b0a2073b6228c40c4947341978941fd9dd152613ca6f1beed992278f5f2ab03
data/.gitignore CHANGED
@@ -8,3 +8,7 @@ spec/api_key.rb
8
8
  .yardoc/
9
9
  doc/
10
10
  .idea
11
+ *.swp
12
+ *.swo
13
+ .ruby-version
14
+ .ruby-gemset
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_places (0.22.0)
4
+ google_places (0.26.0)
5
5
  httparty (~> 0.13.1)
6
6
 
7
7
  GEM
@@ -83,7 +83,7 @@ Get results in specific language:
83
83
  @client.spots(-33.8670522, 151.1957362, :language => 'en')
84
84
 
85
85
  === Retrieving spots based on query
86
-
86
+
87
87
  @client.spots_by_query('Pizza near Miami Florida')
88
88
 
89
89
  Search by multiple types and exclude multiple types
@@ -111,9 +111,35 @@ Then retrieve the spot:
111
111
  @spot = @client.spot('CmRYAAA...upoTH3g')
112
112
 
113
113
  Then request one of the photos url with a max width:
114
-
114
+
115
115
  url = @spot.photos[0].fetch_url(800)
116
116
 
117
+ === Places Autocomplete
118
+
119
+ https://developers.google.com/places/documentation/autocomplete
120
+
121
+ <em>Note:</em> Autocomplete is often used and better suited on client side (browser/javascript). The Autocomplete API is rate limited, so make sure you check the usage limits before deciding on whether to call the API server/client side.
122
+
123
+ https://developers.google.com/maps/documentation/business/articles/usage_limits
124
+
125
+ ==== Example usage
126
+
127
+ Register a new Client:
128
+
129
+ @client = GooglePlaces::Client.new(API_KEY)
130
+
131
+ Then request a prediction based on partial match:
132
+
133
+ @client.predictions_by_input(
134
+ 'San F',
135
+ lat: 0.0,
136
+ lng: 0.0,
137
+ radius: 20000000,
138
+ types: 'geocode',
139
+ language: I18n.locale,
140
+ )
141
+
142
+ The response will be an array of predictions.
117
143
 
118
144
  == Development
119
145
 
@@ -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 = '0.24.0'
6
+ s.version = '0.26.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Marcel de Graaf']
9
9
  s.email = ['mail@marceldegraaf.net']
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
3
 
4
- %w(client location request spot error photo).each do |file|
4
+ %w(client location prediction request spot error photo).each do |file|
5
5
  require File.join(File.dirname(__FILE__), 'google_places', file)
6
6
  end
7
7
 
@@ -5,7 +5,6 @@ module GooglePlaces
5
5
  attr_reader :api_key
6
6
  # @return [Hash] the provided options hash
7
7
  attr_reader :options
8
- attr_reader :sensor
9
8
 
10
9
  # Creates a new Client instance which proxies the requests to the certain classes
11
10
  #
@@ -19,8 +18,6 @@ module GooglePlaces
19
18
  # Defines the distance (in meters) within which to return Place results.
20
19
  # The maximum allowed radius is 50,000 meters.
21
20
  # Note that radius must not be included if <b>:rankby</b> is specified
22
- # @option options [Boolean] :sensor
23
- # 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.
24
21
  # @option options [String,Array] :types
25
22
  # Restricts the results to Spots matching at least one of the specified types
26
23
  # @option options [String] :name
@@ -44,9 +41,8 @@ module GooglePlaces
44
41
  # @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
45
42
  # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
46
43
 
47
- def initialize(api_key = @api_key, sensor = false, options = {})
44
+ def initialize(api_key = @api_key, options = {})
48
45
  api_key ? @api_key = api_key : @api_key = GooglePlaces.api_key
49
- @sensor = sensor
50
46
  @options = options
51
47
  end
52
48
 
@@ -70,10 +66,6 @@ module GooglePlaces
70
66
  # - distance. This option sorts results in ascending order by their distance from the specified location.
71
67
  # Ranking results by distance will set a fixed search radius of 50km.
72
68
  # 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.
73
- # @option options [Boolean] :sensor (false)
74
- # Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS)
75
- # to determine the location sent in this request.
76
- # <b>Note that this is a mandatory parameter</b>
77
69
  # @option options [String,Array] :types
78
70
  # Restricts the results to Spots matching at least one of the specified types
79
71
  # @option options [String] :name
@@ -97,7 +89,7 @@ module GooglePlaces
97
89
  # @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
98
90
  # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
99
91
  def spots(lat, lng, options = {})
100
- Spot.list(lat, lng, @api_key, @sensor, @options.merge(options))
92
+ Spot.list(lat, lng, @api_key, @options.merge(options))
101
93
  end
102
94
 
103
95
  # Search for a Spot with a reference key
@@ -105,9 +97,6 @@ module GooglePlaces
105
97
  # @return [Spot]
106
98
  # @param [String] place_id the place_id of the spot
107
99
  # @param [Hash] options
108
- # @option options [Boolean] :sensor (false)
109
- # 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.
110
- # <b>Note that this is a mandatory parameter</b>
111
100
  # @option options [String] :language
112
101
  # The language code, indicating in which language the results should be returned, if possible.
113
102
  #
@@ -117,7 +106,7 @@ module GooglePlaces
117
106
  # @option options [Integer] :retry_options[:max] (0) the maximum retries
118
107
  # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
119
108
  def spot(place_id, options = {})
120
- Spot.find(place_id, @api_key, @sensor, @options.merge(options))
109
+ Spot.find(place_id, @api_key, @options.merge(options))
121
110
  end
122
111
 
123
112
  # Search for Spots with a query
@@ -141,9 +130,6 @@ module GooglePlaces
141
130
  # - distance. This option sorts results in ascending order by their distance from the specified location.
142
131
  # Ranking results by distance will set a fixed search radius of 50km.
143
132
  # 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.
144
- # @option options [Boolean] :sensor (false)
145
- # 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.
146
- # <b>Note that this is a mandatory parameter</b>
147
133
  # @option options [String,Array] :types
148
134
  # Restricts the results to Spots matching at least one of the specified types
149
135
  # @option options [String] :language
@@ -160,7 +146,7 @@ module GooglePlaces
160
146
  # @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
161
147
  # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
162
148
  def spots_by_query(query, options = {})
163
- Spot.list_by_query(query, @api_key, @sensor, @options.merge(options))
149
+ Spot.list_by_query(query, @api_key, @options.merge(options))
164
150
  end
165
151
 
166
152
  # Search for Spots with a pagetoken
@@ -178,11 +164,11 @@ module GooglePlaces
178
164
  #
179
165
  # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
180
166
  def spots_by_pagetoken(pagetoken, options = {})
181
- Spot.list_by_pagetoken(pagetoken, @api_key, @sensor, @options.merge(options))
167
+ Spot.list_by_pagetoken(pagetoken, @api_key, @options.merge(options))
182
168
  end
183
169
 
184
170
  # 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.
185
- #
171
+ #
186
172
  # @return [Array<Spot>]
187
173
  # @param [String,Integer] lat the latitude for the search
188
174
  # @param [String,Integer] lng the longitude for the search
@@ -205,18 +191,40 @@ module GooglePlaces
205
191
  # @option options [Integer] :maxprice
206
192
  # Restricts results to only those places within the specified price range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive.
207
193
  # @option options [Boolean] :opennow
208
- # Retricts results to those Places that are open for business at the time the query is sent.
209
- # Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
194
+ # Retricts results to those Places that are open for business at the time the query is sent.
195
+ # Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
210
196
  # Setting openNow to false has no effect.
211
197
  # @option options [Boolean] :zagatselected
212
- # Restrict your search to only those locations that are Zagat selected businesses.
213
- # This parameter does not require a true or false value, simply including the parameter in the request is sufficient to restrict your search.
198
+ # Restrict your search to only those locations that are Zagat selected businesses.
199
+ # This parameter does not require a true or false value, simply including the parameter in the request is sufficient to restrict your search.
214
200
  # The zagatselected parameter is experimental, and only available to Places API enterprise customers.
215
201
  #
216
202
  # @see https://developers.google.com/places/documentation/search#RadarSearchRequests
217
203
  def spots_by_radar(lat, lng, options = {})
218
- Spot.list_by_radar(lat, lng, @api_key, @sensor, @options.merge(options))
204
+ Spot.list_by_radar(lat, lng, @api_key, @options.merge(options))
219
205
  end
220
206
 
207
+ # Query for Place Predictions
208
+ #
209
+ # @return [Array<Prediction>]
210
+ # @param [String] query the query to search for
211
+ # @param [Hash] options
212
+ # @option options [String,Integer] lat the latitude for the search
213
+ # @option options [String,Integer] lng the longitude for the search
214
+ # @option options [Integer] :radius (1000)
215
+ # Defines the distance (in meters) within which to return Place results.
216
+ # The maximum allowed radius is 50,000 meters.
217
+ # Note that radius must not be included if :rankby => 'distance' (described below) is specified.
218
+ # <b>Note that this is a mandatory parameter</b>
219
+ # @option options [String,Array] :types
220
+ # Restricts the results to Spots matching at least one of the specified types
221
+ # @option options [String] :language
222
+ # The language code, indicating in which language the results should be returned, if possible.
223
+ #
224
+ # @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
225
+ # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
226
+ def predictions_by_input(input, options = {})
227
+ Prediction.list_by_input(input, @api_key, @options.merge(options))
228
+ end
221
229
  end
222
230
  end
@@ -7,7 +7,6 @@ module GooglePlaces
7
7
  # This can be the case when:
8
8
  # - querying the SPOT_LIST_URL <b>without</b> the following parameters:
9
9
  # - - key
10
- # - - sensor
11
10
  class RequestDeniedError < HTTParty::ResponseError
12
11
  end
13
12
 
@@ -2,23 +2,18 @@ module GooglePlaces
2
2
  class Photo
3
3
  attr_accessor :width, :height, :photo_reference, :html_attributions
4
4
 
5
- def initialize(width, height, photo_reference, html_attributions, api_key, sensor)
5
+ def initialize(width, height, photo_reference, html_attributions, api_key)
6
6
  @width = width
7
7
  @height = height
8
8
  @photo_reference = photo_reference
9
9
  @html_attributions = html_attributions
10
10
  @api_key = api_key
11
- @sensor = sensor
12
11
  end
13
12
 
14
13
  # Search for a Photo's url with its reference key
15
14
  #
16
15
  # @return [URL]
17
16
  # @param [String] api_key the provided api key
18
- # @param [Boolean] sensor
19
- # Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS)
20
- # to determine the location sent in this request.
21
- # <b>Note that this is a mandatory parameter</b>
22
17
  # @param [Hash] options
23
18
  # @option options [Hash] :retry_options ({})
24
19
  # A Hash containing parameters for search retries
@@ -33,7 +28,6 @@ module GooglePlaces
33
28
  @fetched_url = Request.photo_url(
34
29
  :maxwidth => maxwidth,
35
30
  :photoreference => @photo_reference,
36
- :sensor => @sensor,
37
31
  :key => @api_key,
38
32
  :retry_options => retry_options
39
33
  )
@@ -0,0 +1,71 @@
1
+ module GooglePlaces
2
+ class Prediction
3
+
4
+ attr_accessor(
5
+ :description,
6
+ :place_id,
7
+ )
8
+
9
+ def initialize(json_result_object)
10
+ @description = json_result_object['description']
11
+ @place_id = json_result_object['place_id']
12
+ end
13
+
14
+ # Query for Predictions (optionally at the provided location)
15
+ #
16
+ # @option [String,Integer] :lat the latitude for the search
17
+ # @option [String,Integer] :lng the longitude for the search
18
+ # @option options [Integer] :radius (1000)
19
+ # Defines the distance (in meters) within which to return Place results.
20
+ # The maximum allowed radius is 50,000 meters.
21
+ # Note that radius must not be included if :rankby => 'distance' (described below) is specified.
22
+ # @option options [String,Array] :types
23
+ # Restricts the results to Spots matching at least one of the specified types
24
+ # @option options [String] :language
25
+ # The language code, indicating in which language the results should be returned, if possible.
26
+ # @option options [Hash] :retry_options ({})
27
+ # A Hash containing parameters for search retries
28
+ # @option options [Object] :retry_options[:status] ([])
29
+ # @option options [Integer] :retry_options[:max] (0) the maximum retries
30
+ # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
31
+ def self.list_by_input(input, api_key, options = {})
32
+ lat = options.delete(:lat)
33
+ lng = options.delete(:lng)
34
+ language = options.delete(:language)
35
+ radius = options.delete(:radius)
36
+ retry_options = options.delete(:retry_options) || {}
37
+ types = options.delete(:types)
38
+
39
+ options = {
40
+ :input => input,
41
+ :key => api_key,
42
+ :retry_options => retry_options
43
+ }
44
+
45
+ if lat && lng
46
+ options[:location] = Location.new(lat, lng).format
47
+ options[:radius] = radius if radius
48
+ end
49
+
50
+ # Accept Types as a string or array
51
+ if types
52
+ types = (types.is_a?(Array) ? types.join('|') : types)
53
+ options[:types] = types
54
+ end
55
+
56
+ if language
57
+ options[:language] = language
58
+ end
59
+
60
+ request(:predictions_by_input, options)
61
+ end
62
+
63
+ def self.request(method, options)
64
+ response = Request.send(method, options)
65
+
66
+ response['predictions'].map do |result|
67
+ self.new(result)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -14,6 +14,7 @@ module GooglePlaces
14
14
  TEXT_SEARCH_URL = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
15
15
  PAGETOKEN_URL = 'https://maps.googleapis.com/maps/api/place/search/json'
16
16
  RADAR_SEARCH_URL = 'https://maps.googleapis.com/maps/api/place/radarsearch/json'
17
+ AUTOCOMPLETE_URL = 'https://maps.googleapis.com/maps/api/place/autocomplete/json'
17
18
 
18
19
  # Search for Spots at the provided location
19
20
  #
@@ -27,9 +28,6 @@ module GooglePlaces
27
28
  # The maximum allowed radius is 50,000 meters.
28
29
  # Note that radius must not be included if <b>:rankby</b> is specified
29
30
  # <b>Note that this is a mandatory parameter</b>
30
- # @option options [Boolean] :sensor
31
- # 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.
32
- # <b>Note that this is a mandatory parameter</b>
33
31
  # @option options [(Integer,Integer),String] :location
34
32
  # The latitude/longitude around which to retrieve Spot information. This must be specified as latitude,longitude
35
33
  # <b>Note that this is a mandatory parameter</b>
@@ -72,9 +70,6 @@ module GooglePlaces
72
70
  # in requests but is snake_cased in responses (place_id)
73
71
  # @see: https://developers.google.com/places/documentation/details
74
72
  # <b>Note that this is a mandatory parameter</b>
75
- # @option options [Boolean] :sensor
76
- # 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.
77
- # <b>Note that this is a mandatory parameter</b>
78
73
  # @option options [String] :language
79
74
  # The language code, indicating in which language the results should be returned, if possible.
80
75
  #
@@ -94,9 +89,6 @@ module GooglePlaces
94
89
  # <b>Note that this is a mandatory parameter</b>
95
90
  # @option options [String] :location
96
91
  # the lat, lng for the search
97
- # @option options [Boolean] :sensor
98
- # 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.
99
- # <b>Note that this is a mandatory parameter</b>
100
92
  # @option options [Integer] :radius (1000)
101
93
  # Defines the distance (in meters) within which to return Place results.
102
94
  # The maximum allowed radius is 50,000 meters.
@@ -115,12 +107,12 @@ module GooglePlaces
115
107
  # @option options [Integer] :maxprice
116
108
  # Restricts results to only those places within the specified price range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive.
117
109
  # @option options [Boolean] :opennow
118
- # Retricts results to those Places that are open for business at the time the query is sent.
119
- # Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
110
+ # Retricts results to those Places that are open for business at the time the query is sent.
111
+ # Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.
120
112
  # Setting openNow to false has no effect.
121
113
  # @option options [Boolean] :zagatselected
122
- # Restrict your search to only those locations that are Zagat selected businesses.
123
- # This parameter does not require a true or false value, simply including the parameter in the request is sufficient to restrict your search.
114
+ # Restrict your search to only those locations that are Zagat selected businesses.
115
+ # This parameter does not require a true or false value, simply including the parameter in the request is sufficient to restrict your search.
124
116
  # The zagatselected parameter is experimental, and only available to Places API enterprise customers.
125
117
  # @option options [Hash] :retry_options ({})
126
118
  # A Hash containing parameters for search retries
@@ -150,9 +142,6 @@ module GooglePlaces
150
142
  # The maximum allowed radius is 50,000 meters.
151
143
  # Note that radius must not be included if <b>:rankby</b> is specified
152
144
  # <b>Note that this is a mandatory parameter</b>
153
- # @option options [Boolean] :sensor
154
- # 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.
155
- # <b>Note that this is a mandatory parameter</b>
156
145
  # @option options [String,Array] :types
157
146
  # Restricts the results to Spots matching at least one of the specified types
158
147
  # @option options [String] :language
@@ -193,6 +182,25 @@ module GooglePlaces
193
182
  request.parsed_response
194
183
  end
195
184
 
185
+ # Query for Place Predictions
186
+ #
187
+ # @return [Array<Prediction>]
188
+ # @param [String] api_key the provided api key
189
+ # @param [Hash] options
190
+ # @option options [String,Array<String>] :exclude ([])
191
+ # A String or an Array of <b>types</b> to exclude from results
192
+ # @option options [Hash] :retry_options ({})
193
+ # A Hash containing parameters for search retries
194
+ # @option options [Object] :retry_options[:status] ([])
195
+ # @option options [Integer] :retry_options[:max] (0) the maximum retries
196
+ # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
197
+ #
198
+ # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
199
+ def self.predictions_by_input(options = {})
200
+ request = new(AUTOCOMPLETE_URL, options)
201
+ request.parsed_response
202
+ end
203
+
196
204
  # Search for a Photo's URL with a reference key
197
205
  #
198
206
  # @return [URL]
@@ -206,10 +214,6 @@ module GooglePlaces
206
214
  # @option options [String] :photoreference
207
215
  # The reference of a already retrieved Photo
208
216
  # <b>Note that this is a mandatory parameter</b>
209
- # @option options [Boolean] :sensor
210
- # 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.
211
- # <b>Note that this is a mandatory parameter</b>
212
- #
213
217
  # @option options [Hash] :retry_options ({})
214
218
  # A Hash containing parameters for search retries
215
219
  # @option options [Object] :retry_options[:status] ([])
@@ -233,9 +237,6 @@ module GooglePlaces
233
237
  # The maximum allowed radius is 50,000 meters.
234
238
  # Note that radius must not be included if <b>:rankby</b> is specified
235
239
  # <b>Note that this is a mandatory parameter</b>
236
- # @option options [Boolean] :sensor
237
- # 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.
238
- # <b>Note that this is a mandatory parameter</b>
239
240
  # @option options [(Integer,Integer),String] :location
240
241
  # The latitude/longitude around which to retrieve Spot information. This must be specified as latitude,longitude
241
242
  # <b>Note that this is a mandatory parameter</b>
@@ -271,7 +272,6 @@ module GooglePlaces
271
272
  retry_options[:status] = [retry_options[:status]] unless retry_options[:status].is_a?(Array)
272
273
  @response = self.class.get(url, :query => options, :follow_redirects => follow_redirects)
273
274
 
274
- # puts "@response.request.last_uri.to_s"
275
275
  # puts @response.request.last_uri.to_s
276
276
 
277
277
  return unless retry_options[:max] > 0 && retry_options[:status].include?(@response.parsed_response['status'])