def search_yelp body
client = Yelp::Fusion::Client.new(API_KEY)
location = "#{session["zipcode"]}"
params = {
term: "#{session["current_problem"]}",
limit: 3
}
response = client.search(location, params)
# puts message.businesses.to_s
# [<Business 1>, <Business 2>, ...]
num_responses = response.businesses.count
if num_responses < 1
puts "Didn't find any matching businesses"
return "Didn't find any matching businesses"
elsif num_responses == 1
name = response.businesses.first.name
rating = response.businesses.first.phone
phone = response.businesses.first.rating
str = "I found one business: #{ name } with a rating of #{rating}. You can call them at #{phone}"
puts str
return str
else
str = "I found a few business 👍🏼: \n"
for i in 0..2
name = response.businesses[i].name
rating = response.businesses[i].rating
phone = response.businesses[i].phone
str +="#{ name } with a rating of #{rating}. You can call them at #{phone}. \n"
end
puts str
return str
end
end
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .