Sha256: e9e4b65b6409fcaf20ee366d1b5b2a1859d9f27d0e0598b6fa5bf4928705e396

Contents?: true

Size: 1.12 KB

Versions: 45

Compression:

Stored size: 1.12 KB

Contents

module Signature
  # Query string encoding extracted with thanks from em-http-request
  module QueryEncoder
    class << self
      # URL encodes query parameters:
      # single k=v, or a URL encoded array, if v is an array of values
      def encode_param(k, v)
        if v.is_a?(Array)
          v.map { |e| escape(k) + "[]=" + escape(e) }.join("&")
        else
          escape(k) + "=" + escape(v)
        end
      end
      
      # Like encode_param, but doesn't url escape keys or values
      def encode_param_without_escaping(k, v)
        if v.is_a?(Array)
          v.map { |e| k + "[]=" + e }.join("&")
        else
          "#{k}=#{v}"
        end
      end

      private

      def escape(s)
        if defined?(EscapeUtils)
          EscapeUtils.escape_url(s.to_s)
        else
          s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) {
            '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
          }
        end
      end

      if ''.respond_to?(:bytesize)
        def bytesize(string)
          string.bytesize
        end
      else
        def bytesize(string)
          string.size
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 3 rubygems

Version Path
scout-5.9.13 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.12 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.11 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.10.pre vendor/signature/lib/signature/query_encoder.rb
signature-0.1.8 lib/signature/query_encoder.rb
scout-5.9.8 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.7.2.pre vendor/signature/lib/signature/query_encoder.rb
scout-5.9.8.pre vendor/signature/lib/signature/query_encoder.rb
scout-5.9.7.1 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.7.pre vendor/signature/lib/signature/query_encoder.rb
scout-5.9.5 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.4 vendor/signature/lib/signature/query_encoder.rb
scout-5.9.4.pre vendor/signature/lib/signature/query_encoder.rb
signature-acd-0.1.14 lib/signature/query_encoder.rb
signature-acd-0.1.13 lib/signature/query_encoder.rb
signature-acd-0.1.12 lib/signature/query_encoder.rb
signature-acd-0.1.11 lib/signature/query_encoder.rb
signature-acd-0.1.10 lib/signature/query_encoder.rb
signature-acd-0.1.9 lib/signature/query_encoder.rb
scout-5.9.3 vendor/signature/lib/signature/query_encoder.rb