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/README.md b/README.md index a83f6f8..4bf3c21 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,5 @@ -# sinatra-template +# 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 -``` +A user can type any food and get recipes displayed. diff --git a/app.rb b/app.rb index abbd1c7..69dd0fc 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,30 @@ require "sinatra" require "sinatra/reloader" +require 'net/http' +require 'json' + + + + +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}") + 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%> +
+