Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jessica Owens -- Carets #40

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
08bc6e7
setup and first search method
vertige Oct 31, 2017
3daa24d
added recipe controller
vertige Oct 31, 2017
d745086
updated search method
vertige Oct 31, 2017
7ace7f6
added routes, updated test_helper, and works on recipe.rb
vertige Oct 31, 2017
9480832
tidied up EdamamApiWrapper#search and Recipe#init to pack up and go home
vertige Nov 1, 2017
9b1d53e
added EdamamApiWrapper#find_recipe method
vertige Nov 1, 2017
81aab25
worked on Wrapper tests
vertige Nov 1, 2017
c3b6985
Wrote Recipe#init tests
vertige Nov 2, 2017
fd03388
Added tests for Recipe#Equality
vertige Nov 2, 2017
98c7ef1
Wrote positive tests for RecipeController#list_search and #show
vertige Nov 2, 2017
32fbc9b
Added foundation and changed file names
vertige Nov 3, 2017
5ee1f20
Added pagination gem
vertige Nov 3, 2017
161d86c
Added and commented out EdamamApiWrapper#loop_search to get more than…
vertige Nov 3, 2017
a07581b
setup footer, list and show views
vertige Nov 3, 2017
afb74bb
added lines to application.rb and production.rb for heroku to use lib…
vertige Nov 3, 2017
6abaf10
fixed typo for heroku deployment
vertige Nov 3, 2017
cfa9bc7
added dependencies to controller
vertige Nov 3, 2017
6f6723a
more typos for deployment
vertige Nov 3, 2017
1cb0386
added dietary labels
vertige Nov 3, 2017
da11604
fixed tests post pagination
vertige Nov 5, 2017
44dfbb9
started some styling
vertige Nov 5, 2017
b7b4fff
slight refactoring of uri hash
vertige Nov 6, 2017
808c424
worked more on show recipe view
vertige Nov 6, 2017
1a2ce6d
updated test for uri_hash
vertige Nov 6, 2017
61d7414
fussed with header and footer
vertige Nov 6, 2017
382551c
worked on home page
vertige Nov 6, 2017
f53098e
added diet labels and tests
vertige Nov 6, 2017
7117dd5
Tidied up some things
vertige Nov 6, 2017
2096e2a
made list view prettier
vertige Nov 6, 2017
d7f9e6e
external urls open in new tabs
vertige Nov 6, 2017
a1d4215
Tidied up placeholder text and diet labels
vertige May 9, 2018
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
Prev Previous commit
Next Next commit
worked on Wrapper tests
vertige committed Nov 1, 2017
commit 81aab254333adfefb08264042b4843ddae06c03f
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ group :development, :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'dotenv-rails'
gem 'minitest-vcr'
gem 'webmock'
end

group :development do
@@ -61,7 +64,6 @@ group :development do
gem 'better_errors'
gem 'pry-rails'
gem 'binding_of_caller'
gem 'dotenv-rails'

end

