Пример #1
0
 /**
  * Authenticate the request object. Apply the access_token to the URL
  *
  * TODO: implement
  * 
  * @param Request       $request        Request object to authenticate
  */
 public function authenticate(\Buzz\Message\Request $request)
 {
     $url = $request->getUrl();
     $prefix = strpos($url, '?') > 0 ? '&' : '?';
     $request->fromUrl($url . $prefix . 'access_token=' . $this->accessToken);
     return $request;
 }
Пример #2
0
 public function testFromUrlRejectsInvalidUrl()
 {
     $this->setExpectedException('InvalidArgumentException');
     // port number is too high
     $request = new Request();
     $request->fromUrl('http://localhost:123456');
 }
Пример #3
0
 /**
  * @dataProvider provideInvalidHosts
  */
 public function testSendToInvalidUrl($host, $client)
 {
     $this->setExpectedException('Buzz\\Exception\\ClientException');
     $request = new Message\Request();
     $request->fromUrl('http://' . $host . ':12345');
     $response = new Message\Response();
     $client = new $client();
     $client->setTimeout(0.05);
     $client->send($request, $response);
 }
Пример #4
0
 /**
  * Converts a PSR request into a BuzzRequest request.
  *
  * @param RequestInterface $request
  *
  * @return BuzzRequest
  */
 private function createRequest(RequestInterface $request)
 {
     $buzzRequest = new BuzzRequest();
     $buzzRequest->setMethod($request->getMethod());
     $buzzRequest->fromUrl($request->getUri()->__toString());
     $buzzRequest->setProtocolVersion($request->getProtocolVersion());
     $buzzRequest->setContent((string) $request->getBody());
     $this->addPsrHeadersToBuzzRequest($request, $buzzRequest);
     return $buzzRequest;
 }
Пример #5
0
 /**
  * @dataProvider provideInvalidHosts
  */
 public function testSendToInvalidUrl($host)
 {
     $this->setExpectedException('RuntimeException');
     $request = new Message\Request();
     $request->fromUrl('http://' . $host . ':12345');
     $response = new Message\Response();
     $client = new FileGetContents();
     $client->setTimeout(0.05);
     $client->send($request, $response);
 }
Пример #6
0
 public function testAuthenticate()
 {
     $basic = new OAuth('KFGDSYGSDHKKGFSFN');
     // Create request, authenticate it
     $request = new Request();
     $request->fromUrl('http://test.com?name=dsyph3r');
     $request = $basic->authenticate($request);
     // Check access_token param is set correctly
     $url = parse_url($request->getUrl());
     $params = explode('&', $url['query']);
     $this->assertContains('access_token=KFGDSYGSDHKKGFSFN', $params);
 }
Пример #7
0
 public function testLogger()
 {
     $test = $this;
     $logger = function ($line) use($test) {
         $test->assertRegExp('~^Sent "GET http://google.com/" in \\d+ms$~', $line);
     };
     $request = new Message\Request();
     $request->fromUrl('http://google.com/');
     $response = new Message\Response();
     $listener = new LoggerListener($logger);
     $listener->preSend($request);
     $listener->postSend($request, $response);
 }
Пример #8
0
 /**
  * @param $method
  * @param $relativeUrl
  * @param array|\stdClass $content
  * @return mixed
  */
 protected function doHttpRequest($method, $relativeUrl, $content = null)
 {
     $relativeUrl = ltrim($relativeUrl, '/');
     $response = new Response();
     $request = new Request($method);
     $request->fromUrl($this->baseUrl . '/' . $relativeUrl);
     $request->addHeader("Content-Type: application/json");
     $request->addHeader('Accept: application/json');
     if ($content) {
         $request->setContent(json_encode(array_filter((array) $content)));
     }
     $timezone = new \DateTimeZone("UTC");
     $datetime = new \DateTime(null, $timezone);
     $timestamp = str_replace('-', '', $datetime->format('c'));
     $nonce = uniqid();
     $authToken = $this->makeAuthHeader($request, $timestamp, $nonce);
     $request->addHeader("Authorization: " . $authToken);
     // $listener = new BasicAuthListener($this->username, $this->password);
     // $listener->preSend($request);
     $this->httpClient->send($request, $response);
     return $this->getResult($response);
 }
 public function testMultiCurlExecutesRequestsConcurently()
 {
     $client = new MultiCurl();
     $client->setTimeout(10);
     $calls = array();
     $callback = function ($client, $request, $response, $options, $error) use(&$calls) {
         $calls[] = func_get_args();
     };
     for ($i = 3; $i > 0; $i--) {
         $request = new Request();
         $request->fromUrl($_SERVER['TEST_SERVER'] . '?delay=' . $i);
         $client->send($request, new Response(), array('callback' => $callback));
     }
     $client->flush();
     $this->assertCount(3, $calls);
 }
