require File.dirname(__FILE__) + '/../lib/yelp4r'
# Read the Yelp API Documentation
# http://www.yelp.com/developers/documentation
# Initialize a new Yelp Client
client = Yelp4r::Client.new('your_ywsid_key')
# Initialize a new Phone Search object
phone_search = Yelp4r::PhoneSearch.new(client)
# Phone search only does one thing, looks up a business by a phone number
results = phone_search.search_by_phone_number('1234567890')
# A response object is returned
# The following response methods are available to all Yelp searches in the 3 search classes
# PhoneSearch, ReveiwSearch, NeighborhoodSearch
if results.success?
puts results.data # Pure data of the repsonse
puts results.body # Entire body of the response
else
puts results.reponse_code # Yelp repsonse code
puts results.error_message # The text of the error message
end
# Initialize a Neighborhood Search Object
neigh_search = Yelp4r::NeighborhoodSearch.new(client)
# Search by a geocode point
# Pass a Lat and Long respectively
results = neigh_search.search_by_geocode(37.788022, -122.399797)
# Search by a location (with optional country code)
results = neigh_search.search_by_location('Boston, MA')
# or
results = neigh_search.search_by_location('Boston, MA', 'US')
# Again the response methods above apply here as well
# Initialize a Review Search Object
review_search = Yelp4r::ReviewSearch.net(client)
# Each search method for the review_search object takes the following optional parameters
# :category => this is a Yelp category term (see the categories list below)
# :term => this is a search term
# :num_biz_requested => a number 1 through 20 (default is 10)
# Search by a bouding box
# Pass a top left lat/long and bottom right lat/long
results = review_search.search_by_bounding_box(38, -122.6, 37.788022, -122.399797)
results = review_search.search_by_bounding_box(38, -122.6, 37.788022, -122.399797, :term => "bars", :num_biz_requested => 15)
# Search by geocode and radius
# This method accepts and optional param of
# :radius => max of 25
results = review_search.search_by_geocode_and_radius(37.788022, -122.399797)
results = review_search.search_by_geocode_and_radius(37.788022, -122.399797, :radius => .5)
results = review_search.search_by_geocode_and_radius(37.788022, -122.399797, :category => "bars", :radius => 1)
# Search by location
# This method accepts and optional params of:
# :radius => max of 25
# :cc => country code
results = review_search.search_by_location('Boston, MA')
results = review_search.search_by_location('Boston, MA', :num_biz_requested => 10)
results = review_search.search_by_location('Boston, MA', :radius => 5)
results = review_search.search_by_location('Boston, MA', :term => "doctors")
# Again the response methods above apply here as well
# Yelp4r provides a couple of html parsed lists powered by Hpricot
# This first is the list of neighborhoods
# see the page here: http://www.yelp.com/developers/documentation/neighborhood_list
# Create a new Neighborhoods object
neighborhoods = Yelp4r::Neighborhoods.new
# Get the list
# This list is designed to keep the parent and its children in a hash with the parent being the key and the children in an array
# which is generated by a recursive function
# see the spec_helper method yelp4r_test_neighs_list for an example.
puts neighborhoods.list
# There is also a method to return a list of