module Faraday::NestedParamsEncoder

def self.dehash(hash, depth)

FIXME: this is not compatible with Rack::Utils.parse_nested_query
Internal: convert a nested hash with purely numeric keys into an array.
def self.dehash(hash, depth)
  hash.each do |key, value|
    hash[key] = dehash(value, depth + 1) if value.kind_of?(Hash)
  end
  if depth > 0 && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
    hash.keys.sort.inject([]) { |all, key| all << hash[key] }
  else
    hash
  end
end