Sha256: 86ba8dde13a43a156f924231b104170db4f08ea479a75b54fac070faea8bd582

Contents?: true

Size: 506 Bytes

Versions: 19

Compression:

Stored size: 506 Bytes

Contents

require "cgi"

class Phrase::Api::QueryParams
  def self.encode(value, key=nil)
    case value
      when Array then value.map { |v| encode(v, "#{key}[]") }.join("&")
      when Hash then value.map { |k,v| encode(v, append_key(key,k)) }.join("&")
      when nil then ""
      else
        "#{key}=#{CGI.escape(value.to_s)}" 
      end
  end

  def self.append_key(root_key, key)
    if root_key.nil?
      key
    else 
      "#{root_key}[#{key.to_s}]"
    end
  end
  private_class_method :append_key
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
phrase-0.4.14 lib/phrase/api/query_params.rb
phrase-0.4.13 lib/phrase/api/query_params.rb
phrase-0.4.12 lib/phrase/api/query_params.rb
phrase-0.4.11 lib/phrase/api/query_params.rb
phrase-0.4.10 lib/phrase/api/query_params.rb
phrase-0.4.9 lib/phrase/api/query_params.rb
phrase-0.4.8 lib/phrase/api/query_params.rb
phrase-0.4.7 lib/phrase/api/query_params.rb
phrase-0.4.6 lib/phrase/api/query_params.rb
phrase-0.4.5 lib/phrase/api/query_params.rb
phrase-0.4.4 lib/phrase/api/query_params.rb
phrase-0.4.3 lib/phrase/api/query_params.rb
phrase-0.4.2 lib/phrase/api/query_params.rb
phrase-0.4.1 lib/phrase/api/query_params.rb
phrase-0.4.0 lib/phrase/api/query_params.rb
phrase-0.3.7 lib/phrase/api/query_params.rb
phrase-0.3.6 lib/phrase/api/query_params.rb
phrase-0.3.5 lib/phrase/api/query_params.rb
phrase-0.3.4 lib/phrase/api/query_params.rb