Fix version handling so that it builds on Ruby 2.0+

The essential part is 344922465205ef31637926dadf018e00627b320b which fixes the gem build error.
It seems like it's not a good idea to use the internal constants in gemfile. I borrowed the code from faraday.

I also added some refactoring commits which do not affect the code meaning. If you don't like it, please feel free to cherry-pick the commit.