Class: Foodpairing

Inherits:
Object
  • Object
show all
Defined in:
lib/foodpairing.rb

Overview

Dotenv.load(‘variables.env’)

Class Method Summary collapse

Class Method Details

.get_all_brandsObject



38
39
40
41
# File 'lib/foodpairing.rb', line 38

def self.get_all_brands
  response = HTTParty.get("https://api.foodpairing.com/brands", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @brands = JSON.parse(response.body)
end

.get_all_ingredientsObject



13
14
15
16
# File 'lib/foodpairing.rb', line 13

def self.get_all_ingredients
  response = HTTParty.get("https://api.foodpairing.com/ingredients/", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @ingredients = JSON.parse(response.body)
end

.get_brand_by_id(id) ⇒ Object



43
44
45
46
# File 'lib/foodpairing.rb', line 43

def self.get_brand_by_id(id)
  response = HTTParty.get("https://api.foodpairing.com/brands/#{id}", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @brand = JSON.parse(response.body)
end

.get_ingredient_by_id(id) ⇒ Object



8
9
10
11
# File 'lib/foodpairing.rb', line 8

def self.get_ingredient_by_id(id)
  response = HTTParty.get("https://api.foodpairing.com/ingredients/#{id}", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @ingredient = JSON.parse(response.body)
end

.get_ingredient_nutrients(id) ⇒ Object



33
34
35
36
# File 'lib/foodpairing.rb', line 33

def self.get_ingredient_nutrients(id)
  response = HTTParty.get("https://api.foodpairing.com/ingredients/#{id}/nutrients", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @nutrients = JSON.parse(response.body)
end

.get_pairings_for_ingredient(id) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/foodpairing.rb', line 23

def self.get_pairings_for_ingredient(id)
  @pairings_array = []
  response = HTTParty.get("https://api.foodpairing.com/ingredients/#{id}/pairings", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @pairings_object = JSON.parse(response.body)
  @pairings_object.each do |pairing|
    @pairings_array.push(pairing["_links"]["ingredient"]["name"])
  end
  @pairings_array
end

.search_ingredients_by_name(name) ⇒ Object



18
19
20
21
# File 'lib/foodpairing.rb', line 18

def self.search_ingredients_by_name(name)
  response = HTTParty.get("https://api.foodpairing.com/ingredients?q=#{name}", headers: { 'X-Application-ID' => ENV['XApplicationID'], 'X-Application-Key' => ENV['XApplicationKey'] })
  @ingredients = JSON.parse(response.body)
end