src/Block/Social/TwitterEmbedTweetBlockService.php
public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $tweet = $blockContext->getSetting('tweet');

        if (($uriMatched = preg_match(self::TWEET_URL_PATTERN, $tweet))
            || preg_match(self::TWEET_ID_PATTERN, $tweet)) {
            // We matched an URL or an ID, we'll need to ask the API
            if (false === class_exists('Guzzle\Http\Client')) {
                throw new \RuntimeException('The guzzle http client library is required to call the Twitter API. Make sure to add guzzle/guzzle to your composer.json.');
            }

            // TODO cache API result
            $client = new \Guzzle\Http\Client();
            $client->setConfig(['curl.options' => [CURLOPT_CONNECTTIMEOUT_MS => 1000]]);

            try {
                $request = $client->get($this->buildUri($uriMatched, $blockContext->getSettings()));
                $apiTweet = json_decode($request->send()->getBody(true), true);

                $tweet = $apiTweet['html'];
            } catch (CurlException $e) {
                // log error
            }
        }

        return $this->renderResponse($blockContext->getTemplate(), [
            'block' => $blockContext->getBlock(),
            'tweet' => $tweet,
        ], $response);
    }
public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $tweet = $blockContext->getSetting('tweet');

        if (($uriMatched = preg_match(self::TWEET_URL_PATTERN, $tweet))
            || preg_match(self::TWEET_ID_PATTERN, $tweet)) {
            // We matched an URL or an ID, we'll need to ask the API
            if (false === class_exists('Guzzle\Http\Client')) {
                throw new \RuntimeException('The guzzle http client library is required to call the Twitter API. Make sure to add guzzle/guzzle to your composer.json.');
            }

            // TODO cache API result
            $client = new \Guzzle\Http\Client();
            $client->setConfig(['curl.options' => [CURLOPT_CONNECTTIMEOUT_MS => 1000]]);

            try {
                $request = $client->get($this->buildUri($uriMatched, $blockContext->getSettings()));
                $apiTweet = json_decode($request->send()->getBody(true), true);

                $tweet = $apiTweet['html'];
            } catch (CurlException $e) {
                // log error
            }
        }

        return $this->renderResponse($blockContext->getTemplate(), [
            'block' => $blockContext->getBlock(),
            'tweet' => $tweet,
        ], $response);
    }
{@inheritdoc}