Newer
Older
public $status; # valid key = true, invalid key = false, unidentified key = null
private $keyserver = "https://key.metager.de/";
public function __construct($key, $status = null)
{
if (getenv("APP_ENV") !== "production") {
$this->keyserver = "https://dev.key.metager.de/";
}
public function getStatus()
{
if ($this->key !== '' && $this->status === null) {
if ($this->status === null || $this->status === false) {
public function updateStatus()
{
$link = $this->keyserver . urlencode($this->key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link));
if ($result->{'api-access'} == true) {
$this->status = true;
return true;
} else {
$this->status = false;
return false;
}
} catch (\ErrorException $e) {
return false;
}
}
public function requestPermission()
{
$postdata = http_build_query(array(
'dummy' => 0,
));
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
),
);
$context = stream_context_create($opts);
try {
$link = $this->keyserver . urlencode($this->key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link, false, $context));
if ($result->{'api-access'} == true) {
return true;
} else {
$this->status = false;
return false;
}
} catch (\ErrorException $e) {
return false;
}
}