protected function fetchEndpointForUrl($url)
    {
        $client = new Client($url);

        $body = $client->send();

        $regexp = str_replace(
            '@formats@',
            implode('|', $this->supportedFormats),
            self::LINK_REGEXP
        );

        if (!preg_match_all($regexp, $body, $matches, PREG_SET_ORDER)) {
            throw new \InvalidArgumentException('No valid oEmbed links found on page.');
        }

        foreach ($matches as $match) {
            if ($match['Format'] === $this->preferredFormat) {
                return $this->extractEndpointFromAttributes($match['Attributes']);
            }
        }

        return $this->extractEndpointFromAttributes($match['Attributes']);
    }