/**
  * Handle the event
  *
  * @param string $url
  * @param \React\Promise\Deferred $deferred
  */
 public function handleShortenEvent($url, Deferred $deferred)
 {
     $requestId = uniqid();
     // Only urls longer than the minimum length should be shortened
     if (strlen($url) < $this->adapter->getMinimumLength()) {
         $this->logDebug('[' . $requestId . ']Skip shortening url (too short): ' . $url);
         $deferred->resolve($url);
         return;
     }
     // Check if URL host is one we're skipping
     $host = parse_url($url, \PHP_URL_HOST);
     if (in_array($host, $this->skipHosts)) {
         $this->logDebug('[' . $requestId . ']Skip shortening url (based on hostname): ' . $url);
         $deferred->resolve($url);
         return;
     }
     $this->logDebug('[' . $requestId . ']Shortening url: ' . $url);
     $request = $this->adapter->getApiRequest($this->adapter->getApiUrl($url), $deferred);
     $this->getEventEmitter()->emit('http.request', [$request]);
 }
 /**
  * Tests getApiUrl().
  */
 public function testGetApiUrl()
 {
     $apiUrl = $this->adapter->getApiUrl('http://example.com/');
     $this->assertRegExp('/^https?:\\/\\/([0-9a-z.\\-]+)\\.([a-z.]{2,6})\\/[0-9a-z\\-._~+%\\/?=]*$/i', $apiUrl, 'getApiUrl failed to return a valid URL');
 }