Class: BizRatr::GooglePlacesConnector

Inherits:
Connector
  • Object
show all
Defined in:
lib/bizratr/connector.rb

Instance Method Summary collapse

Methods inherited from Connector

#geocode

Constructor Details

#initialize(config) ⇒ GooglePlacesConnector

Returns a new instance of GooglePlacesConnector.



19
20
21
# File 'lib/bizratr/connector.rb', line 19

def initialize(config)
  @client = GooglePlaces::Client.new(config[:key])
end

Instance Method Details

#make_business(item) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bizratr/connector.rb', line 29

def make_business(item)
  b = Business.new(item.lat, item.lng, item.name)
  b.add_id(:google_places, item.id)
  b.add_categories(:google_places, item.types)
  b.phone = item.formatted_phone_number
  b.city = item.city || item.vicinity.split(',').last
  b.country = item.country
  b.zip = item.postal_code
  b.address = item.vicinity.split(',').first
  b.add_rating(:google_places, item.rating)
  b
end

#search_location(location, query) ⇒ Object



23
24
25
26
27
# File 'lib/bizratr/connector.rb', line 23

def search_location(location, query)
  location = geocode(location) if location.is_a? String
  results = @client.spots(location[0], location[1], :name => query)
  results.map { |item| make_business(item) }
end