/** * {@inheritdoc} */ 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 (class_exists('Guzzle\\Http\\Client') === false) { 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(array('curl.options' => array(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(), array('block' => $blockContext->getBlock(), 'tweet' => $tweet), $response); }
/** * Calls the rabbitmq management api /api/<vhost>/queues endpoint to list the available queues. * * @see http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html * * @return array */ protected function getApiQueueStatus() { if (class_exists('Guzzle\\Http\\Client') === false) { throw new \RuntimeException('The guzzle http client library is required to run rabbitmq health checks. Make sure to add guzzle/guzzle to your composer.json.'); } $client = new \Guzzle\Http\Client(); $client->setConfig(array('curl.options' => array(CURLOPT_CONNECTTIMEOUT_MS => 3000))); $request = $client->get(sprintf('%s/queues', $this->settings['console_url'])); $request->setAuth($this->settings['user'], $this->settings['pass']); return json_decode($request->send()->getBody(true), true); }
/** * @param $customerKey * @return \Guzzle\Http\Client * @throws Exception\RuntimeException */ protected static function getPreparedGuzzleClient($customerKey) { $guzzle = new \Guzzle\Http\Client(); $guzzle->setConfig(array('customerKey' => $customerKey, 'redirect.disable' => true)); if (self::$HTTP_DEBUG === TRUE) { if (class_exists('\\Guzzle\\Plugin\\Log\\LogPlugin')) { $guzzle->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin()); return $guzzle; } else { throw new \Searchperience\Common\Exception\RuntimeException('Please run "composer install --dev" to install "guzzle/plugin-log"'); } } return $guzzle; }
/** * @return \Guzzle\Http\Client * @throws Exception\RuntimeException */ protected static function getPreparedGuzzleClient() { $guzzle = new \Guzzle\Http\Client(); $guzzle->setConfig(array('redirect.disable' => true)); return $guzzle; }