Sha256: 39ba66ff90f60b47d8678e79498339c7aaf4536f51796bdd295ec25470e7fb45

Contents?: true

Size: 504 Bytes

Versions: 19

Compression:

Stored size: 504 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.33 lib/phrase/api/query_params.rb
phrase-0.4.32 lib/phrase/api/query_params.rb
phrase-0.4.31 lib/phrase/api/query_params.rb
phrase-0.4.30 lib/phrase/api/query_params.rb
phrase-0.4.29 lib/phrase/api/query_params.rb
phrase-0.4.28 lib/phrase/api/query_params.rb
phrase-0.4.27 lib/phrase/api/query_params.rb
phrase-0.4.26 lib/phrase/api/query_params.rb
phrase-0.4.25 lib/phrase/api/query_params.rb
phrase-0.4.24 lib/phrase/api/query_params.rb
phrase-0.4.23 lib/phrase/api/query_params.rb
phrase-0.4.22 lib/phrase/api/query_params.rb
phrase-0.4.21 lib/phrase/api/query_params.rb
phrase-0.4.20 lib/phrase/api/query_params.rb
phrase-0.4.19 lib/phrase/api/query_params.rb
phrase-0.4.18 lib/phrase/api/query_params.rb
phrase-0.4.17 lib/phrase/api/query_params.rb
phrase-0.4.16 lib/phrase/api/query_params.rb
phrase-0.4.15 lib/phrase/api/query_params.rb