|
4 | 4 |
|
5 | 5 | class Gotify extends \App\SupportedApps implements \App\EnhancedApps
|
6 | 6 | {
|
| 7 | + public $config; |
| 8 | + |
| 9 | + public function __construct() |
| 10 | + { |
| 11 | + } |
| 12 | + |
| 13 | + public function test() |
| 14 | + { |
| 15 | + $attrs = $this->getAttrs(); |
| 16 | + $test = parent::appTest($this->url("health"), $attrs); |
| 17 | + echo $test->status; |
| 18 | + } |
| 19 | + |
| 20 | + public function livestats() |
| 21 | + { |
| 22 | + $status = "inactive"; |
| 23 | + $data = []; |
| 24 | + $attrs = $this->getAttrs(); |
| 25 | + |
| 26 | + // Fetch applications |
| 27 | + $applicationsResponse = parent::execute($this->url("application"), $attrs); |
| 28 | + $applications = json_decode($applicationsResponse->getBody()); |
| 29 | + |
| 30 | + // Count applications |
| 31 | + if ($applications) { |
| 32 | + $data["applications"] = count($applications); |
| 33 | + } else { |
| 34 | + $data["applications"] = 0; |
| 35 | + } |
| 36 | + |
| 37 | + // Fetch clients |
| 38 | + $clientsResponse = parent::execute($this->url("client"), $attrs); |
| 39 | + $clients = json_decode($clientsResponse->getBody()); |
| 40 | + |
| 41 | + // Count clients |
| 42 | + if ($clients) { |
| 43 | + $data["clients"] = count($clients); |
| 44 | + } else { |
| 45 | + $data["clients"] = 0; |
| 46 | + } |
| 47 | + |
| 48 | + // Fetch messages |
| 49 | + $messagesResponse = parent::execute($this->url("message"), $attrs); |
| 50 | + $messages = json_decode($messagesResponse->getBody()); |
| 51 | + |
| 52 | + // Count messages |
| 53 | + if ($messages && isset($messages->messages)) { |
| 54 | + $data["messages"] = count($messages->messages); |
| 55 | + } else { |
| 56 | + $data["messages"] = 0; |
| 57 | + } |
| 58 | + |
| 59 | + // Determine status based on data |
| 60 | + if ($data["applications"] > 0 || $data["clients"] > 0 || $data["messages"] > 0) { |
| 61 | + $status = "active"; |
| 62 | + } |
| 63 | + |
| 64 | + return parent::getLiveStats($status, $data); |
| 65 | + } |
| 66 | + |
| 67 | + public function url($endpoint) |
| 68 | + { |
| 69 | + $api_url = parent::normaliseurl($this->config->url) . $endpoint; |
| 70 | + return $api_url; |
| 71 | + } |
| 72 | + private function getAttrs() |
| 73 | + { |
| 74 | + return [ |
| 75 | + "headers" => [ |
| 76 | + "Accept" => "application/json", |
| 77 | + "X-Gotify-Key" => $this->config->apikey |
| 78 | + ], |
| 79 | + ]; |
| 80 | + } |
7 | 81 | }
|
0 commit comments