def flatten_params(obj, ns=nil)
      case obj
      when Hash
        pairs = obj.map { |k,v| flatten_params(v, ns ? "#{ns}[#{k}]" : k) }
        pairs.empty? ? [] : pairs.inject(&:+)
      when Array
        obj.map { |v| flatten_params(v, "#{ns}[]") }.inject(&:+) || []
      when Time
        [[ns.to_s, iso_format_time(obj)]]
      else
        [[ns.to_s, obj.to_s]]
      end
    end
def flatten_params(obj, ns=nil)
      case obj
      when Hash
        pairs = obj.map { |k,v| flatten_params(v, ns ? "#{ns}[#{k}]" : k) }
        pairs.empty? ? [] : pairs.inject(&:+)
      when Array
        obj.map { |v| flatten_params(v, "#{ns}[]") }.inject(&:+) || []
      when Time
        [[ns.to_s, iso_format_time(obj)]]
      else
        [[ns.to_s, obj.to_s]]
      end
    end
Flatten a hash containing nested hashes and arrays to a non-nested array
 of key-value pairs.

 Examples:

   flatten_params(a: 'b')
   # => [['a', 'b']]

   flatten_params(a: ['b', 'c'])
   # => [['a[]', 'b'], ['a[]', 'c']]

   flatten_params(a: {b: 'c'})
   # => [['a[b]', 'c']]

 @param [Hash] obj the hash to flatten
 @return [Array] an array of key-value pairs (arrays of two strings)