-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoolifyClient.php
55 lines (49 loc) · 1.24 KB
/
CoolifyClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* Uses a preconfigured Guzzle client to connect to the Coolify instance and get stuff.
*/
class CoolifyClient
{
public Client $client;
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* @see https://coolify.io/docs/api/operations/list-projects
* @return mixed
*/
public function getProjects(): mixed
{
return $this->fetchResults('projects');
}
/**
* @see https://coolify.io/docs/api/operations/list-servers
* @return mixed
*/
public function getServers(): mixed
{
return $this->fetchResults('servers');
}
/**
* Returns an array of response objects, or an empty array if something went wrong.
* @param $endpoint
* @return mixed
*/
private function fetchResults($endpoint): mixed
{
try {
$response = $this->client->get($endpoint);
return json_decode(
$response->getBody()->getContents(),
false,
10,
JSON_THROW_ON_ERROR
);
} catch (JsonException|GuzzleException $e) {
return [];
}
}
}