= Spitter {}[http://travis-ci.org/bonsaiben/spitter] {}[https://gemnasium.com/bonsaiben/spitter]
Takes nice Ruby parameter hashes and spits out whatever crap you need it to. A simple way to provide a custom Ruby interface for the request side of an API wrapper. Based on @mislav's nibbler[https://github.com/mislav/nibbler].
== Installation
gem install spitter
== Example Usage
=== Transform Key
class ApiClient < Spitter
parameter :ruby_param => 'apiCamelCaseDataFlag'
end
$ ApiClient.parse(:purchasable => '1')
=> {'apiCamelCaseDataFlag' => '1'}
=== Transform Value with Lambda
class ApiClient < Spitter
parameter :ruby_param => 'apiCamelCaseDataFlag', :with => lambda {|v| v ? '1' : '0'}
end
$ ApiClient.parse(:purchasable => true)
=> {'apiCamelCaseDataFlag' => '1'}
=== Transform Value with Class
class ApiClient < Spitter
class TrueOrFalse
def self.parse(val)
val ? '1' : '0'
end
end
parameter :ruby_param => 'apiCamelCaseDataFlag', :with => TrueOrFalse
end
$ ApiClient.parse(:purchasable => true)
=> {'apiCamelCaseDataFlag' => '1'}
=== Transform Value Only
class ApiClient < Spitter
parameter :timestamp, :with => lambda{|v| v.to_i.to_s }
end
$ ApiClient.parse(:timestamp => Time.now)
=> {'timestamp' => '1341162393'}
== License
(The MIT License)
Copyright (c) 2012 Benjamin Sullivan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
== Credit
Spitter is based on @mislav's nibbler[https://github.com/mislav/nibbler].