Class: BizRatr::YelpConnector

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

Instance Method Summary collapse

Methods inherited from Connector

#initialize

Constructor Details

This class inherits a constructor from BizRatr::Connector

Instance Method Details

#make_business(item) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/bizratr/connector.rb', line 152

def make_business(item)
  b = Business.new(@uberclient, item['location']['coordinate']['latitude'], item['location']['coordinate']['longitude'], item['name'])
  b.add_id(:yelp, item['id'])
  b.add_categories(:yelp, item['categories'].map(&:first))
  b.state = item['location']['state_code']
  b.zip = item['location']['postal_code']
  b.country = item['location']['country_code']
  b.city = item['location']['city']
  b.address = item['location']['address'].first
  b.phone = (item['phone'] || "").gsub(/[\ ()-]*/, '')
  b.add_rating(:yelp, item['rating'])
  b.add_review_counts(:yelp, item['review_count'])
  b
end

#make_client(config) ⇒ Object



138
139
140
# File 'lib/bizratr/connector.rb', line 138

def make_client(config)
  Yelp::Client.new
end

#search_location(location, query) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/bizratr/connector.rb', line 142

def search_location(location, query)
  # while yelp does support searching by address, it does so much more shittily w/o lat/lon
  location = geocode(location) if location.is_a? String
  config = { :term => query, :latitude => location.first, :longitude => location.last }
  result = @client.search Yelp::V2::Search::Request::GeoPoint.new(config.merge(@config)) 
  result['businesses'].map { |item| 
    make_business(item) 
  }
end