Created
October 25, 2011 19:19
-
-
Save diago/1313915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts a hash into a query string | |
# | |
# Hash keys can be underscored names | |
# @example | |
# { :service_type => 'rsemail' } | |
# | |
# Or the Rackspace API expected string | |
# | |
# @param [Hash, #to_hash] hash to convert | |
# @return [String] query param | |
def query_string_from_hash( hash ) | |
hash.to_hash.collect do |k, v| | |
key, *keys = k.to_s.split( '_' ) | |
key << keys.map( &:capitalize ).join( '' ) | |
"%s=%s" % [ key, URI.escape( v.to_s ) ] | |
end.join( '&' ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment