google_places 0.29.0 → 0.30.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: c6cf4c3608d876073641025fdd76161b8954f1b9
4
- data.tar.gz: e65004cd9f37b00077d864233f71619acb91f2cf
3
+ metadata.gz: 38654649db0478793fd7abe3c0b80f2ab7c25f46
4
+ data.tar.gz: 4871aa13e63e37b8b8a393939af98ddfe9a99871
5
5
  SHA512:
6
- metadata.gz: 3858844ce1b18424f74289818e610851d146c9c31621d4a20850a4e83d4227feed2ad16d7251340fb3abbe23fed32bb0494ed6fe529e5010ddf111cb2bd27755
7
- data.tar.gz: 99ae539590a67883916a154b2a79b6bc3781686737c6e1ae91d59781957c40fe323af36a658c1e104c9042bc60aabc1bb6c8de88f9425e64ac849351cd740927
6
+ metadata.gz: 15fb60f01e7d74b0e38eda355810377d401b44e080fbf2861fb1899e68f82b6b0f5218dae63d18d97332c6a40363be84aca46aab1c083737067c00a46158a8c4
7
+ data.tar.gz: 0d6e1fd84dcb5db00e31ff38813da5599f75708394d68896cea88d529f93656fc6a91070f7d51618bec020c9b92e386c672d3645a708907e1b532c120eda782a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_places (0.28.0)
4
+ google_places (0.30.0)
5
5
  httparty (~> 0.13.1)
6
6
 
7
7
  GEM
@@ -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.29.0'
6
+ s.version = '0.30.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Marcel de Graaf']
9
9
  s.email = ['mail@marceldegraaf.net']
data/lib/google_places.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
3
 
4
- %w(client location prediction request spot error photo).each do |file|
4
+ %w(client location rectangle prediction request spot error photo).each do |file|
5
5
  require File.join(File.dirname(__FILE__), 'google_places', file)
6
6
  end
7
7
 
@@ -148,7 +148,42 @@ module GooglePlaces
148
148
  def spots_by_query(query, options = {})
149
149
  Spot.list_by_query(query, @api_key, @options.merge(options))
150
150
  end
151
-
151
+ # Search for Spots within a give SW|NE bounds with query
152
+ #
153
+ # @return [Array<Spot>]
154
+ # @param [Hash] bounds
155
+ # @param [String] api_key the provided api key
156
+ # @param [Hash] options
157
+ # @option bounds [String, Array] :start_point
158
+ # An array that contains the lat/lng pair for the first
159
+ # point in the bounds (rectangle)
160
+ # @option bounds [:start_point][String, Integer] :lat
161
+ # The starting point coordinates latitude value
162
+ # @option bounds [:start_point][String, Integer] :lng
163
+ # The starting point coordinates longitude value
164
+ # @option bounds [String, Array] :end_point
165
+ # An array that contains the lat/lng pair for the end
166
+ # point in the bounds (rectangle)
167
+ # @option bounds [:end_point][String, Integer] :lat
168
+ # The end point coordinates latitude value
169
+ # @option bounds [:end_point][String, Integer] :lng
170
+ # The end point coordinates longitude value
171
+ # @option options [String,Array] :query
172
+ # Restricts the results to Spots matching term(s) in the specified query
173
+ # @option options [String] :language
174
+ # The language code, indicating in which language the results should be returned, if possible.
175
+ # @option options [String,Array<String>] :exclude ([])
176
+ # A String or an Array of <b>types</b> to exclude from results
177
+ # @option options [Hash] :retry_options ({})
178
+ # A Hash containing parameters for search retries
179
+ # @option options [Object] :retry_options[:status] ([])
180
+ # @option options [Integer] :retry_options[:max] (0) the maximum retries
181
+ # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
182
+ #
183
+ # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
184
+ def spots_by_bounds(bounds, options = {})
185
+ Spot.list_by_bounds(bounds, @api_key, @options.merge(options))
186
+ end
152
187
  # Search for Spots with a pagetoken
153
188
  #
154
189
  # @return [Array<Spot>]
@@ -0,0 +1,13 @@
1
+ module GooglePlaces
2
+ class Rectangle
3
+ #The start_lat/lng pair values indicate the starting point of the rectangle
4
+ #The end_lat/lng pair values indicate the end point of the rectangle
5
+ def initialize(start_lat, start_lng, end_lat, end_lng)
6
+ @start_point, @end_point = [ ("%.8f"%start_lat), ("%.8f"%start_lng)], [("%.8f"%end_lat), ("%.8f"%end_lng) ]
7
+ end
8
+
9
+ def format
10
+ [ @start_point.join(','), @end_point.join(',') ].join('|')
11
+ end
12
+ end
13
+ end
@@ -127,6 +127,41 @@ module GooglePlaces
127
127
  request.parsed_response
