Healthy_hunger_api 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/Healthy_hunger_api-0.1.0.gem +0 -0
- data/Healthy_hunger_api.gemspec +31 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/bin/Healthy_hunger_api +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/Healthy_hunger_api.rb +9 -0
- data/lib/Healthy_hunger_api/api.rb +78 -0
- data/lib/Healthy_hunger_api/cli.rb +205 -0
- data/lib/Healthy_hunger_api/meals.rb +92 -0
- data/lib/Healthy_hunger_api/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc7385b0e9689cef6944668d497e7fda8d4ef17f434b2040113023985fb37880
|
4
|
+
data.tar.gz: 64490cc6c8774b1aee964a157b6dac649612f25d5f1aaba4cd38bff6f775b2fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f5c737dc91997f6b3965491260b7d2e899402b920fa507936eca6878b011dd042dcb23ffff98a674dfc45a16e89b67d2c18a3daafad1e112b15b0e4a825bc06
|
7
|
+
data.tar.gz: 7e277d8f313420250a1d90bd95f3fe01dc6ad3b2c899e2ca7457fb84b2e5e862340aa39c279c0c02e3c82bb7586a3525056ff7b1ed96321b361216eccf6e3731
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sean.j.bordelon@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
Healthy_hunger_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.2)
|
10
|
+
rake (12.3.2)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
Healthy_hunger_api!
|
30
|
+
rake (~> 12.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/Healthy_hunger_api/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "Healthy_hunger_api"
|
5
|
+
spec.version = HealthyHungerApi::VERSION
|
6
|
+
spec.authors = ["Sean Bordelon"]
|
7
|
+
spec.email = ["sean.j.bordelon@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Displays a List of created meals from Recipe-Food-Nutrition API}
|
10
|
+
spec.description = %q{CLI program for getting a List of created meals and providing a summary from Recipe-Food-Nutrition API}
|
11
|
+
spec.homepage = "https://github.com/lsuman83/Healthy_hunger_api"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/lsuman83/Healthy_hunger_api"
|
19
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
#spec.bindir = "exe"
|
27
|
+
spec.executables = ["Healthy_hunger_api"]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
31
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Sean Bordelon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# HealthyHungerApi
|
2
|
+
|
3
|
+
Welcome to my ruby gem HealthyHungerApi! It is designed to help those in need of finding some healthy meal options while creating a plan that the user can visualize. My gem takes in input based on whether the user wants a daily or weekly meal plan setup and also takes in certain parameters to help create a more specific plan such as desired caloric intake, diet (i.e. vegan, keto, etc..), and any allergies the user may have. After the user has input the optional parameters, my gem creates and outputs a daily or weekly meal plan based on the specifics entered. The meals that are found and used to create a meal plan and the summary that accompanies each meal are accessed through an outside API. All information that is used to produce the neal plans come from the spoonacular API called recipe-food-nutrition located at rapidapi.com. (https://rapidapi.com/spoonacular/api/recipe-food-nutrition)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install Healthy_hunger_api
|
8
|
+
|
9
|
+
Healthy_hunger_api
|
10
|
+
|
11
|
+
In order to run the gem type in '$ gem install Healthy_hunger_api', and then type in 'Healthy_hunger_api' to begin the cli application
|
12
|
+
|
13
|
+
|
14
|
+
## Development
|
15
|
+
|
16
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
17
|
+
|
18
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lsuman83/Healthy_hunger_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lsuman83/Healthy_hunger_api/blob/master/CODE_OF_CONDUCT.md).
|
23
|
+
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
28
|
+
|
29
|
+
## Code of Conduct
|
30
|
+
|
31
|
+
Everyone interacting in the HealthyHungerApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lsuman83/Healthy_hunger_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "Healthy_hunger_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative "Healthy_hunger_api/version" #gives access to the version file in the Healthy_hunger_api folder
|
2
|
+
require_relative "Healthy_hunger_api/meals" #gives access to the meals file in the Healthy_hunger_api folder
|
3
|
+
require_relative "Healthy_hunger_api/api" #gives access to the api file in the Healthy_hunger_api folder
|
4
|
+
require_relative "Healthy_hunger_api/cli" #gives access to the cli file in the Healthy_hunger_api folder
|
5
|
+
|
6
|
+
module HealthyHungerApi
|
7
|
+
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
9
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
|
7
|
+
module HealthyHungerApi
|
8
|
+
|
9
|
+
class API #class that is accessing the api from the url
|
10
|
+
|
11
|
+
def self.api_key #class method used to help hide the api key by reading it from a
|
12
|
+
#file accessed on the user's computer or allowing the user to input it
|
13
|
+
|
14
|
+
begin
|
15
|
+
@key = File.open(File.expand_path("~/.spoonacular-api-key")).read.strip
|
16
|
+
rescue
|
17
|
+
puts "Unable to locate your API key. Please go to rapidapi.com, search for the
|
18
|
+
recipe-food-nutrition api and subscribe to receive your api key. Then come back and
|
19
|
+
input your key here."
|
20
|
+
@key = gets.strip
|
21
|
+
File.open(File.expand_path("~/.spoonacular-api-key"), "w") do |file|
|
22
|
+
file.print @key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@key
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_meals (timeFrame, targetCalories, diet, exclude) #class method that is accepting input parameters to get specific info from url
|
31
|
+
|
32
|
+
url = URI("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/mealplans/generate")
|
33
|
+
|
34
|
+
http = Net::HTTP.new(url.host, url.port)
|
35
|
+
http.use_ssl = true
|
36
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
37
|
+
|
38
|
+
params = { #optional parameters that are used to access specific info within the api
|
39
|
+
timeFrame: timeFrame,
|
40
|
+
targetCalories: targetCalories,
|
41
|
+
diet: diet,
|
42
|
+
exclude: exclude
|
43
|
+
}
|
44
|
+
|
45
|
+
url.query = URI.encode_www_form(params)
|
46
|
+
|
47
|
+
request = Net::HTTP::Get.new(url) #calling the Net::HTTP get method and passing the url to that method
|
48
|
+
request["x-rapidapi-host"] = 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com'
|
49
|
+
request["x-rapidapi-key"] = api_key
|
50
|
+
|
51
|
+
|
52
|
+
response = http.request(request)
|
53
|
+
JSON.parse(response.read_body) if response.is_a?(Net::HTTPSuccess) #parsing through the return value of the response.body as long as the get request is successful
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_summary(id) #class method used to get the summary of each item using a single id parameter
|
57
|
+
|
58
|
+
url = URI("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/#{id}/summary")
|
59
|
+
|
60
|
+
http = Net::HTTP.new(url.host, url.port)
|
61
|
+
http.use_ssl = true
|
62
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
request = Net::HTTP::Get.new(url)
|
67
|
+
request["x-rapidapi-host"] = 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com'
|
68
|
+
request["x-rapidapi-key"] = api_key
|
69
|
+
response = http.request(request)
|
70
|
+
JSON.parse(response.read_body) if response.is_a?(Net::HTTPSuccess)
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
module HealthyHungerApi
|
2
|
+
|
3
|
+
class CLI #class that runs the CLI. It outputs options to the screen and receives input from a user to help access othe classes
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
|
7
|
+
@input = "" #initializes all input instances to an empty string
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def start #instance method that starts the program and calls other instance methods used to access info for the app
|
12
|
+
|
13
|
+
puts "\tWelcome to our Healthy Hunger CLI app!"
|
14
|
+
puts ""
|
15
|
+
puts "We are here to help you create a healthy meal plan for yourself. Let's get started!"
|
16
|
+
puts ""
|
17
|
+
|
18
|
+
|
19
|
+
meal_plan_time_frame
|
20
|
+
meal_calories
|
21
|
+
diet
|
22
|
+
allergies
|
23
|
+
|
24
|
+
set_meals
|
25
|
+
if @menu_input == 'day' #conditional statements used to call a method that displays the meals by day or by week
|
26
|
+
list_meals_by_day
|
27
|
+
elsif @menu_input == 'week'
|
28
|
+
list_meals_by_week
|
29
|
+
end
|
30
|
+
ask_for_choice
|
31
|
+
|
32
|
+
while @input != 'exit' #conditionals based on the validity of the choice returned by the ask_for_choice method
|
33
|
+
if valid?(@input)
|
34
|
+
if @menu_input == 'day'
|
35
|
+
Meals.find_by_number(@input).display_meals_by_day #calls the instance method that displays the meals by using the class method
|
36
|
+
elsif @menu_input == 'week' #that is used to find the number that references the particular meal from the Meal class
|
37
|
+
Meals.find_by_number(@input).display_meals_by_week
|
38
|
+
end
|
39
|
+
|
40
|
+
puts ""
|
41
|
+
puts "To see the description of another meal, type 'next'"
|
42
|
+
puts "otherwise type 'exit' to exit the app!"
|
43
|
+
|
44
|
+
@input = gets.strip
|
45
|
+
if @input == 'next' #conditional that is used to either exit the program or get more descriptions of meals
|
46
|
+
ask_for_choice
|
47
|
+
elsif @input != 'next' && @input != 'exit'
|
48
|
+
puts "Didn't recognize input. Please try again"
|
49
|
+
puts ""
|
50
|
+
end
|
51
|
+
elsif !valid?(@input) #conditional that is checking input validation and displays error if not valid
|
52
|
+
puts "Please make a valid selection."
|
53
|
+
puts ""
|
54
|
+
ask_for_choice
|
55
|
+
elsif @input == 'exit'
|
56
|
+
return 'exit'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
puts ""
|
62
|
+
puts "Thank you for using our Healthy Hunger CLI app!"
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def meal_plan_time_frame #instance method that takes the input of whether the user wants a daily meal plan or weekly one
|
67
|
+
|
68
|
+
puts "Please choose from one of the following options to"
|
69
|
+
puts "create a meal plan designed especially for you: "
|
70
|
+
puts ""
|
71
|
+
puts "\t1 - Daily Meal Plan"
|
72
|
+
puts "\t2 - Weekly Meal Plan"
|
73
|
+
puts ""
|
74
|
+
@input = gets.strip
|
75
|
+
|
76
|
+
puts ""
|
77
|
+
|
78
|
+
if @input == '1'#conditional used to set the return value of the method based on the user input so that the method returns
|
79
|
+
@menu_input = "day"# the proper string to pass to the api call
|
80
|
+
elsif @input == '2'
|
81
|
+
@menu_input = "week"
|
82
|
+
else
|
83
|
+
puts "Please enter proper input, choose either '1' or '2'"
|
84
|
+
puts ""
|
85
|
+
meal_plan_time_frame#recursively calls the method if input is invalid and gives the user the option again
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def meal_calories #instance method that is getting a calorie input from user also making sure the
|
91
|
+
#value is within the parameters given
|
92
|
+
puts "What is your target Calorie intake? (400 - 3200)"
|
93
|
+
@meal_cal = gets.strip
|
94
|
+
|
95
|
+
puts ""
|
96
|
+
|
97
|
+
if @meal_cal.to_i == 0 #checking to make sure the user doesn't accidentally input a string
|
98
|
+
puts "Please enter a number"
|
99
|
+
puts ""
|
100
|
+
meal_calories
|
101
|
+
end
|
102
|
+
if @meal_cal.to_i < 400 || @meal_cal.to_i > 3200 #checking that the input from the user is within parameters giben
|
103
|
+
puts "Please enter a number between 400 and 3200"#and displaying an error message if it is not
|
104
|
+
puts ""
|
105
|
+
meal_calories
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def diet #instance method that takes in a numbered menu choice and sets that menu choice
|
111
|
+
#to the proper string that needs to be passed to the api as a parameter
|
112
|
+
puts "Choose your diet:"
|
113
|
+
puts " 1. Vegetarian"
|
114
|
+
puts " 2. Vegan"
|
115
|
+
puts " 3. Paleo"
|
116
|
+
puts " 4. Keto"
|
117
|
+
puts " 5. None"
|
118
|
+
@input = gets.strip
|
119
|
+
|
120
|
+
puts ""
|
121
|
+
|
122
|
+
if @input == "1" #conditionals setting the return values of the method equal to the string that the input
|
123
|
+
@diet_input = "vegetarian"#from the user refers to
|
124
|
+
elsif @input == '2'
|
125
|
+
@diet_input = "vegan"
|
126
|
+
elsif @input == '3'
|
127
|
+
@diet_input = "paleo"
|
128
|
+
elsif @input == '4'
|
129
|
+
@diet_input = "keto"
|
130
|
+
elsif @input == '5'
|
131
|
+
@diet_input = 'null'
|
132
|
+
else
|
133
|
+
puts "Please make a valid selection (1 - 5)."
|
134
|
+
puts ""
|
135
|
+
diet
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
def allergies #instance method that takes in possible allergies as input and returns those
|
141
|
+
#strings as values of the method
|
142
|
+
puts "List any allergies you may have. If you enter more than one, seperate them with a comma."
|
143
|
+
@allergy = gets.strip
|
144
|
+
if @allergy.to_i != 0 #checks to make sure that the value entered is not an integer
|
145
|
+
puts "Please enter an allergy, not a number."
|
146
|
+
puts ""
|
147
|
+
allergies
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
def set_meals #instance method that passes each input value for the previous
|
153
|
+
#methods into the class Meals class method load_by_day when menu input
|
154
|
+
Meals.load_meals(@menu_input, @meal_cal, @diet_input, @allergy)
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
def list_meals_by_day #instance method that searches through all of the meal objects that have been
|
159
|
+
#created for a daily meal plan, iterates over the objects and prints out the name of the meal with its
|
160
|
+
#index number next to it
|
161
|
+
|
162
|
+
puts ""
|
163
|
+
Meals.all.each.with_index(1) do |meal, index|
|
164
|
+
puts "Meal ##{index}: #{meal.title}"
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
def list_meals_by_week #instance method that searches through all of the meal objects that have been
|
170
|
+
#created for a weekly meal plan, iterates over the objects and prints out the name of the meal with its
|
171
|
+
#index number next to it. It also prints the meal number and which day of the week it is refering to
|
172
|
+
|
173
|
+
puts ""
|
174
|
+
daily_index = 0
|
175
|
+
Meals.all.each.with_index(1) do |meal, index|
|
176
|
+
meal_name = JSON.parse(meal.value)
|
177
|
+
if daily_index % 3 == 0
|
178
|
+
puts "Day ##{meal.day}:"
|
179
|
+
end
|
180
|
+
puts " Meal ##{meal.slot} (#{index}): #{meal_name["title"]}"
|
181
|
+
daily_index += 1
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
def ask_for_choice #instance method that is asking the user to input the meal number in order to see
|
188
|
+
#which meal that the user wants a description of
|
189
|
+
|
190
|
+
puts ""
|
191
|
+
puts "Choose a meal number to see a description"
|
192
|
+
@input = gets.strip
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
def valid?(input) #instance method that returns as truthy or falsey based on whether the input that
|
197
|
+
#the user has chosen is a valid meal number in the list of meal objects
|
198
|
+
|
199
|
+
Meals.all[input.to_i - 1] != nil
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module HealthyHungerApi
|
2
|
+
|
3
|
+
class Meals #class that takes in the input from the api and creates meal objects that can be
|
4
|
+
#parsed and sent to the cli for output
|
5
|
+
|
6
|
+
@@all = []
|
7
|
+
|
8
|
+
def self.all #class method that is used as a getter for the class array @@all
|
9
|
+
|
10
|
+
@@all ||= load_meals #loads the meal objects into the @@all array if they don't already exist
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_by_number(choice) #class method that takes in the choice of the user and then finds
|
15
|
+
#the meal object associated with it within the all array
|
16
|
+
self.all[choice.to_i - 1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load_meals(time, cal, diet, allergy) #class method that passes input from the user into the class methods
|
20
|
+
#from the API class based on a conditional of whether the user has chosen day or week for time. It then assigns
|
21
|
+
#the return value of those class methods to an instance variable @meals which is passed to a class method within
|
22
|
+
#the meals class to create a new instance for each meal and assign the instances to the @@all array
|
23
|
+
|
24
|
+
if time == 'day'
|
25
|
+
@meals = API.get_meals(time, cal, diet, allergy)["meals"] #gets the meals from the API class using a the hash symbol
|
26
|
+
elsif time == 'week' #necessary to get the appropriate data for daily meals
|
27
|
+
@meals = API.get_meals(time, cal, diet, allergy)["items"]
|
28
|
+
end
|
29
|
+
|
30
|
+
@@all = self.create_meal_from_specifics(@meals) #passing the return values to create new instances of meals
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def self.create_meal_from_specifics(meals) #class method that is used to create new instances by iterating over the meal hash
|
35
|
+
meals.map do |meal_hash|
|
36
|
+
self.new(meal_hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_accessor :id, :title, :readyInMinutes, :servings, :sumnary, :day, :slot, :value #creates getter and setter methods for each
|
42
|
+
#hash key received from the api meal hash
|
43
|
+
|
44
|
+
def initialize(attributes = {}) #initializes new instances of each meal
|
45
|
+
attributes.each do |attribute_name, attribute_value| #iterates over each has assigning each key as an attribute name
|
46
|
+
if self.respond_to?("#{attribute_name}=") #and each key value as the attribute value using the send method
|
47
|
+
self.send("#{attribute_name}=", attribute_value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def value_parser #instance method used to parse through the class method get_summary from the API classes
|
54
|
+
#value key and grab the values that are within the "id" symbol
|
55
|
+
API.get_summary(JSON.parse(self.value)["id"])
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def daily_summaries #instance method that uses the id key from the return value of the class method
|
61
|
+
#get_summary of the API class to get the summary of each meal for a daily meal plan
|
62
|
+
|
63
|
+
@summaries ||= API.get_summary(self.id)
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def weekly_summaries#instance method that calls the value_parser method to get the summary of each meal for a weekly meal plan
|
68
|
+
|
69
|
+
@summaries ||= value_parser
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def display_meals_by_day #instance method that uses the "summary" string to access the value from that hash symbol
|
75
|
+
#and replace each of the symbols found through the regex passed into the .gsub method
|
76
|
+
#with an empty space
|
77
|
+
|
78
|
+
puts daily_summaries["summary"].gsub(/<\/?[a-z]+>/, "").gsub(/<a href="[a-zA-Z0-9\/:\.\-\+]+">/, "")
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def display_meals_by_week#instance method that uses the "summary" string to access the value from that hash symbol
|
83
|
+
#and replace each of the symbols found through the regex passed into the .gsub method
|
84
|
+
#with an empty space
|
85
|
+
|
86
|
+
puts weekly_summaries["summary"].gsub(/<\/?[a-z]+>/, "").gsub(/<a href="[a-zA-Z0-9\/:\.\-\+]+">/, "")
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Healthy_hunger_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Bordelon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 12.3.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 12.3.3
|
27
|
+
description: CLI program for getting a List of created meals and providing a summary
|
28
|
+
from Recipe-Food-Nutrition API
|
29
|
+
email:
|
30
|
+
- sean.j.bordelon@gmail.com
|
31
|
+
executables:
|
32
|
+
- Healthy_hunger_api
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rspec"
|
38
|
+
- ".travis.yml"
|
39
|
+
- CODE_OF_CONDUCT.md
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- Healthy_hunger_api-0.1.0.gem
|
43
|
+
- Healthy_hunger_api.gemspec
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- bin/Healthy_hunger_api
|
48
|
+
- bin/console
|
49
|
+
- bin/setup
|
50
|
+
- lib/Healthy_hunger_api.rb
|
51
|
+
- lib/Healthy_hunger_api/api.rb
|
52
|
+
- lib/Healthy_hunger_api/cli.rb
|
53
|
+
- lib/Healthy_hunger_api/meals.rb
|
54
|
+
- lib/Healthy_hunger_api/version.rb
|
55
|
+
homepage: https://github.com/lsuman83/Healthy_hunger_api
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/lsuman83/Healthy_hunger_api
|
60
|
+
source_code_uri: https://github.com/lsuman83/Healthy_hunger_api
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.0.8
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Displays a List of created meals from Recipe-Food-Nutrition API
|
80
|
+
test_files: []
|