Class: GoogleMaps::Services::Places
- Inherits:
-
Object
- Object
- GoogleMaps::Services::Places
- Defined in:
- lib/googlemaps/services/places.rb
Overview
Performs requests to the Google Places API.
Instance Attribute Summary collapse
-
#client ⇒ Symbol
The HTTP client.
Instance Method Summary collapse
-
#autocomplete(input_text:, offset: nil, location: nil, radius: nil, language: nil, types: nil, components: nil, strict_bounds: false) ⇒ Array, Nokogiri::XML::NodeSet
Returns Place predictions given a textual search string and optional geographic bounds.
-
#autocomplete_query(input_text:, offset: nil, location: nil, radius: nil, language: nil) ⇒ Array, Nokogiri::XML::NodeSet
Returns Place predictions given a textual search query, such as “pizza near Brussels”, and optional geographic bounds.
-
#initialize(client) ⇒ Places
constructor
A new instance of Places.
-
#nearby(location: nil, radius: nil, keyword: nil, language: nil, min_price: nil, max_price: nil, name: nil, open_now: false, rank_by: nil, type: nil, page_token: nil) ⇒ Hash, Nokogiri::XML::Document
Performs nearby search for places.
-
#place_details(place_id:, language: nil) ⇒ Hash, Nokogiri::XML::Document
Comprehensive details for an individual place.
-
#place_photo(photo_reference:, max_width: nil, max_height: nil) ⇒ String
Downloads a photo from the Places API.
-
#radar(location:, radius:, keyword: nil, min_price: nil, max_price: nil, name: nil, open_now: false, type: nil) ⇒ Hash, Nokogiri::XML::Document
Performs radar search for places.
-
#search(query:, location: nil, radius: nil, language: nil, min_price: nil, max_price: nil, open_now: false, type: nil, region: nil, page_token: nil) ⇒ Hash, Nokogiri::XML::Document
Performs places search.
Constructor Details
#initialize(client) ⇒ Places
Returns a new instance of Places.
11 12 13 |
# File 'lib/googlemaps/services/places.rb', line 11 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Symbol
Returns The HTTP client.
9 10 11 |
# File 'lib/googlemaps/services/places.rb', line 9 def client @client end |
Instance Method Details
#autocomplete(input_text:, offset: nil, location: nil, radius: nil, language: nil, types: nil, components: nil, strict_bounds: false) ⇒ Array, Nokogiri::XML::NodeSet
Returns Place predictions given a textual search string and optional geographic bounds.
195 196 197 198 199 |
# File 'lib/googlemaps/services/places.rb', line 195 def autocomplete(input_text:, offset: nil, location: nil, radius: nil, language: nil, types: nil, components: nil, strict_bounds: false) _autocomplete(url_part: "", input_text: input_text, offset: offset, location: location, radius: radius, language: language, types: types, components: components, strict_bounds: strict_bounds) end |
#autocomplete_query(input_text:, offset: nil, location: nil, radius: nil, language: nil) ⇒ Array, Nokogiri::XML::NodeSet
Returns Place predictions given a textual search query, such as “pizza near Brussels”, and optional geographic bounds.
210 211 212 213 |
# File 'lib/googlemaps/services/places.rb', line 210 def autocomplete_query(input_text:, offset: nil, location: nil, radius: nil, language: nil) _autocomplete(url_part: 'query', input_text: input_text, offset: offset, location: location, radius: radius, language: language) end |
#nearby(location: nil, radius: nil, keyword: nil, language: nil, min_price: nil, max_price: nil, name: nil, open_now: false, rank_by: nil, type: nil, page_token: nil) ⇒ Hash, Nokogiri::XML::Document
Performs nearby search for places.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/googlemaps/services/places.rb', line 51 def nearby(location: nil, radius: nil, keyword: nil, language: nil, min_price: nil, max_price: nil, name: nil, open_now: false, rank_by: nil, type: nil, page_token: nil) if !location && !page_token raise StandardError, 'either a location or page_token is required.' end if rank_by == 'distance' if !(keyword || name || type) raise StandardError, 'either a keyword, name or type arg is required when rank_by is set to distance.' elsif radius raise StandardError, 'radius cannot be specified when rank_by is set to distance.' end end _places(url_part: 'nearby', location: location, radius: radius, keyword: keyword, language: language, min_price: min_price, max_price: max_price, name: name, open_now: open_now, rank_by: rank_by, type: type, page_token: page_token) end |
#place_details(place_id:, language: nil) ⇒ Hash, Nokogiri::XML::Document
Comprehensive details for an individual place.
151 152 153 154 155 156 157 158 |
# File 'lib/googlemaps/services/places.rb', line 151 def place_details(place_id:, language: nil) params = {'placeid' => place_id} if language params['language'] = language end self.client.request(url: "/maps/api/place/details/#{self.client.response_format}", params: params) end |
#place_photo(photo_reference:, max_width: nil, max_height: nil) ⇒ String
Downloads a photo from the Places API.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/googlemaps/services/places.rb', line 167 def place_photo(photo_reference:, max_width: nil, max_height: nil) raise StandardError, 'a max_width or max_height arg is required' unless (max_width || max_height) params = {'photoreference' => photo_reference} if max_width params['maxwidth'] = max_width end if max_height params['maxheight'] = max_height end self.client.request(url: '/maps/api/place/photo', params: params) end |
#radar(location:, radius:, keyword: nil, min_price: nil, max_price: nil, name: nil, open_now: false, type: nil) ⇒ Hash, Nokogiri::XML::Document
Performs radar search for places.
81 82 83 84 85 86 87 88 89 |
# File 'lib/googlemaps/services/places.rb', line 81 def radar(location:, radius:, keyword: nil, min_price: nil, max_price: nil, name: nil, open_now: false, type: nil) warn '[DEPRECATION] Places Radar is deprecated as of June 30, 2018. After that time, this feature will no longer be available.' raise StandardError, 'either a keyword, name, or type arg is required.' unless (keyword || name || type) _places(url_part: 'radar', location: location, radius: radius, keyword: keyword, min_price: min_price, max_price: max_price, name: name, open_now: open_now, type: type) end |
#search(query:, location: nil, radius: nil, language: nil, min_price: nil, max_price: nil, open_now: false, type: nil, region: nil, page_token: nil) ⇒ Hash, Nokogiri::XML::Document
Performs places search.
29 30 31 32 33 34 |
# File 'lib/googlemaps/services/places.rb', line 29 def search(query:, location: nil, radius: nil, language: nil, min_price: nil, max_price: nil, open_now: false, type: nil, region: nil, page_token: nil) _places(url_part: 'text', query: query, location: location, radius: radius, language: language, min_price: min_price, max_price: max_price, open_now: open_now, type: type, region: region, page_token: page_token) end |