mirror of
https://github.com/envoyr/php-froxlor-client.git
synced 2026-04-28 04:06:19 +00:00
Initial commit
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/.idea
|
||||||
|
/example
|
||||||
|
/vendor
|
||||||
|
composer.lock
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Maurice Preuß (envoyr) <hello@envoyr.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
45
README.md
Normal file
45
README.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# PHP Froxlor API Client
|
||||||
|
|
||||||
|
API Wrapper for Froxlor.
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
````
|
||||||
|
$froxlor = new \Envoyr\Froxlor\Server([
|
||||||
|
'host' => 'de-nue-dev.bitinflow.space',
|
||||||
|
'key' => '',
|
||||||
|
'secret' => ''
|
||||||
|
]);
|
||||||
|
````
|
||||||
|
|
||||||
|
### Customer
|
||||||
|
|
||||||
|
````
|
||||||
|
$response = $froxlor
|
||||||
|
->customers
|
||||||
|
->create([
|
||||||
|
'email' => 'hello@example.com',
|
||||||
|
'firstname' => 'Test',
|
||||||
|
'name' => 'Testman',
|
||||||
|
'custom_notes' => 'Created By API',
|
||||||
|
'customernumber' => 1337,
|
||||||
|
'new_loginname' => 'username',
|
||||||
|
'new_customer_password' => 'someRandomString',
|
||||||
|
'hosting_plan_id' => 1,
|
||||||
|
'api_allowed' => false,
|
||||||
|
'createstdsubdomain' => true,
|
||||||
|
]);
|
||||||
|
````
|
||||||
|
|
||||||
|
### Email
|
||||||
|
|
||||||
|
````
|
||||||
|
$response = $froxlor
|
||||||
|
->customer('example')
|
||||||
|
->email('hello@example.com')
|
||||||
|
->attributes;
|
||||||
|
````
|
||||||
|
|
||||||
|
### Info
|
||||||
|
|
||||||
|
Domains, Ftps, Email & EmailAccounts are also available.
|
||||||
21
composer.json
Normal file
21
composer.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "envoyr/php-froxlor-client",
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Envoyr\\Froxlor\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "envoyr",
|
||||||
|
"email": "hello@envoyr.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"require": {
|
||||||
|
"php": "^7.4|^8.0",
|
||||||
|
"guzzlehttp/guzzle": "^7.0.1",
|
||||||
|
"ext-json": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
93
src/Customer.php
Normal file
93
src/Customer.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Customer
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public Databases $databases;
|
||||||
|
public Domains $domains;
|
||||||
|
public Ftps $ftps;
|
||||||
|
public Emails $emails;
|
||||||
|
public string $loginname;
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
public function __construct(Server $server, string $loginname)
|
||||||
|
{
|
||||||
|
$this->server = $server;
|
||||||
|
$this->loginname = $loginname;
|
||||||
|
$this->attributes = $this->server->request('Customers.get', [
|
||||||
|
'loginname' => $this->loginname
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->databases = $this->databases();
|
||||||
|
$this->domains = $this->domains();
|
||||||
|
$this->ftps = $this->ftps();
|
||||||
|
$this->emails = $this->emails();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function databases(): Databases
|
||||||
|
{
|
||||||
|
return new Databases($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function domains(): Domains
|
||||||
|
{
|
||||||
|
return new Domains($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ftps(): Ftps
|
||||||
|
{
|
||||||
|
return new Ftps($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function emails(): Emails
|
||||||
|
{
|
||||||
|
return new Emails($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function database(string $dbname): Database
|
||||||
|
{
|
||||||
|
return new Database($this, $dbname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function domain(string $domainname): Domain
|
||||||
|
{
|
||||||
|
return new Domain($this, $domainname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function email(string $emailaddr): Email
|
||||||
|
{
|
||||||
|
return new Email($this, $emailaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ftp(string $username): Ftp
|
||||||
|
{
|
||||||
|
return new Ftp($this, $username);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deactivated(bool $deactivated): array
|
||||||
|
{
|
||||||
|
return $this->server->request('Customers.update', [
|
||||||
|
'loginname' => $this->loginname,
|
||||||
|
'deactivated' => $deactivated
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->server->request(
|
||||||
|
'Customers.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'loginname' => $this->loginname
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(): array
|
||||||
|
{
|
||||||
|
return $this->server->request('Customers.delete', [
|
||||||
|
'loginname' => $this->loginname
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/Customers.php
Normal file
18
src/Customers.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Customers
|
||||||
|
{
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
public function __construct(Server $server)
|
||||||
|
{
|
||||||
|
$this->server = $server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->server->request('Customers.add', $attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/Database.php
Normal file
38
src/Database.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Database
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public string $dbname;
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer, string $dbname)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
$this->dbname = $dbname;
|
||||||
|
$this->attributes = $this->customer->server->request('Mysqls.get', [
|
||||||
|
'dbname' => $this->dbname
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request(
|
||||||
|
'Mysqls.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'dbname' => $this->dbname,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Mysqls.delete', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'dbname' => $this->dbname
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/Databases.php
Normal file
35
src/Databases.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Databases
|
||||||
|
{
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(
|
||||||
|
string $password,
|
||||||
|
string $description = null,
|
||||||
|
bool $mail = false,
|
||||||
|
string $suffix = null
|
||||||
|
): array {
|
||||||
|
return $this->customer->server->request('Mysqls.add', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'mysql_password' => $password,
|
||||||
|
'description' => $description,
|
||||||
|
'sendinfomail' => $mail,
|
||||||
|
'custom_suffix' => $suffix,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Mysqls.listing', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/Domain.php
Normal file
36
src/Domain.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Domain
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public Customer $customer;
|
||||||
|
public string $domainname;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer, string $domainname)
|
||||||
|
{
|
||||||
|
$this->domainname = $domainname;
|
||||||
|
$this->customer = $customer;
|
||||||
|
$this->attributes = $this->customer->server->request('Domains.get', [
|
||||||
|
'domainname' => $this->domainname
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request(
|
||||||
|
'Domains.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'domainname' => $this->domainname,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Domains.delete', [
|
||||||
|
'domainname' => $this->domainname
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/Domains.php
Normal file
36
src/Domains.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Domains
|
||||||
|
{
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(string $domain, bool $letsencrypt = false): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Domains.add', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'domain' => $domain,
|
||||||
|
'letsencrypt' => $letsencrypt,
|
||||||
|
'isemaildomain' => true,
|
||||||
|
'caneditdomain' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Domains.listing', [
|
||||||
|
'sql_search' => [
|
||||||
|
'loginname' => [
|
||||||
|
'op' => '=',
|
||||||
|
'value' => $this->customer->loginname,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/Email.php
Normal file
51
src/Email.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Email
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public EmailAccounts $email_accounts;
|
||||||
|
public string $emailaddr;
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer, string $emailaddr)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
$this->emailaddr = $emailaddr;
|
||||||
|
$this->attributes = $this->customer->server->request('Emails.get', [
|
||||||
|
'emailaddr' => $this->emailaddr
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->email_accounts = $this->email_accounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function email_accounts(): EmailAccounts
|
||||||
|
{
|
||||||
|
return new EmailAccounts($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function email_account(): EmailAccount
|
||||||
|
{
|
||||||
|
return new EmailAccount($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request(
|
||||||
|
'Emails.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'emailaddr' => $this->emailaddr,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Emails.delete', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'emailaddr' => $this->emailaddr
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/EmailAccount.php
Normal file
34
src/EmailAccount.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class EmailAccount
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public Email $email;
|
||||||
|
|
||||||
|
public function __construct(Email $email)
|
||||||
|
{
|
||||||
|
$this->email = $email;
|
||||||
|
$this->attributes = $this->email->attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$this->email->customer->server->request('EmailAccounts.delete', [
|
||||||
|
'loginname' => $this->email->customer->loginname,
|
||||||
|
'emailaddr' => $this->email->emailaddr,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->email->customer->server->request(
|
||||||
|
'EmailAccounts.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'loginname' => $this->email->customer->loginname,
|
||||||
|
'emailaddr' => $this->email->emailaddr,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/EmailAccounts.php
Normal file
23
src/EmailAccounts.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class EmailAccounts
|
||||||
|
{
|
||||||
|
public Email $email;
|
||||||
|
|
||||||
|
public function __construct(Email $email)
|
||||||
|
{
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(string $email_password, bool $sendinfomail = false): array
|
||||||
|
{
|
||||||
|
return $this->email->customer->server->request('EmailAccounts.add', [
|
||||||
|
'loginname' => $this->email->customer->loginname,
|
||||||
|
'emailaddr' => $this->email->emailaddr,
|
||||||
|
'email_password' => $email_password,
|
||||||
|
'sendinfomail' => $sendinfomail,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Emails.php
Normal file
30
src/Emails.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Emails
|
||||||
|
{
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(string $email_part, string $domain, string $description = null): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Emails.add', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'email_part' => $email_part,
|
||||||
|
'domain' => $domain,
|
||||||
|
'description' => $description,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Emails.listing', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Ftp.php
Normal file
39
src/Ftp.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Ftp
|
||||||
|
{
|
||||||
|
public array $attributes;
|
||||||
|
public string $username;
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer, string $username)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
$this->username = $username;
|
||||||
|
$this->attributes = $this->customer->server->request('Ftps.get', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'username' => $this->username
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(array $attributes): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request(
|
||||||
|
'Ftps.update',
|
||||||
|
array_merge($attributes, [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'username' => $this->username,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Ftps.delete', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'username' => $this->username
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/Ftps.php
Normal file
31
src/Ftps.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Envoyr\Froxlor;
|
||||||
|
|
||||||
|
class Ftps
|
||||||
|
{
|
||||||
|
public Customer $customer;
|
||||||
|
|
||||||
|
public function __construct(Customer $customer)
|
||||||
|
{
|
||||||
|
$this->customer = $customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(string $password, string $path = '/', string $description = null, bool $mail = false): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Ftps.add', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
'ftp_password' => $password,
|
||||||
|
'path' => $path,
|
||||||
|
'ftp_description' => $description,
|
||||||
|
'sendinfomail' => $mail,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
return $this->customer->server->request('Ftps.listing', [
|
||||||
|
'loginname' => $this->customer->loginname,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/Server.php
Normal file
65
src/Server.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user