Third Time is a Charm

Baldomero Vela III
5 min readDec 7, 2020

Wow end of phase 1 already. Learning Ruby at Flatiron with my cohort, even with the pandemic’s unique sense of psychological time dilation, this first chapter has gone by so fast. So our final project is all about mastering the basics of designing, implementing and polishing a single application that can interface with an API. Now would you believe that in a span of about a week, I ended up creating three different attempts to satisfy minimum viable product requirements?

Take One: In charta mortuus est

I remember Friday, still a bit behind on labs. The notion was simple, I called it Y.A.R.N. for “Yet Another Random NPC” with the idea that I could have a simple Ruby gem as a tool that I might expand on for one of my favorite hobbies, table-top roleplaying games. But sadly that idea never left the pages of my notebook, melding that nascent idea with a fully versed system for querying a freely accessible API and be something that could be done in a week was given the advice of my friends and far more accomplished programmers Andrew and Jesse, would be in a word excessive. So sadly, YARN would remain a few pseudocode and rambling scribblings on paper.

Take Two: Dusting Off

Months ago, which in pandemic time, feels like a century, I was chief marketer for a small chain of therapy clinics. I and my junior teammate were charged with the handling and interaction of our office both with our existing referring partners, and with establishing our brand with other professional offices. At the start of my tenure, my predecessors had left behind nothing. No address book, nor map of referring partners — not even a Rolodex. So my first few weeks and months involved several hours a day manually building an Excel workbook of addresses and contacts. This served a variety of purposes. First I could check off and filter places that I needed to visit, building a work order for myself, and dump the physical locations into an online navigation aid to solve the Traveling Salesman problem that it would entail. Because although I was issued payment by the mile. Efficient use of time, vehicle wear, and gas mileage was important to me.

Once the pandemic hit though, driving around to doctors offices became a liability. The very notion of visiting potential hot-spots on the front line was simply untenable so I requested being shifted to working from home to work on our company website, and more interestingly on a small Python powered application that would query the Google Maps API for potential leads. The eventual aim, before being laid off, was to be able to have a reliable tool both to learn about newly opened potential referring clinics by their online presence, but also in the event that our company expanded locations, to rapidly expand our address book to include the perspective leads. Following a bit of Python lessons online, and viola a simple hard-coded query script was born. Built in Thonny, and spitting out oodles of chunky .json information about every Places object tagged with ‘doctor’ ‘internal medicine’ within five kilometers of our main office.

So fast forward to now a Flatiron Student, greeted with the dead idea that was YARN, the immediate consideration wasthe possibility of expanding up on the prior work. And sure enough, by around 5pm CST Friday, I had very quickly written a simple enough class in Ruby that when ran would query the Google servers using the #HTTP gem and parse the resulting data with the #JSON gem. Hell_Yeah_Brother.gif

Problem occurred when I wanted to go further, building up the data handling methods for presenting the results into something readable for human eyes. As we know, Google API queries are limited in volume. Go beyond a hard set cap, and big daddy Alphabet is gonna start nickels and dime-ing you for every return. So to prevent my neophyte code from constantly issuing queries, I only ran my ‘PlacesQuery.rb’ interfacing method once, with the added bit of code to have it export the results to a local file titled ‘sample.json.’ Easy-peasy, at least until I started loading that file into a global variable for handling it and testing out my other authored methods. Quite simply somehow ‘$BIGCHUNGUS’ — yes, I named a global variable after a meme, was loading into memory with all the json information twice. Now long after office hours were closed, rougly 6pm EST. Given that the Ask Any Question support team won’t touch student projects with a ten foot pole, and my cohorts screaming that “Dude, this is too hard, what are you doing.” I scrapped my Lead_Book_Builder.rb project.

Take Three:

[1:40 PM]getting mad at it won’t fix the problems

it will only tilt you

tilt is the mind killer

[1:41 PM] and boy, do you ever tilt when your code doesn’t do what you want

— Jesse R. friend and mentor.

Okay, so on to the actual break down of the project. Our Cohort Lead, Enoch Griffith provided us with a handy list of free and open API’s for us to use. Given that, I ran with the geography kick I was on, and elected to use the: https://restcountries.eu/

The app makes a single query to the API using the HTTP gem. It parses the raw data with the JSON gem, and then using an personally authored data container class ‘Country.rb’ instantiates a ‘Country’ object. Each instance, is stored in an array that is returnable by ‘#all’

The command line interface runs in a terminal. It greets a user and presents them with four options. First, is a listing method, to print out a long and human passable list of all the countries provided by the Rest Countries API query. So theoretically if the API is down or offline, it may not work. Additionally, if and when the countries on Earth recognized by the API changes, the app should dynamically load those changes when it’s launched when it loads in the terminal. The second option, is purely a fun random sample of the loaded array. The third menu option takes a user selected number for a country and passes it to the very important and memetically named ‘would_like_to_know_more_about(‘foo’)’ method. Which takes a passed instance of a country object and interpolates it’s assigned values to a CLI output. Option four, does exactly what it says on the tin and exits the program.

--

--