DEV Community

Matt Gahrns
Matt Gahrns

Posted on

My First Ruby CLI

The Open Movie Database CLI Project

My Flatiron School Module 1 Project

View and download the project on GitHub.

Project Overview

This project uses the OMDb API in combination with SQLite to provide users with instant information about movies and the ability to create a list of favorite movies. The program starts by prompting the user to enter an existing username or create one. Upon successfully logging in the user can do a list of things.

  • Find a movie by title
  • Find a moie by IMDb ID
  • Add a movie to their favorites
  • List their favorite movies
  • View a movie's poster in their default browser
  • View a movie's website in their default browser
  • View all the movies that have been favorited by all users
  • See their favorite movies that have earned over $100 million dollars at the box office
  • See their favorite movies that have a IMDb 1-10 star rating over a number given by the user
  • See the movie that has been favorited by the most users
  • See the movie with the highest IMDb 1-10 star rating that any user has favorited
  • Change their username
  • Change their password
  • Delete a movie from their favorites
  • Delete all their favorites.

From anywhere in the program the user can simply type 'exit' and press enter to log off and close the program.

User Stories

  1. As a user, I want to be able to save to and retrieve a list of my favorite movies.

  2. As a user, I want to search for a movie by title or IMDb id to quickly get IMDb information about that movie.

  3. As a user, I should be able to see all the movies that have been favorited by all the users.

  4. As a user, I want to be able to search my favorites by IMDb star rating and box office earnings.

The OMDb API

The Open Movie Database API was a great tool to use for this project. It was my first time working with an API and this was a great one for that. I was also able to use a very handy gem called HTTParty that helped make API calls easy as pie. To make a call all I had to do was fill in a standardized url with the search parameters I wanted and my API key. Upon receiving the return values HTTParty helped me convert it into an easy to work with hash. Once I had the hash I could easily work and manipulate the values to do what I wanted.

SQLite

When a user wanted to save a movie to their favorites I would use the API to find the movie then I would store it in a database with SQLite. I had a table for Users, Movies, and a join table called FavoriteMovies. When ever a movie lost all of its favorites it was deleted from the Movies table.

Data Analytics

Due to the fact that the OMDb API finds one movie at a time and having limited time and resources for this project, all the analytics were done on the Movies table. By using ActiveRecord I was able to easily query my Movies table. However I did have an issue with one query as it took me a while to translate it from SQL into ActiveRecord syntax. Here is a code snippet of the final implementation of that query: https://imgur.com/ZUOLMgL . I had to chain 4 ActiveRecord methods together to achieve the result I wanted and it took me many tries to get the order of the chaining right. I'd also like to shout out Google, Stackoverflow and the ActiveRecord documentation for getting me through that one.

Conclusion

This project was a great way to jump into working with APIs and really helped solidify my skills in Ruby and building relationships between models. I improved my skills with ActiveRecord and got experience with using a lot of cool Gems. I think IMDb is a great application and getting to use the OMDb API was really cool.

Top comments (0)