class APIService

Public Class Methods

fetch_random() click to toggle source
# File lib/api.rb, line 4
def self.fetch_random
    response = HTTParty.get('https://www.thecocktaildb.com/api/json/v1/1/random.php')
    response.parsed_response["drinks"][0]
end
search_by_id(drink_id) click to toggle source
# File lib/api.rb, line 25
def self.search_by_id(drink_id)
    link = "https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=" + drink_id
    response = HTTParty.get(link)
    response.parsed_response["drinks"][0]
end
search_by_ingredient(ingredient) click to toggle source
# File lib/api.rb, line 15
def self.search_by_ingredient(ingredient)
    link = "https://www.thecocktaildb.com/api/json/v1/1/filter.php?i=" + ingredient
    response = HTTParty.get(link)
    if response.parsed_response != nil
        response.parsed_response["drinks"]
    else
        nil
    end
end
search_by_name(name) click to toggle source
# File lib/api.rb, line 9
def self.search_by_name(name)
    link = "https://www.thecocktaildb.com/api/json/v1/1/search.php?s=" + name
    response = HTTParty.get(link)
    response.parsed_response["drinks"]
end