protected function doRequest(Client $client, $url, $options = array())
    {
        $options += array(
            'urlParams' => array(),
            'queryParams' => array(),
            'method' => static::METHOD_GET,
        );
        $token = $client->getToken();

        // Replace parameters in the url.
        $urlReplacements = $this->getParameterReplacements($options['urlParams'], $token);
        $url = str_replace(array_keys($urlReplacements), array_values($urlReplacements), $url);

        // Replace query parameters.
        $queryReplacements = $this->getParameterReplacements($options['queryParams'], $token);
        $queryParams = array_merge($options['queryParams'], $queryReplacements);

        // Process query parameters.
        $queryParams = $this->processQueryParameters($queryParams);

        // Set the request uri.
        $client->setUri($this->credentials->getEnvironment()->getBaseUrl() . $url);

        // Set the parameters.
        switch ($options['method']) {
            case static::METHOD_POST:
                $client->setParameterPost($queryParams);
                break;

            case static::METHOD_GET:
            default:
                $client->setParameterGet($queryParams);
                break;
        }

        // Set the request method and send the request.
        $client->setMethod($options['method']);
        $response = $client->send();

        // Below are all possible error codes as described bij de api
        // documentation.
        $statusCode = $response->getStatusCode();
        switch ($statusCode) {
            // No content.
            case 204:
                return null;
            // Bad request.
            case 400:
            // Missing Authorization header.
            case 401:
            // Unauthorized.
            case 403:
            // Not found.
            case 404:
            // Misdirected request.
            case 421:
            // Any other undocumented error codes.
            case $statusCode >= 400:
                throw new BibException($response->getReasonPhrase(), $response->getStatusCode());
        }
        $doc = new \DOMDocument();
        $doc->loadXML($response->getBody());
        return $doc;
    }