128
128
  end
129
129
 
130
+ # Search for Spots within a give SW|NE bounds with query
131
+ #
132
+ # @return [Array<Spot>]
133
+ # @param [Hash] bounds
134
+ # @param [String] api_key the provided api key
135
+ # @param [Hash] options
136
+ # @option bounds [String, Integer] :se
137
+ # the southeast lat|lng pair
138
+ # @option bounds [:se][String, Integer] :lat
139
+ # the SE latitude
140
+ # @option bounds [:se][String, Integer] :lng
141
+ # the SE longitude
142
+ # @option bounds [:se][String, Integer] :lat
143
+ # the SE latitude
144
+ # @option bounds [:se][String, Integer] :lng
145
+ # the SE longitude
146
+ # @option options [String,Array] :query
147
+ # Restricts the results to Spots matching term(s) in the specified query
148
+ # @option options [String] :language
149
+ # The language code, indicating in which language the results should be returned, if possible.
150
+ # @option options [String,Array<String>] :exclude ([])
151
+ # A String or an Array of <b>types</b> to exclude from results
152
+ #
153
+ # @option options [Hash] :retry_options ({})
154
+ # A Hash containing parameters for search retries
155
+ # @option options [Object] :retry_options[:status] ([])
156
+ # @option options [Integer] :retry_options[:max] (0) the maximum retries
157
+ # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
158
+ #
159
+ # @see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 List of supported languages
160
+ # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
161
+ def self.spots_by_bounds(options = {})
162
+ request = new(TEXT_SEARCH_URL, options)
163
+ request.parsed_response
164
+ end
130
165
  # Search for Spots with a query
131
166
  #
132
167
  # @return [Array<Spot>]
@@ -268,7 +303,6 @@ module GooglePlaces
268
303
  retry_options[:status] ||= []
269
304
  retry_options[:max] ||= 0
270
305
  retry_options[:delay] ||= 5
271
-
272
306
  retry_options[:status] = [retry_options[:status]] unless retry_options[:status].is_a?(Array)
273
307
  @response = self.class.get(url, :query => options, :follow_redirects => follow_redirects)
274
308
 
@@ -1,5 +1,4 @@
1
1
  require 'google_places/review'
2
-
3
2
  module GooglePlaces
4
3
  class Spot
5
4
  attr_accessor :lat, :lng, :viewport, :name, :icon, :reference, :vicinity, :types, :id, :formatted_phone_number, :international_phone_number, :formatted_address, :address_components, :street_number, :street, :city, :region, :postal_code, :country, :rating, :url, :cid, :website, :reviews, :aspects, :zagat_selected, :zagat_reviewed, :photos, :review_summary, :nextpagetoken, :price_level, :opening_hours, :events, :utc_offset, :place_id
@@ -82,7 +81,74 @@ module GooglePlaces
82
81
 
83
82
  request(:spots, multipage_request, exclude, options)
84
83
  end
