DEV Community

Cover image for Bored? Not Anymore.
Catherine Hodgkinson
Catherine Hodgkinson

Posted on • Updated on

Bored? Not Anymore.

When the time finally came to begin my first CLI project, I struggled to even pick a subject because of how much data is truly available to us as programmers. Learning about using data from an API and scraping have opened a very important door in my programming knowledge development.

My project, "Bored?," has a variety of basic functionalities like taking in a user's name, asking them to make several selections, and offers them a random, potentially boredom-curing activity to do. It also offers the user the number of participants they need for the specific activity, a rough cost, and the category the activity falls into (i.e. recreational, academic, etc.).

Certain aspects of the project flew easily from my mind to the screen. I knew I was using an API, and I knew the basic format for fetching data from an API, so I knew I could build my API class:

Alt Text

I have also become increasingly familiar with the initialize method, accessing pieces of data through iteration, assigning attribute accessors, and at the very end I quickly picked up on how to use the "colorize" gem in Ruby to change the color of the text that is output to the terminal. Not only was that really fun (which was the only reason I was incorporating it) but I actually found the coloration to be useful in terms of organization and separating ideas and phrases in the terminal. In short, the pretty colors make my prompts easier to read. And let's face it, no one wants to use a plain-looking application!

I did, however, run into an issue that took some time, creative thought, and some instruction to conquer. My code has a "see_more" method, in which some input options can be reused in other places if, for instance, the user is not interested in the activity they are presented with and wants to see a new one. It is a different take on my "menu" method earlier in the program that also has some reusable assets. The problem I was facing involved showing the user that new, or alternate option for an activity. My program was continually printing the same activity over and over and over again until the program was exited. So, I presented the following solution within a method of my CLI class:

Alt Text

This solution allows the program to re-call the API and gather a new set of data. Using the Ruby gem "pry" I could see that the site was only providing a single hash of an activity and its attributes, which was being stored in the class variable and array "all" as an object. The solution was rather simple because of this. I could just clear that array and call the API again to get a new hash of activity data instantiated. It also helps that there is only a small amount of data being loaded every time the API is called, to prevent the user from having to wait with a blank screen (although they are bored so after all that might be a step up?).

I included the cover image of the top of a mountain in my home state because the application includes a possible suggestion of "taking a hike," which is one of my favorite things to do. It also includes ideas like "try a food you never have before," "make a new friend," and "volunteer at a local food pantry."

With this project complete, I find myself confident in what I have learned so far in my journey (now about two months in). I am excited that I have the ability to build projects like this and look forward to building on this foundation.

Top comments (0)