Sha256: f723ef0212e20360c609b4edd512511c70921425899fa8aa974b7532f68c4047

Contents?: true

Size: 1.04 KB

Versions: 32

Compression:

Stored size: 1.04 KB

Contents

module Restfully
  module HTTP
    module Helper

      def sanitize_head(h = {})
        sanitized_headers = {}
        h.each do |key, value|
          sanitized_key = key.to_s.
            downcase.
            gsub(/[_-]/, ' ').
            split(' ').
            map{|word| word.capitalize}.
            join("-")
          sanitized_value = case value
          when Array 
            value.join(", ")
          else 
            value
          end
          sanitized_headers[sanitized_key] = sanitized_value
        end
        sanitized_headers
      end
    
      def sanitize_query(h = {})
        sanitized_query = {}
        h.each do |key,value|
          sanitized_query[key] = stringify(value)
        end
        sanitized_query
      end
      
      protected
      def stringify(value)
        case value
        when Hash
          h = {}
          value.each{|k,v| h[k] = stringify(v)}
          h
        when Array
          value.map!{|v| stringify(v)}
        else
          value.to_s
        end
      end
    
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
restfully-1.3.0 lib/restfully/http/helper.rb
restfully-1.2.0 lib/restfully/http/helper.rb
restfully-1.1.1 lib/restfully/http/helper.rb
restfully-1.1.0 lib/restfully/http/helper.rb
restfully-1.0.8 lib/restfully/http/helper.rb
restfully-1.0.7 lib/restfully/http/helper.rb
restfully-1.0.6 lib/restfully/http/helper.rb
restfully-1.0.5 lib/restfully/http/helper.rb
restfully-1.0.4 lib/restfully/http/helper.rb
restfully-1.0.3 lib/restfully/http/helper.rb
restfully-1.0.2 lib/restfully/http/helper.rb
restfully-1.0.1 lib/restfully/http/helper.rb
restfully-1.0.0 lib/restfully/http/helper.rb
restfully-1.0.0.rc2 lib/restfully/http/helper.rb
restfully-1.0.0.rc1 lib/restfully/http/helper.rb
restfully-0.8.8 lib/restfully/http/helper.rb
restfully-0.8.7 lib/restfully/http/helper.rb
restfully-0.8.6 lib/restfully/http/helper.rb
restfully-0.8.5 lib/restfully/http/helper.rb
restfully-0.8.4 lib/restfully/http/helper.rb