First CLI project -Harry Potter Sorting Hat
Published: 2020-12-07 04:28:58

This is my first project at Flatiron school. It is a CLI program that gets data from an API and works through different menus(methods) to output specific details.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ixnrk6kthrhsq8rheuae.jpg)

I decided to use a Harry Potter API and after looking at the information it provided, I thought the best route would be to divide the data up by Hogwarts houses. Of course in Harry Potter, when a new student comes to Hogwarts, one of the first things they do is sit with the sorting hat on their head and get placed into a house. I thought it would be really cool to have a program that acts as the sorting hat.

The first thing I did was set up my file structure and auto installed all the folders. The set up was kind of confusing and overwhelming so I reached out to my class mates and they helped me clean up the files to just what I needed for this program. In my bin directory I needed a run file. This tells the project where to start and also uses the shebang line to let it know the code is in ruby. In the lib directory I needed an environment file, a models folder, and a services folder. 

My environment file is set up so that all the other files can talk to each other. So when I call upon my my Characters class inside of my Cli class, it will know where to look. The environment folder also holds my gems needed to complete this project.

My models folder held my Characters class which initialized the information I would be using in the program. I also have a method in here that choses a house at random. When running the program I realized that my API had some hidden information. Some characters were stored that did not belong to houses. This included Argus Filch, the caretaker of the school and his cat, Mrs. Norris. So when a blank house was chosen it would show up empty. I was able to add an if statement that said if the house was empty, run the randomizer again. This took care of that problem.

My services folder held my Api class and my Cli class. The Api class was in charge of getting the data from the website and parsing it. I used JSON to do that. Whenever I needed this data I could call on the Api class and apply it to certain parts of my code. So it was basically the gateway from my program to the data online.

The Cli class was in charge of the structure and function of the program. In here I made lots of menus that would access further menus until the application was exited. After being welcomed to Hogwarts, you would be assigned a house. Once a house was chosen, you were asked if you would like to meet your house mates. Upon choosing yes, the characters in that house were listed with numbers so you could chose by number. After choosing one, a string was outputted with the characteristics for that character. I displayed their name, house, ancestry, and patronus. After running the program multiple times I saw that some characters do not have all of these characteristics. I made an alternate output statement so if the information was blank, it would not be an empty spot in my sentence. I also had a method to take care of any invalid choices, get input, and exit. I referenced these multiple times around my code so it was easy for the user to flow through the program. 

I learned so much through out this project. Things that I was only beginning to grasp now feel natural to do. I am very proud of my work and the outcome. Its awesome that I was able to do this project on such a fun API and I hope my professors enjoy it too.