17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ GEM
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.2)
debug_inspector (0.0.3)
dotenv (2.2.1)
@@ -74,6 +76,7 @@ GEM
ffi (1.9.18)
globalid (0.4.1)
activesupport (>= 4.2.0)
hashdiff (0.3.7)
httparty (0.15.6)
multi_xml (>= 0.5.2)
i18n (0.9.0)
@@ -99,6 +102,8 @@ GEM
mime-types-data (3.2016.0521)
mini_mime (0.1.4)
mini_portile2 (2.3.0)
minispec-metadata (2.0.0)
minitest
minitest (5.10.3)
minitest-rails (3.0.0)
minitest (~> 5.8)
@@ -108,6 +113,10 @@ GEM
builder
minitest (>= 5.0)
ruby-progressbar
minitest-vcr (1.4.0)
minispec-metadata (~> 2.0)
minitest (>= 4.7.5)
vcr (>= 2.9)
multi_json (1.12.2)
multi_xml (0.6.0)
nio4r (2.1.0)
@@ -154,6 +163,7 @@ GEM
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
safe_yaml (1.0.4)
sass (3.5.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
@@ -190,11 +200,16 @@ GEM
thread_safe (~> 0.1)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
vcr (3.0.3)
web-console (3.5.1)
actionview (>= 5.0)
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webmock (3.1.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
@@ -217,6 +232,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
minitest-rails
minitest-reporters
minitest-vcr
pg (~> 0.18)
pry-rails
puma (~> 3.7)
@@ -229,6 +245,7 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
webmock

BUNDLED WITH
1.15.4
18 changes: 18 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

end
40 changes: 24 additions & 16 deletions lib/edamam_api_wrapper.rb
Original file line number Diff line number Diff line change
@@ -7,13 +7,16 @@ class EdamamApiWrapper
APP_KEY = ENV["EDAMAM_KEY"]
APP_ID = ENV["EDAMAM_ID"]

RECIPE_URL = "http://www.edamam.com/ontologies/edamam.owl%23recipe_"

SEARCH_LENGTH = 10
MINIMUM_BAR = %w(label uri image ingredientLines)
RECIPE_URL = "http://www.edamam.com/ontologies/edamam.owl%23recipe_"

def self.search(query, hits = SEARCH_LENGTH)
url = BASE_URL + "q=#{query}" + "&app_id=#{APP_ID}" + "&app_key=#{APP_KEY}" + "&to=#{hits}"
def self.search(query, options = { } )
options[:app_id] ||= APP_ID
options[:app_key]||= APP_KEY
options[:hits] ||= SEARCH_LENGTH

url = BASE_URL + "q=#{query}" + "&app_id=#{options[:app_id]}" + "&app_key=#{options[:app_key]}" + "&to=#{options[:hits]}"

response = HTTParty.get(url)

@@ -36,20 +39,25 @@ def self.search(query, hits = SEARCH_LENGTH)
end
end

def self.find_recipe(mini_uri)
url = BASE_URL + "r=" + RECIPE_URL + mini_uri + "&app_id=#{APP_ID}" + "&app_key=#{APP_KEY}"
def self.find_recipe(mini_uri, options = { })
options[:app_id] ||= APP_ID
options[:app_key] ||= APP_KEY

url = BASE_URL + "r=" + RECIPE_URL + mini_uri + "&app_id=#{options[:app_id]}" + "&app_key=#{options[:app_key]}"

response = HTTParty.get(url)

if response[0]
if self.complete?(response[0])
recipe = Recipe.new(
response[0]["label"],
response[0]["uri"],
response[0]["image"],
response[0]["ingredientLines"],
external_url: response[0]["url"],
source: response[0]["source"]
)
end
if self.complete?(response[0])
recipe = Recipe.new(
response[0]["label"],
response[0]["uri"],
response[0]["image"],
response[0]["ingredientLines"],
external_url: response[0]["url"],
source: response[0]["source"]
)
end
return recipe
else
return "oops"
12 changes: 10 additions & 2 deletions lib/recipe.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
class Recipe
attr_reader :title, :mini_uri, :photo_uri, :external_url, :source, :ingredients

RECIPE_URL = "http://www.edamam.com/ontologies/edamam.owl%23recipe_"
def initialize( title, uri, photo_uri, ingredients, options = { } )
@title = title
@mini_uri = uri[RECIPE_URL.length-2,uri.length]
@mini_uri = uri[EdamamApiWrapper::RECIPE_URL.length-2,uri.length]
@photo_uri = photo_uri
@ingredients = ingredients
@external_url = options[:external_url]
@source = options[:source]
end

def == (another_recipe)
self.title == another_recipe.title
self.mini_uri == another_recipe.mini_uri
self.photo_uri == another_recipe.photo_uri
self.ingredients == another_recipe.ingredients
self.external_url == another_recipe.external_url
self.source == another_recipe.source
end

end
87 changes: 87 additions & 0 deletions test/cassettes/wrapper_find_recipe.yml

Large diffs are not rendered by default.

633 changes: 633 additions & 0 deletions test/cassettes/wrapper_search.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/controllers/recipe_controller_test.rb
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@

describe RecipeController do
it "should get index" do
skip
get recipe_index_url
value(response).must_be :success?
end

it "should get show" do
skip
get recipe_show_url
value(response).must_be :success?
end
104 changes: 104 additions & 0 deletions test/lib/edamam_api_wrapper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require 'test_helper'

describe EdamamApiWrapper do

describe "self.search" do
it "returns a list of Recipes" do
VCR.use_cassette("wrapper_search") do
recipes = EdamamApiWrapper.search("pineapple")

recipes.must_be_instance_of Array
recipes.length.must_be :>, 0
recipes.each do |recipe|
recipe.must_be_instance_of Recipe
end
end
end

it "returns a blank array if no recipes are found or the request is broken" do
VCR.use_cassette("wrapper_search") do
recipes = EdamamApiWrapper.search("")

recipes.must_be_instance_of Array
recipes.must_equal []

recipes = EdamamApiWrapper.search("chicken", app_id: "")

recipes.must_be_instance_of Array
recipes.must_equal []

recipes = EdamamApiWrapper.search("chicken", app_key: "")

recipes.must_be_instance_of Array
recipes.must_equal []
end
end

it "returns a default number of results (or less) or the amount specified" do
VCR.use_cassette("wrapper_search") do
recipes = EdamamApiWrapper.search("chicken")
recipes.length.must_equal EdamamApiWrapper::SEARCH_LENGTH

recipes = EdamamApiWrapper.search("chicken and soysauce")
recipes.length.must_be :<=, EdamamApiWrapper::SEARCH_LENGTH

recipes = EdamamApiWrapper.search("chicken", hits: 4)
recipes.length.must_equal 4

recipes = EdamamApiWrapper.search("chicken", hits: 20)
recipes.length.must_equal 20
end
end
end #self.search

describe "self.find_recipe" do
it "returns a single Recipes" do
VCR.use_cassette("wrapper_find_recipe") do
recipe = EdamamApiWrapper.search("pineapple").first
new_recipe = EdamamApiWrapper.find_recipe(recipe.mini_uri)

new_recipe.must_be_instance_of Recipe
new_recipe.must_equal recipe
end
end

it "DO: WHAT DO I WANT IT TO RETURN- returns a blank array if no recipe is found or the request is broken" do
skip
VCR.use_cassette("wrapper_find_recipe") do
recipe = EdamamApiWrapper.find_recipe("")
recipe.must???

recipe = EdamamApiWrapper.search("pineapple").first
new_recipe = EdamamApiWrapper.find_recipe(recipe.mini_uri, app_id: "BOGUS")
new_recipe.must???

new_recipe = EdamamApiWrapper.find_recipe(recipe.mini_uri, app_key: "BOGUS")
new_recipe.must???

end
end #self.find_recipe

describe "self.complete?" do
it "returns false if any of the minimum keys aren't found" do
hash = {
"uri" => "some_url",
"image" => "some_url",
"ingredientLines" => ["stuff"]
}

EdamamApiWrapper.complete?(hash).must_equal false
end
end

it "returns true if all minimum keys are present" do
hash = {
"label" => "something",
"uri" => "some_url",
"image" => "some_url",
"ingredientLines" => ["stuff"]
}

EdamamApiWrapper.complete?(hash).must_equal true
end
end #self.complete?
end
Empty file added test/lib/recipe_test.rb
Empty file.