public function Process($parameters)
 {
     // set the URL parameters
     $content = '';
     $count = count($parameters['param']);
     foreach ($parameters['param'] as $paramName => $param) {
         $content .= $paramName . '=' . rawurlencode($param);
         if (--$count > 0) {
             $content .= '&';
         }
     }
     $request = new \Buzz\Message\Request('GET', '/1/' . $parameters['endpoint'] . '?' . $content . '&key=' . $this->getEmbedlyApiKey(), 'http://api.embed.ly');
     $response = new \Buzz\Message\Response();
     $client = new \Buzz\Client\FileGetContents();
     $client->send($request, $response);
     $json = $response->getContent();
     $decoder = new JsonDecode(true);
     $result = $decoder->decode($json, 'json');
     if ($response->getStatusCode() == '200') {
         $parameters['response'] = $result;
     } else {
         $msg = 'Something went wrong';
         if (isset($result['error_message'])) {
             $msg = $result['error_message'];
         }
         throw new \Exception($msg);
     }
     return $parameters;
 }
Example #2
0
 /**
  * Initializes context.
  * Every scenario gets it's own context object.
  *
  * @param array $parameters Context parameters (set them up through behat.yml)
  */
 public function __construct(array $parameters)
 {
     $fileGetContent = new \Buzz\Client\FileGetContents();
     $fileGetContent->setTimeout(15);
     $this->client = new \Buzz\Browser($fileGetContent);
     $this->associative = array_key_exists('associative', $parameters) ? $parameters['associative'] : true;
 }
 /**
  * Send a single SMS message
  * 
  * @param type $phoneNumber
  * @param type $message
  * 
  * @return \HumanSms\SingleSmsResponse
  */
 public function sendSingleSms($phoneNumber, $message)
 {
     $singleSmsRequest = new SingleSmsRequest($phoneNumber, $message);
     $singleSmsRequest->setAccount($this->account);
     $singleSmsRequest->setCode($this->code);
     $singleSmsRequest->setTo($phoneNumber);
     $singleSmsRequest->setMsg($message);
     $formRequest = new \Buzz\Message\Form\FormRequest();
     $formRequest->setHost(self::URL_SINGLE_SMS);
     $formRequest->setResource('');
     $formRequest->setFields($singleSmsRequest->getPostParams());
     $formResponse = new \Buzz\Message\Response();
     $httpClient = new \Buzz\Client\FileGetContents();
     $httpClient->send($formRequest, $formResponse);
     $parsedResponse = $this->parseResponse($formResponse->getContent());
     return new SingleSmsResponse($parsedResponse['code'], $parsedResponse['message']);
 }
Example #4
0
 public function handleRequest($type, $path)
 {
     $request = new Buzz\Message\Request($type, $path, $this->_host);
     $response = new Buzz\Message\Response();
     $client = new Buzz\Client\FileGetContents();
     $client->send($request, $response);
     // Display headers
     foreach ($response->getHeaders() as $i => $header) {
         if ($i == 0) {
             \cli\line('%G{:header}%n', compact('header'));
             continue;
         }
         list($key, $value) = explode(': ', $header, 2);
         \cli\line('%W{:key}%n: {:value}', compact('key', 'value'));
     }
     \cli\line("\n");
     print $response->getContent() . "\n";
     switch ($type) {
     }
 }
 public function Process($parameters)
 {
     // set the URL parameters
     $content = '';
     $count = count($parameters['param']);
     foreach ($parameters['param'] as $paramName => $param) {
         $content .= $paramName . '=' . rawurlencode($param);
         if (--$count > 0) {
             $content .= '&';
         }
     }
     $request = new \Buzz\Message\Request('GET', '/1/oembed?' . $content, 'http://api.embed.ly');
     $response = new \Buzz\Message\Response();
     $client = new \Buzz\Client\FileGetContents();
     $client->send($request, $response);
     if ($response->getStatusCode() == '200') {
         $json = $response->getContent();
         $decoder = new JsonDecode(true);
         $parameters['response'] = $decoder->decode($json, 'json');
     } else {
         throw new Exception('Something went wrong');
     }
     return $parameters;
 }
 /**
  * Gets the 'sonata.media.buzz.connector.file_get_contents' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return Buzz\Client\FileGetContents A Buzz\Client\FileGetContents instance.
  */
 protected function getSonata_Media_Buzz_Connector_FileGetContentsService()
 {
     $this->services['sonata.media.buzz.connector.file_get_contents'] = $instance = new \Buzz\Client\FileGetContents();
     $instance->setIgnoreErrors(true);
     $instance->setMaxRedirects(5);
     $instance->setTimeout(5);
     $instance->setVerifyPeer(true);
     $instance->setProxy(NULL);
     return $instance;
 }