My First CLI Project

Rupinder Kaur
3 min readMar 27, 2021

--

Find Recipe

After one month of Software Engineering at Flatiron school , it’s time to build my first portfolio project. I had to choose to do my project between scraping a website or using built in APIs . I want to build something that i’d find useful. So, i choose to grab data from Spoonacular Food Api to get information of all Recipes. I have to use HTTParty (a ruby gem) to get response from url, and parse through the JSON to find the relevant data.

It was challenging for me , i didn’t know how to get started as i never created a gem before. A quick google search and few creating gem lectures provided some resources to get started. There were several resources that were recommended to use to build a gem and get started with necessary files . I set up the gem from the command line using bundler . I found HTTParty (a ruby gem) very helpful which can be used to query web services and examine the resulting output . By default it will output the response as a pretty-printed ruby object. Also pry(a ruby gem) that can either be required in your Gemfile or installed with gem install pry, pry will do is pause our code as it is running ,so that we can poke around and see what’s going on.

It took me awhile to figure out how to get more information I wanted from the object returned by HTTParty. First — i want to create a call method that would ask the user to select any option to go futher to see recipes , then CLI class should receive the input and then provide a list of recipes and give more iformation of recipes. Once user selected the specific recipe , it will provide more information to the user :

  • Recipe_name
  • Preparation Time
  • Servings
  • Vegetarian — True or False
  • Ingredients
  • Summary

Once this information has been provided to the user , the CLI would prompt returning to main menu again . At each step of the call method , CLI will return you to main menu until you typed exit or logout from the app. Other option will be find recipe by ingredient, In this method asks the user for ingredients to search for recipe. Then calls the ingredient api to fetch all the recipe ids. Then i use the recipe id to call the recipe api to get more detailed info like Recipe_name , prepartion time , servings , ingredients and summary of the recipes

Then i created two more methods

  • Find recipe with instruction
  • Find similar recipes

In the Find recipe with instruction method, user can type any id of the recipe to get instruction of how to prepare the recipe step by step. i have to use recipe id to call the recipe api to get more detailed information for the recipe . In the find similar recipes method , it gets the id from the user and calls the spoonacular api url to find out all the similar recipes and store them into the array , then i also calls the recipe api again to get the title of the recipe and then prints it out to the user. User can also press enter to see the list again or will press exit to leave from the app.

Thank you for your time.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rupinder Kaur
Rupinder Kaur

No responses yet

Write a response