Class: GooglePlacesAutocomplete::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/google_places_autocomplete/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @api_key = options[:api_key] || GooglePlaces.api_key
end

Instance Attribute Details

#api_keyObject (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(options={})
  sensor = options.delete(:sensor) || false
  types  = options.delete(:types)
  language  = options.delete(:language) || nil
  input  = options.delete(:input)
  offset = options.delete(:offset) || nil
  radius = options.delete(:radius) || nil
  lat = options.delete(:lat) || nil
  lng = options.delete(:lng) || nil
  location = [lat,lng].join(',') if lat && lng
  sw_bounds = [options[:sw_bounds].delete(:lat),options[:sw_bounds].delete(:lng)].join(',') if options[:sw_bounds] && options[:sw_bounds][:lat] && options[:sw_bounds][:lng]
  ne_bounds = [options[:ne_bounds].delete(:lat),options[:ne_bounds].delete(:lng)].join(',') if options[:ne_bounds] && options[:ne_bounds][:lat] && options[:ne_bounds][:lng]
  bounds = [sw_bounds,ne_bounds].join('|') if sw_bounds && ne_bounds
  components = options.delete(:components) || nil
  user_ip = options.delete(:user_ip) ||  nil
  quota_user = options.delete(:quota_user) || nil
  session_token = options.delete(:session_token) || nil

  options = {
    :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)
    options.merge!(:types => types)
  end

  options = options.delete_if {|key, value| value.nil?}
  mashup(self.class.get("/autocomplete/json", :query => options.merge(self.default_options)))
end

#details(options = {}) ⇒ Object



55
56
57
58
# File 'lib/google_places_autocomplete/client.rb', line 55

def details(options={})
  options.delete(:reference) if options[:placeid]
  mashup(self.class.get("/details/json", :query => options.merge(self.default_options)))
end