def list_directory(dir_path, opts = {})
      url     = obj_url(dir_path)
      headers = gen_headers(opts)
      query_parameters = {}

      limit = opts[:limit] || MAX_LIMIT
      raise ArgumentError unless 0 < limit && limit <= MAX_LIMIT
      query_parameters[:limit] = limit

      marker = opts[:marker]
      if marker
        raise ArgumentError unless marker.is_a? String
        query_parameters[:marker] = marker
      end

      attempt(opts[:attempts]) do
        method = opts[:head] ? :head : :get
        result = @client.send(method, url, query_parameters, headers)
        raise unless result.is_a? HTTP::Message

        if result.status == 200
          raise unless result.headers['Content-Type'] ==
                       'application/x-json-stream; type=directory'

          return true, result.headers if method == :head

          json_chunks = result.body.split("\n")

          if json_chunks.size > limit
            raise CorruptResult
          end

          dir_entries = json_chunks.map { |i| JSON.parse(i) }

          return dir_entries, result.headers
        end

        raise_error(result)
      end
    end
def list_directory(dir_path, opts = {})
      url     = obj_url(dir_path)
      headers = gen_headers(opts)
      query_parameters = {}

      limit = opts[:limit] || MAX_LIMIT
      raise ArgumentError unless 0 < limit && limit <= MAX_LIMIT
      query_parameters[:limit] = limit

      marker = opts[:marker]
      if marker
        raise ArgumentError unless marker.is_a? String
        query_parameters[:marker] = marker
      end

      attempt(opts[:attempts]) do
        method = opts[:head] ? :head : :get
        result = @client.send(method, url, query_parameters, headers)
        raise unless result.is_a? HTTP::Message

        if result.status == 200
          raise unless result.headers['Content-Type'] ==
                       'application/x-json-stream; type=directory'

          return true, result.headers if method == :head

          json_chunks = result.body.split("\n")

          if json_chunks.size > limit
            raise CorruptResult
          end

          dir_entries = json_chunks.map { |i| JSON.parse(i) }

          return dir_entries, result.headers
        end

        raise_error(result)
      end
    end
Gets a lexicographically sorted directory listing on Manta at a given path,

 The path must start with /<user>/stor or /<user/public and point at an
 actual directory. :limit optionally changes the maximum number of entries;
 the default is 1000. If given :marker, an object name in the directory,
 returned directory entries will begin from that point. :head => true can
 optionally be passed in to do a HEAD instead of a GET.

 Returns an array of hash objects, each object representing a directory
 entry. Also returns the received HTTP headers.

 If there was an unrecoverable error, throws an exception. On connection or
 corruption errors, more attempts will be made; the number of attempts can
 be altered by passing in :attempts.