Class: CoffeeHunt::API
- Inherits:
-
Object
- Object
- CoffeeHunt::API
- Defined in:
- lib/Coffee_Hunt/api.rb
Constant Summary collapse
- API_HOST =
"https://api.yelp.com"
- SEARCH_PATH =
"/v3/businesses/search"
- BUSINESS_PATH =
"/v3/businesses/"
Class Method Summary collapse
Class Method Details
.api_key ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/Coffee_Hunt/api.rb', line 13 def self.api_key begin @@key = File.open(File.("~/.yelp-api-key")).read.strip rescue puts "Uh Oh! Looks like you are missing your Yelp API key! You can sign up for a new key and enter it or exit the CLI." @@key = gets.strip return if @@key == "exit" File.open(File.("~/.yelp-api-key"), "w") do |file| file.print @@key end end @@key end |
.yelp_search(term, location) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Coffee_Hunt/api.rb', line 28 def self.yelp_search(term, location) url = "#{API_HOST}#{SEARCH_PATH}" params = { term: term, location: location } response = HTTP.auth("Bearer #{api_key}").get(url, params: params) JSON.parse(response)["businesses"] end |