Exemplo n.º 1
0
 /**
  * @param string $code
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  * @return GithubAccessResponse
  */
 public function getAccessTokenFromCode($code)
 {
     $json = $this->httpClient->post('https://github.com/login/oauth/access_token', array(), array('client_id' => $this->clientId, 'client_secret' => $this->secret, 'code' => $code), null, array('Accept: application/json'));
     if ($this->httpClient->getStatusCode() != HttpStatusCode::OK) {
         throw new HttpException($this->httpClient->getStatusCode(), $this->httpClient->getErrorText() . ' : ' . $json);
     }
     /** @var GithubAccessResponse $result */
     $result = GithubAccessResponse::deserialize($json);
     if (!$result) {
         new \LogicException('Unable to parse github response: ' . $json);
     }
     if ($result->error) {
         throw new HttpException(HttpStatusCode::INTERNAL_SERVER_ERROR, $result->error . ': ' . $result->error_description);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @param string $id
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  * @return Account
  */
 public function profileRead($id = 'me')
 {
     $url = sprintf('%s://%s%s/api/v1/profile/%s', $this->scheme, $this->domain, $this->sufix, $id);
     if ($this->logger) {
         $this->logger->info('Appsco.AppscoClient.profileRead', array('id' => $id, 'url' => $url, 'accessToken' => $this->accessToken));
     }
     $json = $this->makeRequest($url);
     if ($this->logger) {
         $this->logger->info('Appsco.AppscoClient.profileRead', array('result' => $json, 'statusCode' => $this->httpClient->getStatusCode()));
     }
     if ($json === false || $this->httpClient->getStatusCode() != HttpStatusCode::OK) {
         throw new HttpException($this->httpClient->getStatusCode(), sprintf("%s\n%s\n%s\n%s", $url, $this->accessToken, $this->httpClient->getErrorText(), $json));
     }
     return $this->serializer->deserialize($json, 'Appsco\\Dashboard\\ApiBundle\\Model\\Account', 'json');
 }