DEV Community

Salmaan Ali
Salmaan Ali

Posted on

TodaysWeather: My first Ruby CLI Gem

It's now been close to 2 months since starting my software engineering journey with Flatiron. And I'm proud to announce that I've successfully created my first Ruby CLI gem using an object-oriented design. It's called TodaysWeather. And as you might guess, it provides the user with today's weather in the zip code of their choice.

The process was initially trickier than expected. Up until now, I've been building my fundamental dev skills through exercises with clear-cut answers. This was the first time that I had to tap into my own imagination and creativity to solve a problem from scratch using those new skills.

Once I decided on the purpose of the gem being to provide the user with the weather information, I hit my first roadblock. My experience so far had been solely with coding. But the first task of creating the gem was to create and organize the overall framework of files. Something I'd never done or experienced before. Where do I even start? Ugh. But with all other coding questions I've had so far, I immediately turned to Google. In a quick search, I learned that there's a simple command for creating the basic framework of files for a gem: $bundle gem project_name.

And it was great! It built the general framework and came with all the bells and whistles! The basic architecture of files. The MIT license. A README template that helps organize the developer's thoughts to the user. Sweet!! I was ready to get started!

Over the next 2-3 days, I coded the entire project with a few hurdles here and there. The main hurdles were staying focused on a single task at a time and properly organizing methods between the different objects I had created. I had to keep reminding myself to pace myself and to not worry too much about complete cleanliness now. Let's just get this thing working and then I can refactor it later to be more organized and concise.

I found a free weather API from OpenWeatherMap.org. I created an account with them and they provided me with a unique API key to access their weather data. I integrated the API key with my code and was successfully able to access their weather data stored in a hash.

I had previously linked my code to a repository on my GitHub account. After I had committed and pushed my updates, I got an alarming automated email from GitHub. My API key had been exposed. I immediately changed my repository settings to private and googled the situation.

I didn't even consider that my API key could be used by others on the internet. Fortunately, I had acted soon enough (much thanks to GitHub) that there weren't any problems. I deleted my original API key, generated a new one, and learned to save it in an environment variable that I could gitignore from being pushed to my public repository. Phew! That mistake could have costed me upwards of $2,000!

In the end, this was an extremely valuable experience. I learned a ton of new lessons and with my first gem successfully developed, I definitely gained some nice confidence boosts.

Stay tuned for more updates on this journey!

Top comments (0)