Heimdall-Apps/Memos/Memos.php
Lucas Araujo 67c5d00369
feat(Memos): add livestats and config support for Memos app (#867)
* feat(Memos): add livestats and config support for Memos app

Implement livestats functionality to display memo count and add config support for API access. Enable enhanced app features in app.json.

* style(Memos): improve code formatting and readability

* style: remove empty line in Memos constructor

---------

Co-authored-by: Lucas Araujo <lucas.ribeiro.de.araujo@rabobank.nl>
2025-09-20 16:14:33 +02:00

59 lines
1.2 KiB
PHP

<?php
namespace App\SupportedApps\Memos;
class Memos extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;
public function __construct() {
}
public function test()
{
$test = parent::appTest(
$this->url('api/v1/auth/sessions/current'),
$this->attrs()
);
echo $test->status;
}
public function livestats()
{
$status = 'inactive';
$res = parent::execute(
$this->url('api/v1/memos'),
$this->attrs()
);
$details = json_decode($res->getBody());
$data = [];
if ($details) {
$status = 'active';
$data['memo_count'] = count($details->memos);
}
return parent::getLiveStats($status, $data);
}
public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
return $api_url;
}
public function attrs()
{
$access_token = $this->config->access_token;
$attrs = [
"headers" => [
"content-type" => "application/json",
"Authorization" => "Bearer " . $access_token,
],
];
return $attrs;
}
}