26 May 2013

Buff - A Gem that Puts Muscle in the Buffer API

It’s Done! Buff is a Ruby Gem that wraps the Buffer API.

Why Write Buff Gem from Scratch?

Because the current Buffer Gem doesn’t have full coverage for the API. I started to update the Buffer Gem but quickly realized that I was spinning my wheels. I wanted to implement the gem as a set of layered abstractions and to be able to process the responses using Hashie::Mash. I envisioned a Gem where each response was a first class Ruby object, where each nested key could be called as a method.

I realized that it would be cleaner and more expedient to code from scratch: I spent the next few hours and produced a gem that had feature parity with Buffer’s existing gem:

Introducing Buff, the API complete Ruby Wrapper for BufferApp.com. Buff muscles Ruby into Buffer’s API.

Buff is RSpec tested, Webmocked, Travis CI’d, and easy to use.

Setbacks and Triumphs

It wasn’t all roses and perfume in the creation of this gem. Three setbacks stand out in my mind.

Webmock

I’ve previously used VCR for testing web APIs, but wanted to use a new system to build new skills. Webmocks are very pleasant to use and allowed the Specs to verify what API was contacted, along with testing the body content and return values.

HTTP Libraries

Buff Gem started with HTTParty , which was splendid while implementing the HTTP GET API methods. Once I began implementing the HTTP POST requests I started experiencing discomfort with using HTTParty. It’s a reliable library but I didn’t gel with the DSL for describing HTTP requests. Thankfully the HTTParty calls were wrapped inside the post and get methods in Buff::Client::Core.

Since the code was tested with Rspec and the post and get methods were abstracted, swapping out HTTParty for Faraday was merely a one hour setback.

What a wonderful confirmation that it’s valuable to wrap external library calls in an abstraction method inside your own library. This made dependency swaps much simpler.

Creating correct “application/x-www-form-urlencoded” Data

I expected to find a Standard Library tool for converting a nested Hash + Array object into www-form-encoded data. I was sorely disappointed, looking at you Addressable Gem, and spent hours trying to find an already coded solution.

After stepping back from the code for two days, I was explaining the problem to non-technical coworkers. In that moment, my subconscious presented the answer. I realized how easily I could write the transformation myself. I mentally coded it on the way home that afternoon and wrote it in bytes that evening. Here’s the implementation from Buff::Client::Encode:

Moral of the story : When stumped, back off and solve another problem. The subconscious is a useful ally. Hours of struggling could have been saved through patience and getting other things done.

What’s Next?

Since the Buff Gem provides greater coverage of the Buffer API than the existing Gem, it’d be awesome to see it replace Buffer Gem as the official Ruby Wrapper.

I feel great about completing a Gem with 100% coverage of an HTTP API :).

I’m considering writing a couple of small Buffer CommandLine tools for easy posting. If I have more steam, I’ll add an Alfred Workflow on top that allows posting to Buffer!

Want a Demo of Using Buff inside Pry?

PS

If you work with Bufferapp and want to adopt this Gem as your Official Ruby Wrapper, that would be snazzy. Let’s talk: @_ZPH or Zander!

04 May 2013

Privilege Means Responsibility

Let’s redefine privilege

Because it’s not working well for our society. Here’s what we have right now: Privilege : advantage, benefit; prerogative, entitlement, right; concession, freedom, liberty. Advantage, benefit, freedom, liberty: those are all accurate words for what I disproportionately enjoy with being a privileged member of society. In fact, I’ve got just about all of the social advantages that one could ask for with being white, male, able bodied, living in a well off country and a few other choice characteristics. I rolled mostly 20 in this attempt at life. Because of my family’s assistance and scholarships, I also had the advantage of completing my Bachelor’s Degree. Did I mention that my parents both had college degrees or better when I was young?

Where this puts me in life according to statistics:

According to US Census data from 2010 median income varies significantly along ethnic lines: - White = $54k - Black = $32k - Hispanic = $37k According to US Census data from 2009 that compares income of full time workers based on education and sex for my age: - Male = $67k - Female = $52k How about the fact that during my childhood, I had one parent with a professional degree and one with a bachelor’s degree? Poverty Based on Parent's EducationTo summarize, statistics indicate that I earn $1.69 for every $1 that a black person will earn, $1.29 for every $1 that a woman earns, and my odds of being a child in poverty were ~ 14 that of a child raised by parents without a high school diploma. This is purely a function of my genetic and socio-economic background not about any shred of my own accomplishments. It bears repeating that the fact that I have an advantage in earning power as outlined in this paragraph has nothing to do with my own merit. Want to argue these statistics? A study found that transgender women earned 32% less on average following their transition from male to female! SourceI’ve faced some challenges in life, but they’re a lot easier to overcome when playing with a stacked deck.

I’m Privileged So…

I’m introspective enough to admit that I haven’t always been as aware of my advantages as I am now. Being a few decades into life, living meagerly for a decent chunk of my twenties, and traveling outside of the United States has opened my eyes. Having friends who are different than myself has opened my eyes. Listening to smart people who have huge hearts has also opened my eyes. Witnessing people who live in abject poverty has opened my eyes. And this process isn’t over, I’m still learning. A couple of months back was my first exposure to the term ‘ableism’. I hadn’t previously considered that calling someone ‘dumb’ harkenens back to this definition dumb : offensive (of a person) unable to speak, most typically because of congenital deafness: he was born deaf, dumb, and blind. Or that using the word ‘insane’ as a pejorative probably refers to individuals who suffer from schizophrenia and who historically faced persecution and death.

I’m still learning

I’m proud of where I’ve gotten to in my approach to the world, but I want to share an example or two of my own past prejudices. I share them not because I’m proud of my behavior, quite the contrary; I share them to show that it’s a learning process. When I was in elementary school, I remember seeing another child on the basketball court. In most respects, he appeared quite similar to me. But his elbows and arms were covered in scaly, reddened skin that cracked and bled. I remember my revulsion and how I avoided him. I can’t say that I thought much of that child after moving on from elementary school. I became busy with school, friends, baseball and listening to music. In high school I started having to deal with my own challenge in life called psoriasis. Psoriasis is an autoimmune disorder where cells reproduce much faster than normal, causing intense itching and discomfort. It wasn’t until a few years into dealing with psoriasis that it dawned on me: that child who I avoided suffered from the very skin disorder as I did.

Join Me

As it stands now, I’m playing the game of life with a stacked deck. I face less consequences for raising my voice in support of individuals who don’t have that luxury. I have better financial resilience to deal with social opposition as I work towards better equity in our society. It’s not only my choice to do this, it’s also my responsibility that comes with the hand I was dealt. I’m going to take a stand on issues of gender equality, racial equality, sexual orientation equality (and more broadly the right to be yourself), disabled rights, bullying, and marginalizing behavior. I may not get it all right, but I welcome receiving feedback so that I can improve. The next time you see someone use a pejorative based on race, disability, sex, or someone bullying another individual:Don’t fucking let it slide! Stand up and lend your voice to the conversation. Your voice offsets the hatred and bigotry that is being leveled against someone. You’ll be glad you took a stand and you’re making this world of ours a better place.