I have spent 85% of this week working on my Ruby/CLI project for Flatiron's FT Software Engineering class. We were tasked with taking an available and free API from the internet and pulling data from it. The data would be used in a Ruby program that would sort or search or manipulate in ways to give it an interactive element through the Command Line Interface (CLI). I spent a day looking through APIs and figuring out how I could use each of them. In the end, I went with Joakim Skoog's "An API of Ice And Fire" (https://www.anapioficeandfire.com/). I haven't read the Game of Thrones books, but I loved the show (up until the last season). The API was based upon the books but acknowledged the show by providing information such as a character's appearance in episodes or seasons. With there being SO MANY CHARACTERS, I opted to focus on the Houses, like Stark and Lannister.
My program, entitled "Welcome to Westeros", assumes you just moved to Westeros, where most of the main Houses reside. Since you're new and not sure where to settle, I show you the different regions and allow you to view the different houses of each region. You get to choose which Houses you want to be allies with, and which ones you can do without. To avoid overloading the user with options, I narrowed the information down by ensuring that the Houses we search through have a House motto ("words"). How else can you get to know a House if you don't know what they stand for?
Below is my recorded walk-thru of my project. Take a look before we continue.
Fun, right? Making it was not always fun. I went to every Open Office Hours this week, asking questions and seeing how my fellow students were doing. A brief timeline of this week would read something like this:
- Day 1: coding and feeling slightly optimistic
- Day 2: shooting for the moon with all the options I'll give the user
- Day 3: feeling like a fraud and an idiot and wondering why I can't do this; scaling back my project to present a respectable option or two
- Day 4: having a finished product that meets requirements. my first smile this week.
- Day 5: but I want it to do more! Let's try that query in the URL line again.
- Day 6: it's-done-it's-fine-stop-touching-it-lady-put-the-keyboard-down.
- Day 7: blog about this experience and turn it all in. Hi there!
I am grateful for the rollercoaster that was this week. As a beginner, it was an excellent learning experience in how to plan a project, map out the steps, and learn what I can and cannot do well (and also what I should and should not do). I am also grateful for our instructors, who were gracious enough to show us how to set up our project skeletons-- files, linking, example API use, etc. We were tasked with making it our own and from the projects I have seen, we did more than that. Kudos to my cohort!
Let's take a look at some of my highs and lows from this week.
The first big struggle came with how my API was presented vs. the examples my leaders provided. With using JSON to make our long list of data into a readable hash, I had a problem-- my data did not have a key I could call upon. Every object (in this case, each House from Westeros), was listed in an array, as one long hash, with its details in nested hashes. Each house did not have a key, like "House Stark", to call upon to help me sort out its contents. To a beginner, seeing this is a little overwhelming:
I'm glad we studied nested hashes and how they behave!
def create_houses self.fetch_houses.each do |house| House.new(house["name"], house["region"], house["words"], house["titles"], house["seats"], house["coatOfArms"], house["ancestralWeapons"]) end end
With create_hashes bringing in the API data, I was able to parse through every hash of data using .each and assign them workable attributes, like "name" and "region", with every new instance. Hashes and arrays are so similar with how you can manipulate them that I was able to treat the info as an array from here on out.
Another struggle with any kind of program like this is the "choose your own adventure" aspect of the program. You are trying to use each page in the appropriate spot without accidentally sending the user to the wrong page. You also Don't want to Repeat Yourself (D.R.Y.). To be frank, I still think there are areas of my finished code that are a little "wet," but I tried to give each new action a new method so I could avoid repeating myself as much as possible.
This is a small thing, but as I was towards the end of my initial coding spree, I wanted to do the following
- save all the House choices a user liked
- avoid adding repeat selections
- remove Houses previously selected
- print all chosen Houses upon exit
So what was I so proud of? I was able to write three simple methods in under an hour that accomplished all of these objectives. I feel accomplished that I was able to recall everything I learned about if/else statements, class variables, shoveling, and more. It was like I took Day 3 and proved it wrong. I could do this and I can belong.
Like the TV Game of Thrones, I am going to start this blog strong and finish on a poorly-written conclusion: this was fun, House Stark is awesome, and Ruby is a great programming language. Go Flatiron!