public function SiteimproveUtils::requestToken in Siteimprove 8
Return Siteimprove token.
File
- src/
SiteimproveUtils.php, line 109
Class
- SiteimproveUtils
- Utility functions for Siteimprove.
Namespace
Drupal\siteimproveCode
public function requestToken() {
try {
// Request new token.
$response = $this->httpClient
->get(self::getTokenRequestUrl(), [
'headers' => [
'Accept' => 'application/json',
],
]);
$data = (string) $response
->getBody();
if (!empty($data)) {
$json = json_decode($data);
if (!empty($json->token)) {
return $json->token;
}
else {
throw new \Exception();
}
}
else {
throw new \Exception();
}
} catch (\Exception $e) {
$this->logger
->log(RfcLogLevel::ERROR, 'There was an error requesting a new token. %type: @message in %function (line %line of %file).', Error::decodeException($e));
}
return FALSE;
}