Welcome to my second blog post that I’m writing as a software engineer trainee. Today I am going to discuss and give you a demonstration of my very first CLI application that I built using an existing API from none other than Studio Ghibli: https://ghibliapi.herokuapp.com/. Before I go any further into the project I just wanted to say that Studio Ghibli was a great API source for me to use in my first CLI application because not only was it super easy for me to implement, but it is also one of the few APIs that does not require authentication. Thus making it more user friendly and developer friendly in that regard. Now onto the project.
So rather than bore you all with an epistle narrative of how it works, I figured that I would include an actual visual demonstration of the program and all of its functionality. Instead I’m going to be discussing some hiccups that I had and things that I learned along the way.
The first thing that I’m going to talk about which I experienced is with object oriented functionality. In order to expand on the functionality of objects in my class I had to create multiple different class methods. In doing so, I got to have more practice with the keyword self and being able to utilize it to manipulate the display of the object instances which I later created in my CLI class. Here’s a brief overview of the class methods that I used in this program:
In creating these class methods and then later implementing them in my CLI I decided to demonstrate the use of sorting the list of movie objects in both ascending and descending orders. I didn’t have any problem sorting the movie titles, however the ratings presented me with a different task. When I went to sort the ratings I discovered that any movie ratings which contained triple digits would not sort in chronological order with the rest of the objects. In order to address this issue, I had to explicitly convert the rating score attribute data type from a string to a float. In this case, I decided to go ahead and implement the to_f conversion as opposed to the to_i which would convert my scores to integers because I felt that it was more appropriate than in this instance given the fact that these are scores and it gives the developer the option to add decimal values. Once I implemented that explicit to_f conversion, all my rating scores were sorted properly.
In my main menu screen, I decided to give the user 5 different options to choose from that would give them a display of the movie listings of their choice. The only thing that this menu method doesn’t do is error handling. I decided that for the purposes of this project that error handling would be best demonstrated by going one level deeper. You will see this when you select option 1 from the main menu selection.
In order to demonstrate error handling effectively and ease the development of this program, I opted to implement it in the option 1 selection screen. At this point, the user is prompted to enter a movie selection of their choice from the display screen, and in the event they enter an invalid number or a non-numeric character as input, they will be greeted with a screen that indicates they have entered an invalid entry at which point they are prompted to try again.
Another thing that I got to play around with in this project that I haven’t talked about yet is the pry gem. This is a great tool for test driven development because it gives the developer an opportunity to test out the functionality of the code that they have written thus far and also give them an opportunity to come up with new, innovative strategies that they can implement along the way as they desire. I used this to test out all of my methods throughout the program, and it made me feel a lot more confident each and every time knowing that I always had an effective solution.
So hopefully you all enjoyed this glimpse of my new CLI application and I look forward to creating more applications just like this one in the future. Included down below is a link to my GitHub project in case any of you are curious and would like to test it out for yourselves. Have fun, and thanks for following along!