Initial commit

This commit is contained in:
2022-01-18 17:14:29 +01:00
commit 320a153918
18 changed files with 622 additions and 0 deletions

65
src/Server.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
namespace Envoyr\Froxlor;
use GuzzleHttp\Client;
class Server
{
public Customers $customers;
protected Client $client;
protected string $apiKey;
protected string $apiSecret;
protected array $config;
public function __construct(array $config)
{
$this->config = $config;
$this->client = new Client([
'base_uri' => $config['host']
]);
$this->apiKey = $config['key'];
$this->apiSecret = $config['secret'];
$this->customers = $this->customers();
}
private function customers(): Customers
{
return new Customers($this);
}
public function request($command, array $attributes = [], bool $clear_empty_attributes = false): array
{
if ($clear_empty_attributes) {
$attributes = array_filter($attributes, fn($value) => !is_null($value) && $value !== '');
}
$payload = [
'header' => [
'apikey' => $this->apiKey,
'secret' => $this->apiSecret,
],
'body' => [
'command' => $command,
'params' => $attributes
]
];
$response = $this->client->post("api.php", [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode($payload)
]);
$payload = json_decode($response->getBody(), true);
return $payload['data'];
}
public function customer(string $loginname): Customer
{
return new Customer($this, $loginname);
}
}