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 - " -
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 @@ +