84
+ # Search for Spots within a give SW|NE bounds with query
85
+ #
86
+ # @return [Array<Spot>]
87
+ # @param [Hash] bounds
88
+ # @param [String] api_key the provided api key
89
+ # @param [Hash] options
90
+ # @option bounds [String, Array] :start_point
91
+ # An array that contains the lat/lng pair for the first
92
+ # point in the bounds (rectangle)
93
+ # @option bounds [:start_point][String, Integer] :lat
94
+ # The starting point coordinates latitude value
95
+ # @option bounds [:start_point][String, Integer] :lng
96
+ # The starting point coordinates longitude value
97
+ # @option bounds [String, Array] :end_point
98
+ # An array that contains the lat/lng pair for the end
99
+ # point in the bounds (rectangle)
100
+ # @option bounds [:end_point][String, Integer] :lat
101
+ # The end point coordinates latitude value
102
+ # @option bounds [:end_point][String, Integer] :lng
103
+ # The end point coordinates longitude value
104
+ # @option options [String,Array] :query
105
+ # Restricts the results to Spots matching term(s) in the specified query
106
+ # @option options [String] :language
107
+ # The language code, indicating in which language the results should be returned, if possible.
108
+ # @option options [String,Array<String>] :exclude ([])
109
+ # A String or an Array of <b>types</b> to exclude from results
110
+ #
111
+ # @option options [Hash] :retry_options ({})
112
+ # A Hash containing parameters for search retries
113
+ # @option options [Object] :retry_options[:status] ([])
114
+ # @option options [Integer] :retry_options[:max] (0) the maximum retries
115
+ # @option options [Integer] :retry_options[:delay] (5) the delay between each retry in seconds
116
+ #
117
+ # @see https://developers.google.com/maps/documentation/places/supported_types List of supported types
118
+ def self.list_by_bounds(bounds, api_key, options = {})
119
+ start_lat = bounds[:start_point][:lat]
120
+ start_lng = bounds[:start_point][:lng]
121
+ end_lat = bounds[:end_point][:lat]
122
+ end_lng = bounds[:end_point][:lng]
123
+ rect = Rectangle.new(start_lat, start_lng, end_lat, end_lng)
124
+ multipage_request = !!options.delete(:multipage)
125
+ rankby = options.delete(:rankby)
126
+ query = options.delete(:query)
127
+ name = options.delete(:name)
128
+ language = options.delete(:language)
129
+ exclude = options.delete(:exclude) || []
130
+ retry_options = options.delete(:retry_options) || {}
131
+ zagat_selected = options.delete(:zagat_selected) || false
132
+ exclude = [exclude] unless exclude.is_a?(Array)
133
+
134
+
135
+ options = {
136
+ :bounds => rect.format,
137
+ :key => api_key,
138
+ :language => language,
139
+ :retry_options => retry_options
140
+ }
85
141
 
142
+ options[:zagatselected] = zagat_selected if zagat_selected
143
+
144
+ # Accept Types as a string or array
145
+ if query
146
+ query = (query.is_a?(Array) ? query.join('|') : query)
147
+ options.merge!(:query => query)
148
+ end
149
+
150
+ request(:spots_by_bounds, multipage_request, exclude, options)
151
+ end
86
152
  # Search for Spots using Radar Search. Spots will only include reference and lat/lng information. You can send a Place Details request for more information about any of them.
87
153
  #
88
154
  # @return [Array<Spot>]
@@ -29,7 +29,14 @@ describe GooglePlaces::Client do
29
29
 
30
30
  @client.spots_by_query(query)
31
31
  end
32
-
32
+ it 'should request spots by bounds' do
33
+ query = 'pizza'
34
+ bounds = {:start_point => {:lat => '36.06686213257888', :lng => '-86.94168090820312'},
35
+ :end_point => {:lat => '36.268635800737876', :lng => '-86.66152954101562'}}
36
+ @client = GooglePlaces::Client.new(api_key)
37
+ expect(GooglePlaces::Spot).to receive(:list_by_bounds).with(bounds, api_key, {:query => query})
38
+ res = @client.spots_by_bounds(bounds, :query => query)
39
+ end
33
40
  it 'should request spots by radar' do
34
41
  keywords = 'landmarks'
35
42
  lat, lng = '51.511627', '-0.183778'
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe GooglePlaces::Rectangle do
4
+ it 'should return two lat/lng pairs separated by a "|" based on SW and NE lat/lng bounds' do
5
+ expect(GooglePlaces::Rectangle.new('123', '456', '321', '654').format).to eq('123.00000000,456.00000000|321.00000000,654.00000000')
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_places
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcel de Graaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -88,6 +88,7 @@ files:
88
88
  - lib/google_places/location.rb
89
89
  - lib/google_places/photo.rb
90
90
  - lib/google_places/prediction.rb
91
+ - lib/google_places/rectangle.rb
91
92
  - lib/google_places/request.rb
92
93
  - lib/google_places/review.rb
93
94
  - lib/google_places/spot.rb
@@ -98,6 +99,7 @@ files:
98
99
  - spec/google_places/location_spec.rb
99
100
  - spec/google_places/photo_spec.rb
100
101
  - spec/google_places/prediction_spec.rb
102
+ - spec/google_places/rectangle.rb
101
103
  - spec/google_places/request_spec.rb
102
104
  - spec/google_places/spot_spec.rb
103
105
  - spec/spec_helper.rb
@@ -148,6 +150,7 @@ test_files:
148
150
  - spec/google_places/location_spec.rb
149
151
  - spec/google_places/photo_spec.rb
150
152
  - spec/google_places/prediction_spec.rb
153
+ - spec/google_places/rectangle.rb
151
154
  - spec/google_places/request_spec.rb
152
155
  - spec/google_places/spot_spec.rb
153
156
  - spec/spec_helper.rb