Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2aad47f
INITIAL commit with .gitignore and updated gemfiles.
jm-rives Nov 1, 2016
ee29483
UPDATE gemfile, add search controller
jm-rives Nov 1, 2016
fbcef37
ADD test controller file
jm-rives Nov 1, 2016
c42cc24
ADD controllers for search, show, and list
jm-rives Nov 1, 2016
56278ad
ADD test helper method VCR configuration.
jm-rives Nov 1, 2016
9ea1ef3
ADD Gemfile.lock updated
jm-rives Nov 2, 2016
b00d9db
UPDATE gemfile
jm-rives Nov 2, 2016
9e112e0
ADD Search controller
jm-rives Nov 3, 2016
3682bdf
ADD Search controller
jm-rives Nov 3, 2016
20e3ca9
ADD Results controller
jm-rives Nov 3, 2016
424d144
ADD Recipe controller
jm-rives Nov 3, 2016
19e366d
ADD wrapper for api_muncher
jm-rives Nov 3, 2016
7cc6331
ADD empty wrapper class
jm-rives Nov 3, 2016
06d069f
MERGE CONFLICT resolved
jm-rives Nov 3, 2016
e352e82
UPDATE gemfile/ gemlock
jm-rives Nov 3, 2016
9a50203
ADD attr_reader to api muncher
jm-rives Nov 3, 2016
05e22e7
ADD empty initialize method
jm-rives Nov 3, 2016
821b582
ADD partial wrapper and search view
jm-rives Nov 3, 2016
83234c7
ADD config autoload path, FIX Error in wrapper.
jm-rives Nov 5, 2016
66d8d51
UPDATED routes
jm-rives Nov 5, 2016
8155bd0
ADD index view
jm-rives Nov 5, 2016
94e485b
ADD working index view, updates to search controller and Api Muncher …
jm-rives Nov 6, 2016
b9dc8fd
ADD cassettes to .gitignore
jm-rives Nov 6, 2016
f8cf55e
ADD UPDATE to README
jm-rives Nov 7, 2016
9676305
Pre-checkout committ
jm-rives Nov 13, 2016
02ae263
ADD comments
jm-rives Nov 13, 2016
695f4dd
ADD working logo, working search, working link to one recipe
jm-rives Nov 13, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/controllers/recipe_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class RecipeController < ApplicationController
def new
end

def update
def index
end

def show

end

def destroy
Expand Down
41 changes: 18 additions & 23 deletions app/controllers/results_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
class ResultsController < ApplicationController

# https://developer.edamam.com/edamam-docs-recipe-api
# from Edamam q = query text, r = return of recipe based on it's id
attr_reader :q, :uri

# def initialize(q, uri)
# # @q = q
# # @uri = uri
# end

# attr_reader :query, :uri
def index
end

def new
end

def create
@page = '/'
end

def show
end

def edit
end

def update
end

def destroy
# @page = "/"
# @results = ApiMuncherWrapper.search(params[:query], params[:from])
# @count = ApiMuncherWrapper.results(params[:query])
# @query = params[:query]

# # expect user to be redirected to new search
# if @results == false
# redirect_to results_index_path
# flash[:notice] = "Recipe not found. Try Again Please!"
# else # expect user to be shown serach results
# @results_start = params[:from].to_i + 1
# @results_end = @results_start + @results.length - 1
# # do I need to reset query here, should I clear the field?

end
end
end
6 changes: 4 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
class SearchController < ApplicationController

def index
@results = ApiMuncherWrapper.get_recipe

@results = ApiMuncherWrapper.get_recipes(params[:search])
# puts "!!!!!!!!!!!!!!"
# puts params.inspect
# puts "!!!!!!!!!!!!!!"
end

def new
Expand Down
14 changes: 11 additions & 3 deletions app/views/search/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<h1>See your Recipes here!</h1>
<% @results.each do |recipe|%>
<%= recipe[:name] %>
<%= image_tag(recipe[:pic]) %>
<%= link_to recipe[:uri] do %>
<%= recipe[:name] %><br>
<%= image_tag(recipe[:pic]) %>
<!-- <%# recipe[:uri] %> -->
<% end %>
<br><br><br>
<% end %>
<!-- turn this into a partial -->
<footer><p class="attribute"> Powered by Edamam <img src="../edamam_logo.svg" alt="Edamam Logo"><p></footer>
<footer>
<p class="attribute"> Powered by Edamam

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This footer could be abstracted into the layout or as a partial.

<img src="/assets/edamam_logo.png" alt="Edamam Logo">
<p>
</footer>
6 changes: 5 additions & 1 deletion app/views/search/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<%= submit_tag "Search", :name => nil %>

<% end %>
<footer><p class="attribute"> Powered by Edamam <img src="../edamam_logo.svg" alt="Edamam Logo"><p></footer>
<footer>
<p class="attribute"> Powered by Edamam
<img src="/assets/edamam_logo.png" alt="Edamam Logo">
<p>
</footer>
30 changes: 17 additions & 13 deletions lib/ApiMuncherWrapper.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
require 'httparty'
# did you change this ? Then restart the server!
class ApiMuncherWrapper

BASE_URL = "https://api.edamam.com/search"
# should this be listed as Token/ id instead/
APP_ID = ENV['app_id']
APP_KEY = ENV['app_key']

# https://developer.edamam.com/edamam-docs-recipe-api
# from Edamam q = query text, r = return of recipe based on it's id
# attr_reader :recipe, :q, :url, :image, :returns, :r
# def initialize(recipe, q, url, image, returns, r)
# @recipe = recipe
# @q = q
# @url = url
# @image = image
# end

def self.get_recipe
url = BASE_URL + "?q=bacon&from=0&to=10" + "&app_id=#{APP_ID}" + "&app_key=#{APP_KEY}"

def self.get_recipes(query, from=nil)

url = BASE_URL + "?q=#{query}" + "&app_id=#{APP_ID}" + "&app_key=#{APP_KEY}" + "#{from}"

puts "*******" + url + "*******"

# url = BASE_URL + "?q=bacon&from=0&to=10" + "&app_id=#{APP_ID}" + "&app_key=#{APP_KEY}"

data = HTTParty.get(url)
# return data['hits'][0]['recipe']['label']
recipes = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to put in some checks in for if the API responds with something unexpected, like if 'hits' is null.

I would also probably setup a recipe class and return either a specific recipe or an array of them. That way you would separate the implementation of the Recipe API from it's use. It would let you switch APIs or other sources of the recipes easier.

Expand All @@ -26,14 +24,20 @@ def self.get_recipe
data['hits'].each do |recipe|
label = recipe["recipe"]["label"]
image = recipe["recipe"]["image"]
uri = recipe["recipe"]["uri"]
recipes << {
name: label,
pic: image
pic: image,
uri: uri
}
end
end
return recipes
end

def self.get_one_recipe

end
end


Expand Down