module GLPI::SDK::HashConverter

Public Class Methods

to_query(params) click to toggle source
# File lib/glpi/sdk/util/hash_converter.rb, line 4
def self.to_query(params)
  URI.encode_www_form(encode(params))
end

Private Class Methods

append_key(root_key, key) click to toggle source
# File lib/glpi/sdk/util/hash_converter.rb, line 23
def self.append_key(root_key, key)
  root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
end
encode(value, key = nil, out_hash = {}) click to toggle source
# File lib/glpi/sdk/util/hash_converter.rb, line 8
def self.encode(value, key = nil, out_hash = {})
  case value
  when Hash then
    value.each { |k, v| encode(v, append_key(key, k), out_hash) }
    out_hash
  when Array then
    value.each { |v| encode(v, "#{key}[]", out_hash) }
    out_hash
  when nil then ''
  else
    out_hash[key] = value
    out_hash
  end
end