DEV Community

Cover image for Marian the Librarian CLI Project

Marian the Librarian CLI Project

Software Engineering student at the Flatiron School
・3 min read

For my first major solo project in the Flatiron School curriculum, I was tasked with creating a CLI(Command Line Interface) application that pulls data from a public API to provide information to a user. I wanted to create something that I myself would want to use and also something manageable, as I only had a week to pull everything together. Github has a very handy list of free public APIs identifies which APIs require key authorization and which don't. I decided to use an API that didn't require a key(for ease of use) and selected the OpenLibrary API.

I used the HTTParty and Json gems to retrieve and parse the data collected from OpenLibrary. The colorize gem I used helped to make everything more legible and engaging for the potential user.

Marian the Librarian--the name of my CLI--includes an API class, which collects data on books when searched with an author's first and last name; a Book class, which serves as my model; and a CLI class, which is where the application runs, loops, and prompts the user for input.

The first hurdle I had in building this CLI was dealing with all the data from the OpenLibrary API. Looking back, I probably would have chosen an API that was slightly less vast. This one has information about pretty much every author that has ever existed. It has entries for every book each author has ever written, including separate entries for various translation. What it also has is seperate entries of the same book if the book title is recorded in a different way. For example. Searching for all books written by Zadie Smith will return: On Beauty, White Teeth, A Changed Mind, a changed mind,..etc. I didn't want to return a list of books to my users with duplicate titles. To make sure that only unique titles were created from all the data parsed from OpenLibrary, I wrote my API method to account for, and not create duplicate titles. If a book object had already been created with that same title, my application would not create a second book object.

Alt Text

The name of the game for me on this project was menuing logic. Because I created a main menu that asked for user input concerning an author as well as a secondary menu that asked for user input concerning a book number, there were a couple times when I accidentally coded myself into a never-ending loop.

My #list method was one of those never-ending loops. Before I had coded it to receive another possible input, it was stuck printing out the details of a book forever.

Alt Text

Working step by step through the logic of each coded line really helped me breakdown the functionality of the application to understand exactly what needed to happen and where the librarian was going off the rails--so to speak.

Once I had everything working, I spent a significant amount of time trying to clean everything up. I wanted to refactor my code so that my CLI was DRY (do not repeat yourself) and easy to follow.

I feel incredibly proud of myself for finishing my first Flatiron project! It's amazing to look back to merely four weeks ago and realize how much I have learned in such a short period of time. Now onto the next piece of the curriculum!

Discussion (0)