Building my first CLI project. Tips, and tricks I learned a long the way.

After finishing my first mile with FlatIron, hearing about our first big project personally scared me and had no clue what I was going to do. I first had the idea to do a MCU movie countdown project. Getting half way through it I landed on an issue. The site worked but the hash was weird and made no sense. Thankfully I had my amazing cohort help me find a perfect project to work on. Building a calendar based on Holidays here in the U.S.

Basic Concept of the Lab

The basic concepts I wanted for this lab is for the user to have 3 options to choose from.

List the holidays in the U.S.

Select any holiday on the list and learn more information about it.

Have the choice to return to the menu or to exit the program.

Easy concepts, and easy to do. Now is the process of learning how to create the application. Watching countless videos again it wasn’t to terribly hard to manage. I created a GEM from my previous project attempt just had to rename the file. But the next steps I had to learn new which was:

How to upload my project GitHub and push the file from the terminal to there.

How to use and place an API key into my program

Remembering how to do the coding process with little to know panicking (We Got This!)

Figuring out how to use pry.

“Pry” = Your best friend

“Pry” was honestly the biggest help in making my code. But I will admit, I didn’t like “pry” but also was so confused by it in the beginning when first started coding. But to make sure I didn’t end up in the same situation as before with the MCU countdown, it turned out to be my best friend. I had to make sure that when selecting any holiday that it would make a new request in the API and return the string of information that was in its hash.

Scraping a site or to use an API

When it came time to scrape a website I honestly had no clue and was so lost. It seemed really confusing and with many steps. But when my cohort mentioned API’s and how easy it was. After watching a lecture in class about API’s it made way more sense than full on scraping a website. You first create an API class then define a method to grab the data from the site. so we use self.get_data. When putting the specific API link into the program we have to use RestClient which is a simple way to access HTTP and Rest resources. With all that said it should end up looking like this.

hash => {“data”}

Now to grab data and information from the site. Here we will use “binding.pry” in the program to find the sites information and return an array of holidays. It was very intimating and seemed like a never ending list of data but that’s where “JSON.parse” comes in and helps make the hash a bit neater and easier to read. Easily finding what information and data I wanted to use and add to my project. So that when a user selects a holiday it returns information that I chose from the hash.

Assigning certain keys to their instance variable I created in the class I created and called Holidays. The information inside the selected keys will be equal to their instance variable. That way through the entire program the information will be accessed and manipulated.

Hash and Keys

Looking at this code I have keys and instance variables I chose from my hash. But what if I wanted to add more so the user has more information when they select any certain holiday? Hash and keys will allow me to do that without having to pass them in individually. Using self.send creates all the key invalue pairs instead of having to write out a bunch of them.

Now its running all the keys and running into a no method error. It’s hitting a key I don’t have added into my code. So to keep that from happening I want to do an if statement right after self.send(“#{key}=”, value).

What that does is that it will only run what keys I have written in my attr_accessor if those keys exist.

How did pry really help me?

Though its not much of an example, “pry” helped me find the information I needed for the program and to make sure my program was running smooth and not hitting any errors. “Pry” is a great tool to have when building a Ruby program