everything-but-the-kitchen-sink 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e0586fe6f8dbbe17a38f13d0f33d29abbaf7ea0d40c1a0defe489bd2148b54e
4
+ data.tar.gz: 972833e31d429fb996e5db4b1883fba7cbbc0839dc8e2ef13576818182f1d7b4
5
+ SHA512:
6
+ metadata.gz: df575e0bdfd935551f27c282befdf42193bf00b48844ece9e71a860330df5e5405bc125b5ff9672bdffd843e8bfe54aa7186c4855628b8a130f28e1b258553f3
7
+ data.tar.gz: 2f0ebb823314b1ceac14c74de6bfb4e2ed338455425793fb899d86eb0f9a898a0f626e915806a34a049a2cf8bbf92ffa15cba318b04a333b2025c63df4114641
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../config/environment.rb'
4
+ # require_relative '../lib/recipe_cli/cli.rb'
5
+
6
+ EverythingButTheKitchenSink::CLI.new.call
7
+
8
+ #need to be abel to start from within the EverythingButTheKitchenSink module??
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+
5
+ module EverythingButTheKitchenSink
6
+ end
7
+
8
+
9
+ require_relative '../lib/recipe_cli/cli.rb'
10
+ require_relative '../lib/recipe_cli/recipe.rb'
11
+ require_relative '../lib/recipe_cli/spoonacular_api.rb'
12
+ require_relative '../lib/recipe_cli/transform_data.rb'
@@ -0,0 +1,96 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'dotenv/load'
4
+
5
+ class EverythingButTheKitchenSink::CLI
6
+
7
+ #call will be used to run function (will call methods in order of how they should execute)
8
+ def call
9
+ shouldContinue = true
10
+ listEmpty = false
11
+ welcome_message
12
+ enter_ingredients
13
+ while !listEmpty && shouldContinue
14
+ listEmpty = display_recipe_list
15
+ if !listEmpty
16
+ recipe = user_recipe_choice
17
+ display_recipe_time_and_link(recipe)
18
+ shouldContinue = other_options
19
+ end
20
+ end
21
+ end
22
+
23
+ #will print welcome message
24
+ def welcome_message
25
+ puts "Welcome to Everything but the Kitchen Sink!"
26
+ end
27
+
28
+ #will prompt/gets ingredients and send to API class
29
+ def enter_ingredients
30
+ puts "\nPlease input your ingredients below. Separate each ingredient with a comma.\n"
31
+
32
+ ingredients = gets.strip
33
+ recipes = EverythingButTheKitchenSink::SpoonacularApi.get_recipes(ingredients)
34
+ EverythingButTheKitchenSink::TransformData.get_id_and_title(recipes)
35
+ end
36
+
37
+ #will print out numbered recipe list
38
+ def display_recipe_list
39
+ if EverythingButTheKitchenSink::Recipe.all.count == 0
40
+ return true
41
+ else
42
+ EverythingButTheKitchenSink::Recipe.all.each_with_index do |recipe, index|
43
+ puts (index + 1).to_s + "." + recipe.title
44
+ end
45
+ return false
46
+ end
47
+ end
48
+
49
+ #will prompt/gets recipe choice and will send to api. will call Recipe class object to add info
50
+ def user_recipe_choice
51
+ puts "\nWhich recipe would you like to see?\nPlease input the recipe number:\n"
52
+
53
+ input = gets.strip
54
+ if valid_recipe_choice(input)
55
+ recipe_index = (input.to_i - 1)
56
+
57
+ attributes = EverythingButTheKitchenSink::SpoonacularApi.recipe_info(recipe_index)
58
+ recipe_object = EverythingButTheKitchenSink::Recipe.all[recipe_index]
59
+ EverythingButTheKitchenSink::TransformData.get_time_and_url(attributes, recipe_object)
60
+ recipe_object
61
+ else
62
+ user_recipe_choice
63
+ end
64
+ end
65
+
66
+ #checks if recipe choice number is valid choice
67
+ def valid_recipe_choice(input)
68
+ input.to_i.between?(1,10)
69
+ end
70
+
71
+ #will print recipe info (time and link)
72
+ def display_recipe_time_and_link(recipe)
73
+ puts "\nThis meal can be ready in " + recipe.time.to_s + " minutes.\nFor detailed instructions go to: " + recipe.url
74
+ end
75
+
76
+ #prompt user for other options; will take in yes/no and either loop through or exit function and call leave method
77
+ def other_options
78
+ puts "\nWould you like to see another recipe?\nPlease enter 'Yes' or 'No':"
79
+
80
+ input = ""
81
+ while input
82
+ input = gets.strip.upcase
83
+ case input
84
+ when "YES"
85
+ return true
86
+ when "NO"
87
+ puts "\nEnjoy your meal!"
88
+ return false
89
+ else
90
+ puts "\nPlease enter 'Yes' or 'No'."
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ end
@@ -0,0 +1,26 @@
1
+ class EverythingButTheKitchenSink::Recipe
2
+
3
+ attr_accessor :id, :title, :url, :time
4
+ @@all = []
5
+
6
+ def initialize(recipe_data)
7
+ recipe_data.each {|key, value| self.send(("#{key}="), value)}
8
+ @id = recipe_data[:id]
9
+ @title = recipe_data[:title]
10
+ save
11
+ end
12
+
13
+ def additional_recipe_info(recipe_info) # This should be handled using individual setter functions (recipe.setTime / recipe.time = {time})
14
+ @time = recipe_info[:readyInMinutes]
15
+ @url = recipe_info[:sourceUrl]
16
+ end
17
+
18
+ def save
19
+ @@all << self
20
+ end
21
+
22
+ def self.all
23
+ @@all
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ class EverythingButTheKitchenSink::SpoonacularApi
2
+
3
+ # key = 3705831af10240c595aa20e41ae1f8b5
4
+ # key = 786b7fc42de54bfcb1fe1fb99e697d4d
5
+
6
+ #send ingredients to API to get recipes
7
+ def self.get_recipes(ingredients)
8
+ url = "https://api.spoonacular.com/recipes/findByIngredients?apiKey=3705831af10240c595aa20e41ae1f8b5&ingredients=" + ingredients
9
+ response = RestClient.get(url, headers={})
10
+ recipes = JSON.parse(response)
11
+ end
12
+
13
+ #will send recipe id to API to get additional info
14
+ def self.recipe_info(recipe_index)
15
+ recipe_object = EverythingButTheKitchenSink::Recipe.all[recipe_index]
16
+ recipe_id = recipe_object.id
17
+ url = "https://api.spoonacular.com/recipes/#{recipe_id}/information?apiKey=3705831af10240c595aa20e41ae1f8b5&includeNutrition=true."
18
+ response = RestClient.get(url, headers={})
19
+ attributes = JSON.parse(response)
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+
3
+ class EverythingButTheKitchenSink::TransformData
4
+
5
+ def self.get_id_and_title(recipes)
6
+ if recipes.count == 0
7
+ puts "Sorry, I couldn't find any recipes with those ingredients."
8
+ else
9
+ recipes.each do |recipe|
10
+ recipe_data = {}
11
+ recipe_data[:id] = recipe["id"]
12
+ recipe_data[:title] = recipe["title"]
13
+ EverythingButTheKitchenSink::Recipe.new(recipe_data)
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.get_time_and_url(attributes, recipe_object)
19
+ recipe_info = {}
20
+ recipe_info[:readyInMinutes] = attributes["readyInMinutes"]
21
+ recipe_info[:sourceUrl] = attributes["sourceUrl"]
22
+ recipe_object.additional_recipe_info(recipe_info)
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: everything-but-the-kitchen-sink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amanda Mongiove
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ description: Provides recipes based on ingredients you have.
56
+ email: amandamongiove@gmail.com
57
+ executables:
58
+ - everythingbut
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - bin/everythingbut
63
+ - config/environment.rb
64
+ - lib/recipe_cli/cli.rb
65
+ - lib/recipe_cli/recipe.rb
66
+ - lib/recipe_cli/spoonacular_api.rb
67
+ - lib/recipe_cli/transform_data.rb
68
+ homepage: http://rubygems.org/gems/everything-but-the-kitchen-sink
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.0.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Everything but the Kitchen Sink
91
+ test_files: []