Well here I am, building my first RubyGem. How did I even get here? Did I black out up until this point? Do I even remember learning anything about APIs? Except maybe a few mentions here and there in between lessons? I do remember thinking one thing when I first learned/heard about APIs, “Nice, someone did all the work and I can just use their code.” Lazy, I know, right? Obviously, it’s an important part of programming but never in a million years did I think I would be building my own RubyGem, using an open API and understanding it.

I’m starting off on Codecademy to familiarize myself with using APIs.

Alright so scratch everything I just said, back to the drawing board. It turns out I don’t want to use a public API right now…I was a little hasty in my decision earlier. I want to reinforce everything I just learned in Object Oriented Ruby and Scraping.

Let’s choose a website I want to scrape. I currently live in Ohio, but I lived in Raleigh, NC for the last five years. I LOVED IT and hope to move back in six months. While my husband and I lived there, we used this website, www.get-offline.com A LOT. It was awesome because it shows all of the upcoming events in the area, from stuff to do with friends, romantic dates, outdoorsy adventures, places to take your pups and alcohol endeavors. Everything I needed for a great social life in Raleigh is all on one site. So, that is how I decided I really want to scrape www.get-offline.com and create a CLI gem.

I started off watching a lot of videos, and reading different blogs. The most helpful video was Video- CLI Data Gem Walkthrough from the Dean of Flatiron School, Avi. I honestly don’t know what I would have done without this video. It was a tutorial on how to create a CLI gem.

I created my gem using bundler. Using bundler removed a lot of confusion for me because it provided me a skeleton for my ruby gem. From here, I was able to edit then start coding. Turns out, I feel like I actually know what I’m doing. Coding went fairly smoothly. I spent a little extra time when scraping www.get-offline.com. I must say I really appreciate a company who writes easily-readable code, it makes my life much easier to scrape when the HTML is flawless.

One thing I learned about myself while using bundler is that I’m lazy. I didn’t look closely enough in my spec to edit/add crucial information to get my gem up and running. Here is an error message I learned to hate but also love (and also showed me I was extremely lazy for not seeing this in the first place):

The gemspec at /Users/laniberry/Development/code/raleigh_events/raleigh_events.gemspec is not valid. Please fix this gemspec. (Gem::InvalidSpecificationException)

The validation error was ‘”FIXME” or “TODO” is not a description’.

In the basic skeleton bundler provides, it literally says

spec.authors = [TODO:fill in ]

spec.email = [TODO: fill in]

…or something along those lines.

Everything was running smoothly, I thought, “oh my goodness, I think I have a working gem! Let’s publish this baby!” I went to How to publish your gem and from there I was able to build it using ♥ gem build raleigh_events.gemspec then push it using ♥ gem push raleigh_events-0.1.1.gem. Seeing these next two lines made me the happiest person alive:

Pushing gem to https://rubygems.org...

Successfully registered gem: raleigh_events (0.1.1).

That moment was fleeting because when I actually tried to run my gem as a user, it didn’t work. I installed it, then tried running it with “raleigh_events” and I got:

-bash: raleigh_events: command not found.

It turns out I was being lazy again and I missed a minor detail.

In my `gemspec` there is `spec.executables` I had to set it to the word/phrase I want to execute/run the gem, like this `spec.executables = “raleigh_events”`. I fixed it and thought, this has to be complete. I was wrong. Another error:

`require’: cannot load such file — ./lib/raleigh_events (LoadError)

Luckily, I’m getting better at reading errors, with the help of my wonderful friend, google and the amazing network of the Learn community. It was a simple fix. Instead of

require ‘./lib/raleigh_events’,

I needed

require ‘../lib/raleigh_events’

One missed period makes a world of a difference. New error! I can’t run my gem:

// ♥ raleigh_events

/Users/laniberry/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121:in `require’: cannot load such file — ./lib/raleigh_events (LoadError)

Low and behold my gem works! After publishing my gem, I had to keep making changes. Which means I had to gem build, gem push and change the version in my text editor four different times. I now have a working gem, raleigh_events 0.1.4. A big lesson for me was to go slow, read through everything and pay attention to punctuation and every little detail. I learned a great deal, and it reminds me that I made the right decision to become a Software Developer.

Like what you read? Give Lani Berry a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.