change API methods to use metaprogramming

Hey :) I just stumbled upon your gem and realized that code I wrote for my application is quite similiar but much shorter and thought you may want to merge it. I will probably also contribute some tests in near future (another PR).