From e5be1425a662856026c4a5b140e1bdf25e8b6e98 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:13:08 +0000 Subject: [PATCH 1/8] Initial commit --- app.rb | 26 +++++++++++++++++++---- views/fg.erb | 10 +++++++++ views/home.erb | 12 +++++++++++ views/layout.erb | 54 +++++++++++++++++++++++++++++++++++++++++++++++- views/recipe.erb | 27 ++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 views/fg.erb create mode 100644 views/home.erb create mode 100644 views/recipe.erb diff --git a/app.rb b/app.rb index abbd1c7..06b777e 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,27 @@ require "sinatra" require "sinatra/reloader" +require 'net/http' +require 'json' + +def getRecipe(search_term) + API_ID = ENV.fetch("API_ID") + API_KEY = ENV.fetch("API_KEY") + url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=0443a169&app_key=1ee0cbfaf95acc2db0be467e463a22ba") + response = Net::HTTP.get(url) + response_obj = JSON.parse(response) + results = response_obj.fetch("hits") +end + get("/") do - " -

Welcome to your Sinatra App!

-

Define some routes in app.rb

- " + + erb(:home) +end + +post("/recipe_search") do + + search_term = params.fetch("search_term") + @results = getRecipe(search_term) + + erb(:recipe) end diff --git a/views/fg.erb b/views/fg.erb new file mode 100644 index 0000000..7ba34d8 --- /dev/null +++ b/views/fg.erb @@ -0,0 +1,10 @@ +
+<% @recipe.each do |item| %> + " class="card-img-top" alt="..."> +
+
<%= item["recipe"]["label"] %>
+
+ <%end%> +
+ + \ No newline at end of file diff --git a/views/home.erb b/views/home.erb new file mode 100644 index 0000000..6364f9b --- /dev/null +++ b/views/home.erb @@ -0,0 +1,12 @@ +
+
+

Find your favorite recipe!

+ +
+ + +
+
+
+ + diff --git a/views/layout.erb b/views/layout.erb index d0e831e..592a1eb 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -1,9 +1,61 @@ - Sinatra Template + Find your recipe. + + + + + + + + + + diff --git a/views/recipe.erb b/views/recipe.erb new file mode 100644 index 0000000..e813b78 --- /dev/null +++ b/views/recipe.erb @@ -0,0 +1,27 @@ +
+ Go back +
+ +
+
+ <% @results.each do |item| %> +
+
+ " class="card-img-top" alt="..."> +
+

<%= item["recipe"]["label"] %>

+ +
+
+
+ <%end%> +
+
From ccb2742a1ac3bcb1e09dc050dd8572fdc585b481 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:22:14 +0000 Subject: [PATCH 2/8] update --- app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 06b777e..b3a89e8 100644 --- a/app.rb +++ b/app.rb @@ -6,7 +6,7 @@ def getRecipe(search_term) API_ID = ENV.fetch("API_ID") API_KEY = ENV.fetch("API_KEY") - url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=0443a169&app_key=1ee0cbfaf95acc2db0be467e463a22ba") + url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=#{API_ID}&app_key=#{API_KEY}") response = Net::HTTP.get(url) response_obj = JSON.parse(response) results = response_obj.fetch("hits") From 3406544656ba288dda31c9d5943dd61232846f74 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:42:33 +0000 Subject: [PATCH 3/8] updated --- app.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index b3a89e8..69dd0fc 100644 --- a/app.rb +++ b/app.rb @@ -3,10 +3,13 @@ require 'net/http' require 'json' + + + def getRecipe(search_term) - API_ID = ENV.fetch("API_ID") - API_KEY = ENV.fetch("API_KEY") - url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=#{API_ID}&app_key=#{API_KEY}") + api_key = ENV.fetch("API_KEY") + api_id = ENV.fetch("API_ID") + url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=#{api_id}&app_key=#{api_key}") response = Net::HTTP.get(url) response_obj = JSON.parse(response) results = response_obj.fetch("hits") @@ -19,7 +22,7 @@ def getRecipe(search_term) end post("/recipe_search") do - + search_term = params.fetch("search_term") @results = getRecipe(search_term) From d582862aa8b30433b3e279c4b09bceb5394ccede Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:45:23 -0500 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a83f6f8..1936dbf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# sinatra-template +# simple recipe finder app Use this repository to create new Sinatra apps. From 5a2d62b81005373668c9d9fb13d1c9ed276764a1 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:47:45 -0500 Subject: [PATCH 5/8] Update README.md --- README.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1936dbf..ffb4217 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,5 @@ # simple recipe finder app -Use this repository to create new Sinatra apps. +App uses Edamam API for recipe search. -Optionally, to use `ActiveRecord` for database operations, add to the `app.rb`: - -```ruby -require "sinatra/activerecord" -``` - -And in the `config/environment.rb` file add this code block: - -```ruby -configure do - # setup a database connection - set(:database, { adapter: "sqlite3", database: "db/development.sqlite3" }) -end -``` +User can type any food and get recipes displayed. From eb2d563ba00f42ca997bf84f82eb8bc7c16ebcf2 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:48:20 -0500 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffb4217..4bf3c21 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ App uses Edamam API for recipe search. -User can type any food and get recipes displayed. +A user can type any food and get recipes displayed. From e6540dd7324f75b98950acbf060d6fd0ce66ef08 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Wed, 5 Jun 2024 22:47:37 +0000 Subject: [PATCH 7/8] updsate --- .vscode/settings.json | 5 ++++- app.rb | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bc0935b..4227896 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -53,5 +53,8 @@ }, "files.associations": { "*.html.erb": "erb" - } + }, + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] } diff --git a/app.rb b/app.rb index 69dd0fc..65c926c 100644 --- a/app.rb +++ b/app.rb @@ -7,9 +7,7 @@ def getRecipe(search_term) - api_key = ENV.fetch("API_KEY") - api_id = ENV.fetch("API_ID") - url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=#{api_id}&app_key=#{api_key}") + url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=0443a169&app_key=1ee0cbfaf95acc2db0be467e463a22ba") response = Net::HTTP.get(url) response_obj = JSON.parse(response) results = response_obj.fetch("hits") From 2c47802e35fa8a59b9194802e6db14da500cde66 Mon Sep 17 00:00:00 2001 From: Hanna Slesarska <127249050+Hanna-Slesarska@users.noreply.github.com> Date: Thu, 6 Jun 2024 01:39:40 +0000 Subject: [PATCH 8/8] update --- app.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 65c926c..69dd0fc 100644 --- a/app.rb +++ b/app.rb @@ -7,7 +7,9 @@ def getRecipe(search_term) - url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=0443a169&app_key=1ee0cbfaf95acc2db0be467e463a22ba") + api_key = ENV.fetch("API_KEY") + api_id = ENV.fetch("API_ID") + url = URI("https://api.edamam.com/api/recipes/v2?type=public&q=#{search_term}&app_id=#{api_id}&app_key=#{api_key}") response = Net::HTTP.get(url) response_obj = JSON.parse(response) results = response_obj.fetch("hits")