Conversation
API MuncherWhat We're Looking For
|
| get "recipes/", to: "recipes#index", as: "recipes_index" | ||
| get 'recipes/:uri/view', to: "recipes#show", as: "recipe_show" | ||
|
|
||
| get '/search', to: 'search#new', as: "search_recipes" #where searches are routed to |
There was a problem hiding this comment.
I'm not sure that new is a good name for this route/action. You're not really creating a new recipe, you're doing a search.
| Rails.application.routes.draw do | ||
| get root "search#new" | ||
| get "recipes/", to: "recipes#index", as: "recipes_index" | ||
| get 'recipes/:uri/view', to: "recipes#show", as: "recipe_show" |
There was a problem hiding this comment.
Could you use resources for the index and show pages?
| #example url search: "https://api.edamam.com/search?q=chicken&app_id=${YOUR_APP_ID}&app_key=${YOUR_APP_KEY}&from=0&to=3&calories=591-722&health=alcohol-free" | ||
|
|
||
| BASE_URL = "https://api.edamam.com/search" #what query params are attached to (?q for eng, ?r for nums) | ||
| REQUEST_URI = URI::encode("http://www.edamam.com/ontologies/edamam.owl#recipe_") |
There was a problem hiding this comment.
Good work distinguishing these elements from one another.
| api_params["recipe"]["healthLabels"], | ||
| api_params["recipe"]["calories"], | ||
| api_params["recipe"]["totalTime"], | ||
| api_params["recipe"]["url"], |
There was a problem hiding this comment.
Could you dry this code by removing the recipe wrapper before passing the data into single_recipe?
| before_action :find_query | ||
|
|
||
| def index | ||
| @recipes = EdamamApiWrapper.search_recipes(find_query).paginate(page: params[:page], per_page: 10) |
There was a problem hiding this comment.
You've written your API wrapper to raise an error if the API call fails, but you're not looking for an error here. You should wrap this call in a begin/rescue.
This causes your pages to break on bogus data, rather than redirect.
| @recipe = EdamamApiWrapper.recipe_contents(params[:uri]) | ||
|
|
||
| if @recipe.nil? || @recipe == false | ||
| redirect_to root_path, status: :not_found |
There was a problem hiding this comment.
Your redirect doesn't complete, possibly because you're explicitly setting the status code here.
| require 'httparty' | ||
|
|
||
| class EdamamApiWrapper | ||
| #example url search: "https://api.edamam.com/search?q=chicken&app_id=${YOUR_APP_ID}&app_key=${YOUR_APP_KEY}&from=0&to=3&calories=591-722&health=alcohol-free" |
There was a problem hiding this comment.
Nice work not giving away your app key, and keeping handy data nearby. Others goofed on this.
| http_interactions: | ||
| - request: | ||
| method: get | ||
| uri: https://api.edamam.com/search?app_id=73a32603&app_key=fc79540af556f65253707c3c2b00862e&r=http://www.edamam.com/ontologies/edamam.owl%23recipe_a53ef6c8495adcb9f2859b1e5d99e9ba |
There was a problem hiding this comment.
You didn't hide your app key from the cassettes here. :'(
|
|
||
| describe "index" do | ||
|
|
||
| it "should get index" do |
There was a problem hiding this comment.
There are some interesting cases you're not covering here:
- What happens if no search term is provided?
- What if the search returns no results?
It might also be worthwhile to add some tests around the paging parameters:
- What happens if they're absent?
- Do you get different results when they change?
- What if you send a bogus value, like a negative page number?
API Muncher
Congratulations! You're submitting your assignment!
Comprehension Questions
lib? How would your project change if you needed to interact with more than one API (aka more than just the Edamam API)?