My First CLI App ‘HappyHour’

Ben Harter-Murphy
3 min readDec 2, 2020

This is my very first project built with Ruby that interacts with the user through the Command Line Interface.

What ‘HappyHour’ achieves is an alternative to paper menus for the restaurant industry at large. When running the application the user is greeted with a welcome message.

Upon receiving that message they are prompted with an option to either view the menu, or exit the program. Exiting the program will provide a message of “Thanks for stopping by :)”. If the user wants to view the menu they are then presented with a list of 25 options provided by an API from: https://punkapi.com/documentation/v2

The next step is selecting the beverage! Given what the user enters it will return a list of data about the beverage. If the user is satisfied with this option they are free to exit the program. If not, they are then given the option to return to the menu to make a selection. Theoretically you could stay in ‘HappyHour’ as long as you want, who wouldn’t right?

The Process

For a seasoned developer a simple one level deep CLI application might be child’s play. But for a newcomer I definitely had a tiny panic attack. But it all worked out, I wouldn’t be writing this if I didn’t get my Gem to function properly.

The first step was choosing the API. We were given the option to either utilize and API or site scrape. If you don’t know what site scrapping is it can be a very tedious and long process by accessing elements in a HTML page. And whose to say when all is said an done that those developers decide to switch the layout that makes your Gem function? For this reason I decided to go with an API.

I had to find one that met my idea for my Gem. Luckily I found Punk API that has a list of beers that I could play with for free.

The Environment

Next I had to set up my VSCode for success. That meant setting up my files so that they would all co-operate together. We call this process ‘require’-ing files. Doing so will make your life 10 times easier. For example my file tree flows as such :

lib files(Where my code is)->environment file(where all the lib folders are required)->run file(my executable file where my environment file is stored)

And voila! At the end of the day while your testing you only have to worry about running one command ‘bin/run’. Instead of rooting into every single file path every time you want to test two lines of code.

The Code

Finally, the home stretch…almost. Now that we had the API and were making a get request we had to find out how to access the data we needed for ‘HappyHour’. To do this we needed to install a JSON gem. For those of you who don’t know JSON is a way to parse and return raw data so that is easily readable for us humans.

Once we had that working it was on to the logic. How is this going to work? What would the user most likely want to see? Here is how I wanted my program to flow:

  • Greet the user
  • Ask if they would want to see a menu or not
  • Display menu
  • Have the user choose a beverage
  • Display more info on said beverage
  • See if the user is satisfied with this choice. Or take them back to the menu.
  • Once satisfied they are welcome to exit the program

Easy?! Right? To be quite honest once you get a feel for how Object Oriented Ruby Programming works, as soon as you have the data, it’s all gas and no brakes! This is where we get to express our creativity as developers. How do we want to display this info to the user? How would the user interact with the app?

So test, after test, after test, and debugging, and more testing, and more brainstorming, and more whiteboarding…I was done…I had finally completed my first solo project. And let me tell you what, I can’t wait for the next one!

The Finished Project

--

--