Class: BizRatr::UberClient

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ UberClient

Returns a new instance of UberClient.



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/bizratr/connector.rb', line 169

def initialize(config)
  @connectors = {}
  config.each { |key, value| 
    @connectors[key] = case key
                       when :foursquare then FourSquareConnector.new(self, value)
                       when :yelp then YelpConnector.new(self, value)
                       when :google_places then GooglePlacesConnector.new(self, value)
                       when :factual then FactualConnector.new(self, value)
                       when :facebook then FacebookConnector.new(self, value)
                       else raise "No such connector found: #{key}"
                       end
  }
end

Instance Method Details

#geocode(address) ⇒ Object



193
194
195
# File 'lib/bizratr/connector.rb', line 193

def geocode(address)
  Geocoder.coordinates(address)
end

#get_connector(key) ⇒ Object



197
198
199
# File 'lib/bizratr/connector.rb', line 197

def get_connector(key)
  @connectors.fetch(key, nil)
end

#search_location(location, query) ⇒ Object

Search for a business (or business category) near lat/lon coordinates. The location parameter should be either an address string or an array consisting of [ lat, lon ].



186
187
188
189
190
191
# File 'lib/bizratr/connector.rb', line 186

def search_location(location, query)
  location = geocode(location) if location.is_a? String
  merge @connectors.values.map { |c|
    c.search_location(location, query)
  }
end

#search_location_strictly(location, name) ⇒ Object

Search a location (just like search_location) but only return the best matching business (based on name).



203
204
205
206
207
# File 'lib/bizratr/connector.rb', line 203

def search_location_strictly(location, name)
  search_location(location, name).inject(nil) { |a,b|
    (a.nil? or b.name_distance_to(name) < a.name_distance_to(name)) ? b : a
  }
end