Class: BizRatr::YelpConnector

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

Instance Method Summary collapse

Methods inherited from Connector

#geocode

Constructor Details

#initialize(config) ⇒ YelpConnector

Returns a new instance of YelpConnector.



75
76
77
78
# File 'lib/bizratr/connector.rb', line 75

def initialize(config)
  @config = config
  @client = Yelp::Client.new
end

Instance Method Details

#make_business(item) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bizratr/connector.rb', line 90

def make_business(item)
  b = Business.new(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']
  b.add_rating(:yelp, item['rating'])
  b.add_review_counts(:yelp, item['review_count'])
  b
end

#search_location(location, query) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/bizratr/connector.rb', line 80

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