Пример #10
0
 /**
  * @param string $credentials
  *
  * @return \Buzz\Message\Request
  */
 public function buildValidationRequest($credentials)
 {
     $request = new Request();
     $request->fromUrl(sprintf('%s&ticket=%s', $this->getValidationUrl(), $credentials));
     return $request;
 }
Пример #11
0
 /**
  * @parem string  $controller
  * @param Request $request
  * @param array   $qs
  *
  * @throws RequestException
  *
  * @return JsonResponse
  */
 protected function doRequest($controller, Request $request, array $qs = array())
 {
     $request->fromUrl($this->getApiEndpoint($controller) . '?' . http_build_query($qs));
     $request->addHeader('Authorization: Basic ' . $this->options['key']);
     $request->addHeader('Accept: text/json');
     $this->client->send($request, $response = new JsonResponse());
     $content = $response->getContentJson(true);
     if (!in_array($content['ReturnCode'], array(self::EXECCODE_SUCCESS, self::EXECCODE_OPERATION_REFUSED))) {
         $e = new RequestException(print_r(array_merge($content, array('url' => $request->getUrl(), 'content' => $request->getContent())), true));
         $e->setRequest($request);
         throw $e;
     }
     return $response;
 }
Пример #12
0
 /**
  * @expectedException RuntimeException
  * @expectedExceptionMessage Protocol pop3 not supported or disabled in libcurl
  */
 public function testRedirectedToForbiddenProtocol()
 {
     $client = new Curl();
     $request = new Request();
     $request->fromUrl($_SERVER['TEST_SERVER'] . '?redirect_to=pop3://localhost/');
     $response = $this->send($client, $request);
 }
Пример #13
0
 /**
  * @dataProvider provideClient
  */
 public function testConsecutiveRequests($client)
 {
     // request 1
     $request = new Request(Request::METHOD_PUT);
     $request->fromUrl($_SERVER['TEST_SERVER']);
     $request->addHeader('Content-Type: application/json');
     $request->setContent(json_encode(array('foo' => 'bar')));
     $response = new Response();
     $client->send($request, $response);
     $data = json_decode($response->getContent(), true);
     $this->assertEquals('PUT', $data['SERVER']['REQUEST_METHOD']);
     $this->assertEquals('application/json', $data['SERVER']['CONTENT_TYPE']);
     $this->assertEquals('{"foo":"bar"}', $data['INPUT']);
     // request 2
     $request = new Request(Request::METHOD_GET);
     $request->fromUrl($_SERVER['TEST_SERVER']);
     $response = new Response();
     $client->send($request, $response);
     $data = json_decode($response->getContent(), true);
     $this->assertEquals('GET', $data['SERVER']['REQUEST_METHOD']);
     $this->assertEmpty($data['INPUT']);
 }
Пример #14
0
 /**
  * Return an array of Image most similar to the supplied image
  *
  * @param string $url
  * @param int $returns (optional) defaults to 12
  * @param int $sketch (optional)  0 for photograph 1 for sketch, defaults to 0
  * @param $fast (optional)
  *
  * @return array of ImgSeek\Entity\ImageInterface
  */
 public function queryByUrl($url, $returns = 12, $sketch = 0, $fast = false)
 {
     $request = new Request();
     $request->fromUrl($url);
     $response = new Response();
     $this->httpClient->send($request, $response);
     $imgResponses = $this->imgSeekGateway->request('queryImgBlob', array($this->defaultDbId, $response->getContent(), $returns, $sketch, $fast));
     $imageIds = array();
     foreach ($imgResponses as $imgResponse) {
         $imageIds[] = $imgResponse[0];
     }
     $images = array();
     foreach ($this->persistence->findImages($imageIds) as $image) {
         $imageId = $image->getImageId();
         foreach ($imgResponses as $imgResponse) {
             if ($imgResponse[0] == $imageId) {
                 $imageSet['image'] = $image;
                 $imageSet['score'] = $imgResponse[1];
                 $images[] = $imageSet;
                 continue;
             }
         }
     }
     return $images;
 }
Пример #15
0
 /**
  * @dataProvider provideClient
  */
 public function testRedirectedResponse($client)
 {
     $request = new Request();
     $request->fromUrl($_SERVER['TEST_SERVER'] . '?redirect_to=' . $_SERVER['TEST_SERVER']);
     $response = $this->send($client, $request);
     $headers = $response->getHeaders();
     $this->assertContains('200', $headers[0]);
 }