DEV Community

Desiree Lerma
Desiree Lerma

Posted on

The TV Encyclopedia

Alt Text

This week I was tasked with creating my very first project with the Flatiron School. My emotions were an odd concoction of excitement and "dear God what the hell am I doing?!"
I reminded myself, on many occasions, take it step by step and don't try to build the world's best program (at least not in the beginning).

First and foremost, I needed to find an API that would be fun for me to work with and that wouldn't want to know my precious credit card numbers. Alas, I found one that involved one of my favorite hobbies... television (right next to movies).

Tv Maze

This API was a beaut. It gave me access to search shows by simply adding their names to a query at the end of the URL (i.e http://api.tvmaze.com/search/shows?q=the office) and it will adjust to bring back further information regarding the show you're looking for. Fun! However, this data isn't immediately brought to me tied in a pretty bow. I had to put it in a pretty bow myself.

Learning how to utilize and present data from an API was definitely a major learning point for me.

Alt Text

Initially, I need to fetch_info which would be the method to tie my data in a pretty bow. I assign a URL variable to that of my API's URL. Then I create a uri variable to call to URI(url). This essentially, allows my class to handle URI (aka Uniform Resource Identifiers).
I then had to send a request for my desired information and to do so I had to use the code Net::HTTP.get(uri) and assign it to the variable response (logically titled because it is the response we get from the API).
Finally, to make my response a readable one and not a jumbled mess, I needed to use JSON and parse through the response to have it returned in an organized, listed fashion. I wanted to store this data into a variable, once again, logically titled info.

Another fun thing I re-learned and utilized in my project was removing unnecessary characters from a returned string. In my show's returned summary I had some hidden HTML code. Well guess what? There was a simple fix to this! My good friend .gsub came into play here. Global Substitute, aka .gsub, takes in 2 arguments: what you want to remove from the string and what you would like to replace the removed item with. Below is an example:

show.summary.gsub('<p>', '')

I was ecstatic that I got something fun to play with. I know, personally, when I watch a show or a movie I enjoy knowing all the details. Or if it is a show I've never seen before I'd like to get a quick overview. BAM! The lightbulb in my head nearly blew out.

My project allows the user to view a list of popular television programs. From that list the user can view information such as the average rating, if the show is still in production, and even a short summary of what it's about. Then, if the show piques their interest, the user can save it to their favorites. If you'd like to give my project a spin you can access it on my Github.

Top comments (0)