Class: GooglePlacesAutocomplete::Client
- Inherits:
-
Object
- Object
- GooglePlacesAutocomplete::Client
- Includes:
- HTTParty
- Defined in:
- lib/google_places_autocomplete/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #autocomplete(options = {}) ⇒ Object
- #details(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/google_places_autocomplete/client.rb', line 10 def initialize(={}) @api_key = [:api_key] || GooglePlaces.api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/google_places_autocomplete/client.rb', line 8 def api_key @api_key end |
Instance Method Details
#autocomplete(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/google_places_autocomplete/client.rb', line 14 def autocomplete(={}) sensor = .delete(:sensor) || false types = .delete(:types) language = .delete(:language) || nil input = .delete(:input) offset = .delete(:offset) || nil radius = .delete(:radius) || nil lat = .delete(:lat) || nil lng = .delete(:lng) || nil location = [lat,lng].join(',') if lat && lng sw_bounds = [[:sw_bounds].delete(:lat),[:sw_bounds].delete(:lng)].join(',') if [:sw_bounds] && [:sw_bounds][:lat] && [:sw_bounds][:lng] ne_bounds = [[:ne_bounds].delete(:lat),[:ne_bounds].delete(:lng)].join(',') if [:ne_bounds] && [:ne_bounds][:lat] && [:ne_bounds][:lng] bounds = [sw_bounds,ne_bounds].join('|') if sw_bounds && ne_bounds components = .delete(:components) || nil user_ip = .delete(:user_ip) || nil quota_user = .delete(:quota_user) || nil session_token = .delete(:session_token) || nil = { :location => location, :radius => radius, :language => language, :sensor => sensor, :input => input, :offset => offset, :bounds => bounds, :components => components, :userIp => user_ip, :quotaUser => quota_user, :sessiontoken => session_token } if types types = (types.is_a?(Array) ? types.join('|') : types) .merge!(:types => types) end = .delete_if {|key, value| value.nil?} mashup(self.class.get("/autocomplete/json", :query => .merge(self.))) end |
#details(options = {}) ⇒ Object
55 56 57 58 |
# File 'lib/google_places_autocomplete/client.rb', line 55 def details(={}) .delete(:reference) if [:placeid] mashup(self.class.get("/details/json", :query => .merge(self.))) end |