Open
Conversation
…till need to paginate
…ed flash messages for user friendliness
…me back later to check on index
API MuncherWhat We're Looking For
|
dHelmgren
reviewed
Nov 14, 2018
lib/edamam_api_wrapper.rb
Outdated
|
|
||
|
|
||
| #list the channels ** | ||
| # base_url = https://api.edamam.com/search?app_id=cce9a91f&app_key=d0f4da3c9d8a64a9be87b192561284b7&q=chocolate mouse |
There was a problem hiding this comment.
You did. Such a good job. Keeping your app key hidden. Except for the comments. 😦
| get '/recipes', to: 'recipes#index', as: 'search' | ||
| # get '/recipes/:url', to: 'recipes#show', as: 'recipe_url' | ||
|
|
||
| get '/recipes/:uri', to: 'recipes#show', as: 'recipe' |
There was a problem hiding this comment.
Could you use resources for the index and show pages?
| def show | ||
| # binding.pry | ||
| @recipe = EdamamApiWrapper.find_recipe_by(params[:uri]) | ||
| if @recipe.nil? |
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.
|
|
||
| must_respond_with :ok | ||
| end | ||
| end |
There was a problem hiding this comment.
What if you give them a negative page?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
API Muncher
Congratulations! You're submitting your assignment!
Comprehension Questions
What is an API Wrapper? Why is it in
lib? How would your project change if you needed to interact with more than one API (aka more than just the Edamam API)? |Using an API wrapper allows us to separate our concerns so that all the API specific stuff happens in the one class called the API wrapper so if we switch from Slack to using Microsoft we can just switch classes and the rest of our app won’t have to change. It lets us adapt our code more easily. It lives in the 'lib' folder because that is where custom libraries live, regular classes would live in the model folder.
Describe your API wrapper, the methods you created in it, and why you decided to create those methods/how they were helpful | The API wrapper has three methods: self.list_recipes(user_search), self.find_recipe_by(uri), and a private method self.create_recipe(api_params). The #create_recipes is an important private method that takes the api_params from Edamam and returns an instance of Recipe. Rather than creating an instance of Recipe directly from the 'uri' value that comes from api_params, I partitioned the uri string to only select the unique recipe identifier that comes at the end of the full uri. The #find_recipe_by(uri) method searches for a specific recipe by its uri, calls #create_recipe helper method and returns an instance of Recipe containing the attributes of the searched recipe. Reading the Edimam documentation was important because it specified that you can search for uri by specifiying "r=" in the url. That method is called in #show in the Recipes Controller. The #list_recipes(user_search) searches for all recipes in the API's database, "q=" needed to be speficied in the url, it calls the #create_recipe helper for each recipe and returns and array of Recipe objects. This method is called in the #index in Recipes Controller. Is it necessary to call 'encode.URI' in these two methods? I found that it broke the app at one point when I used it so I commented it out.
What was an edge case or failure case test you wrote for your API Wrapper? What was a nominal case? | Two edge cases are "it returns empty array when given a search term that doesn't exist", "returns nil if non-existing uri is passed". A nominal case is it "can list recipes when given a search term that exists in the API"
How does VCR aid in testing an API? | It records the interaction with the API and lets you replay it later so you don’t have to make too many API calls.
What is the Heroku URL of your deployed application? |
https://kay-api-muncher.herokuapp.com/