-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.rb
58 lines (51 loc) · 1.53 KB
/
info.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rest-client'
require 'json'
require 'pry'
def make_api_call(url)
authorization_hash = {
content_type: "application/json;charset=utf-8",
authorization: "Bearer API_KEY"
}
response = RestClient.get url, headers = authorization_hash
JSON.parse(response.body)
end
def get_restaurants(location, search_term = nil)
search_term ? additional_search_term = "+#{search_term}" : additional_search_term = ""
url = "https://api.yelp.com/v3/businesses/search?term=restaurants#{additional_search_term}&location=#{location}x&limit=10"
make_api_call(url)
end
def get_resturant_info(yelp_business_id)
url = "https://api.yelp.com/v3/businesses/#{yelp_business_id}"
make_api_call(url)
end
def get_restaurant_reviews(yelp_business_id)
url = "https://api.yelp.com/v3/businesses/#{yelp_business_id}/reviews"
make_api_call(url)
end
def parse_restaurants(location, term)
result = get_restaurants(location, term)
business_array = result['businesses'].map do |h|
{
yelp_id: h['id'],
name: h['name'],
image_url: h['image_url'],
categories: h['categories'][0]['title'],
rating: h['rating'],
address: h['location']['display_address'].join(', ')
}
end
end
def parse_reviews_and_customers(yelp_business_id)
result = get_restaurant_reviews(yelp_business_id)['reviews']
result.map do |h|
{
rating: h['rating'],
text: h['text'],
user: {
name: h['user']['name'],
profile_url: h['user']['profile_url'],
image_url: h['user']['image_url']
}
}
end
end