Example #1
0
 /**
  * @expectedException \RequestLab\Estat\EstatException
  */
 public function testQueryWithJsonError()
 {
     $this->clientMock->expects($this->once())->method('getAccessToken')->will($this->returnValue('token'));
     $this->queryMock->expects($this->once())->method('build')->with($this->equalTo('token'))->will($this->returnValue(array('content')));
     $this->httpAdapterMock->expects($this->once())->method('postContent')->with('https://ws.estat.com/gosu/rest/data/json', array('Content-Type' => 'application/json'), $this->equalTo(array('content')))->will($this->returnValue(json_encode(array('gosuResponse' => array('errorCode' => '999', 'errorMessage' => 'error')))));
     $this->service->query($this->queryMock);
 }
Example #2
0
 /**
  * @expectedException \Widop\Twitter\OAuth\OAuthException
  * @expectedExceptionMessage An error occured when creating the OAuth token.
  */
 public function testGetRequestTokenError()
 {
     $response = $this->getMockBuilder('Widop\\HttpAdapter\\HttpResponse')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('getBody')->will($this->returnValue('foo'));
     $this->httpAdapter->expects($this->once())->method('postContent')->will($this->returnValue($response));
     $this->oauth->getRequestToken();
 }
 /**
  * Sends a service request.
  *
  * @param string $url The service url.
  *
  * @return \Widop\HttpAdapter\HttpResponse The response.
  *
  * @throws \Ivory\GoogleMap\Exception\ServiceException If the response is null.
  * @throws \Ivory\GoogleMap\Exception\ServiceException If the response has an error 4XX or 5XX.
  */
 protected function send($url)
 {
     $response = $this->httpAdapter->getContent($url);
     if ($response === null) {
         throw ServiceException::invalidServiceResult();
     }
     $statusCode = (string) $response->getStatusCode();
     if ($statusCode[0] === '4' || $statusCode[0] === '5') {
         throw ServiceException::invalidResponse($url, $statusCode);
     }
     return $response;
 }
Example #4
0
 /**
  * Gets the google OAuth access token.
  *
  * @throws GoogleAnalyticsException If the access token can not be retrieved.
  *
  * @return string The access token.
  */
 public function getAccessToken()
 {
     if ($this->accessToken === null) {
         $headers = array('Content-Type' => 'application/x-www-form-urlencoded');
         $content = array('grant_type' => 'assertion', 'assertion_type' => 'http://oauth.net/grant_type/jwt/1.0/bearer', 'assertion' => $this->generateJsonWebToken());
         $response = json_decode($this->httpAdapter->postContent($this->url, $headers, $content));
         if (isset($response->error)) {
             throw GoogleAnalyticsException::invalidAccessToken($response->error);
         }
         $this->accessToken = $response->access_token;
     }
     return $this->accessToken;
 }
Example #5
0
 /**
  * @return string
  * @throws EstatException
  */
 public function getAccessToken()
 {
     if ($this->accessToken === null) {
         $headers = array('Content-Type' => 'application/json');
         $params = array('login' => $this->getLogin(), 'password' => $this->getPassword());
         $uri = sprintf('%s?%s', $this->url, http_build_query($params));
         $response = $this->httpAdapter->getContent($uri, $headers);
         if ($response === null) {
             throw EstatException::invalidResponse($response);
         }
         $response = json_decode($response->getBody());
         if (isset($response->tokenResponse->errorCode)) {
             throw EstatException::invalidAccessToken($response->tokenResponse->errorMessage);
         }
         $this->accessToken = $response->tokenResponse->tokenId;
     }
     return $this->accessToken;
 }
Example #6
0
 /**
  * Sends an OAuth request.
  *
  * @param \Widop\Twitter\OAuth\OAuthRequest $request The OAuth request.
  *
  * @throws \RuntimeException If the request method is not supported.
  *
  * @return \Widop\Twitter\OAuth\OAuthResponse The OAuth response.
  */
 public function sendRequest(OAuthRequest $request)
 {
     switch ($request->getMethod()) {
         case OAuthRequest::METHOD_GET:
             $httpResponse = $this->httpAdapter->getContent($request->getUrl(), $request->getHeaders());
             break;
         case OAuthRequest::METHOD_POST:
             $postParameters = array();
             foreach ($request->getPostParameters() as $name => $value) {
                 $postParameters[rawurldecode($name)] = rawurldecode($value);
             }
             $httpResponse = $this->httpAdapter->postContent($request->getUrl(), $request->getHeaders(), $postParameters, $request->getFileParameters());
             break;
         default:
             throw new \RuntimeException(sprintf('The request method "%s" is not supported.', $request->getMethod()));
     }
     $response = new OAuthResponse($httpResponse, $request->getResponseFormat());
     if (!$response->isValid()) {
         throw new OAuthException('The http response is not valid.', $response);
     }
     return $response;
 }
 public function testPutContentWithHeadersAndContentAndFiles()
 {
     $this->assertResponse($this->httpAdapter->put($this->url, $this->headers, $this->content, $this->files));
 }