Sha256: 6f9a0f0aaf800d4532800b4d711413d3459f832a57866c2f312338a504c6adae

Contents?: true

Size: 469 Bytes

Versions: 6

Compression:

Stored size: 469 Bytes

Contents

module Elevate
module HTTP
  module URI
    def self.encode_query(hash)
      return "" if hash.nil? || hash.empty?

      hash.map do |key, value|
        "#{URI.escape_query_component(key.to_s)}=#{URI.escape_query_component(value.to_s)}"
      end.join("&")
    end

    def self.escape_query_component(component)
      component.gsub(/([^ a-zA-Z0-9_.-]+)/) do
        '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
      end.tr(' ', '+')
    end
  end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
elevate-0.5.0 lib/elevate/http/uri.rb
elevate-0.4.0 lib/elevate/http/uri.rb
elevate-0.3.3 lib/elevate/http/uri.rb
elevate-0.3.2 lib/elevate/http/uri.rb
elevate-0.3.1 lib/elevate/http/uri.rb
elevate-0.3 lib/elevate/http/uri.rb