Skip to content

Commit

Permalink
Merge pull request #82 from realtimeregister/whmcs
Browse files Browse the repository at this point in the history
Small improvements
  • Loading branch information
glenn1001 authored Sep 6, 2024
2 parents 923ae0a + 6641b09 commit 11dd0ea
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"php": "^8.1",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.5.0",
"psr/log": "^3.0.0",
"psr/log": "^1.0|^2.0|^3.0.0",
"webmozart/assert": "^1.11.0"
},
"require-dev": {
Expand Down
10 changes: 10 additions & 0 deletions src/Api/BrandsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public function list(
return BrandCollection::fromArray($response->json());
}

public function export(
string $customer,
array $parameters = []
): array {
$query = $parameters;
$query['export'] = 'true';
$response = $this->client->get("/v2/customers/{$customer}/brands", $query);
return $response->json()['entities'];
}

/**
* @see https://dm.realtimeregister.com/docs/api/brands/create
*
Expand Down
2 changes: 1 addition & 1 deletion src/Api/CustomersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function priceList(string $customer): PriceCollection
public function credits(string $customer): AccountCollection
{
$response = $this->client->get("v2/customers/{$customer}/credit");
return AccountCollection::fromArray($response->json());
return AccountCollection::fromArray($response->json()['accounts']);
}
}
32 changes: 16 additions & 16 deletions src/Api/DnsZonesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ public function create(
if ($master !== null) {
$payload['master'] = $master;
}
if($ns !== null) {
if ($ns !== null) {
$payload['ns'] = $ns;
}
if($dnssec !== null) {
if ($dnssec !== null) {
$payload['dnssec'] = $dnssec;
}
if($hostMaster !== null) {
if ($hostMaster !== null) {
$payload['hostMaster'] = $hostMaster;
}
if($refresh !== null) {
if ($refresh !== null) {
$payload['refresh'] = $refresh;
}
if($retry !== null) {
if ($retry !== null) {
$payload['retry'] = $retry;
}
if($expire !== null) {
if ($expire !== null) {
$payload['expire'] = $expire;
}
if($ttl !== null) {
if ($ttl !== null) {
$payload['ttl'] = $ttl;
}
if($records !== null) {
if ($records !== null) {
$payload['records'] = $records->toArray();
}

Expand Down Expand Up @@ -167,28 +167,28 @@ public function update(
if ($master !== null) {
$payload['master'] = $master;
}
if($ns !== null) {
if ($ns !== null) {
$payload['ns'] = $ns;
}
if($dnssec !== null) {
if ($dnssec !== null) {
$payload['dnssec'] = $dnssec;
}
if($hostMaster !== null) {
if ($hostMaster !== null) {
$payload['hostMaster'] = $hostMaster;
}
if($refresh !== null) {
if ($refresh !== null) {
$payload['refresh'] = $refresh;
}
if($retry !== null) {
if ($retry !== null) {
$payload['retry'] = $retry;
}
if($expire !== null) {
if ($expire !== null) {
$payload['expire'] = $expire;
}
if($ttl !== null) {
if ($ttl !== null) {
$payload['ttl'] = $ttl;
}
if($records !== null) {
if ($records !== null) {
$payload['records'] = $records->toArray();
}

Expand Down
10 changes: 9 additions & 1 deletion src/Api/DomainsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function list(
return DomainDetailsCollection::fromArray($response->json());
}

public function export(array $parameters = []): array
{
$query = $parameters;
$query['export'] = 'true';
$response = $this->client->get('v2/domains', $query);
return $response->json()['entities'];
}

/* @see https://dm.realtimeregister.com/docs/api/domains/check */
public function check(string $domainName, ?string $languageCode = null): DomainAvailability
{
Expand Down Expand Up @@ -151,7 +159,7 @@ public function register(
}

$response = $this->client->post("v2/domains/{$domainName}", $payload, [
'quote' => $isQuote,
'quote' => $isQuote ? 'true' : 'false',
]);

if ($isQuote) {
Expand Down
8 changes: 8 additions & 0 deletions src/Api/ProvidersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public function list(
return ProviderCollection::fromArray($response->json());
}

public function export(array $parameters = []): array
{
$query = $parameters;
$query['export'] = 'true';
$response = $this->client->get('v2/providers', $query);
return $response->json()['entities'];
}

/* @see https://dm.realtimeregister.com/docs/api/providers/downtime/get */
public function getDowntime(int $id): Downtime
{
Expand Down
29 changes: 17 additions & 12 deletions tests/Clients/CustomersApiCreditsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@
namespace SandwaveIo\RealtimeRegister\Tests\Clients;

use PHPUnit\Framework\TestCase;
use SandwaveIo\RealtimeRegister\Domain\Account;
use SandwaveIo\RealtimeRegister\Domain\AccountCollection;
use SandwaveIo\RealtimeRegister\Tests\Helpers\MockedClientFactory;

class CustomersApiCreditsTest extends TestCase
{
public function test_credits(): void
{
$primary = include __DIR__ . '/../Domain/data/account_valid.php';
$primary['primary'] = true;

$secondary = include __DIR__ . '/../Domain/data/account_valid.php';
$secondary['primary'] = false;
$sdk = MockedClientFactory::makeSdk(
200,
json_encode([
'entities' => [
include __DIR__ . '/../Domain/data/account_valid.php',
include __DIR__ . '/../Domain/data/account_valid.php',
include __DIR__ . '/../Domain/data/account_valid.php',
],
'pagination' => [
'total' => 3,
'offset' => 0,
'limit' => 10,
],
]),
json_encode(
[
'accounts' => [
$primary,
$secondary,
$secondary,
],
]
),
MockedClientFactory::assertRoute('GET', 'v2/customers/johndoe/credit', $this)
);

$response = $sdk->customers->credits('johndoe');
$this->assertInstanceOf(AccountCollection::class, $response);
$this->assertInstanceOf(Account::class, $response->entities[0]);
$this->assertCount(3, $response->entities);
}
}
2 changes: 1 addition & 1 deletion tests/Domain/data/exchangerates_valid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

return [
return [
'currency' => 'EUR',
'exchangerates' => [
'USD' => 1000000,
Expand Down
2 changes: 1 addition & 1 deletion tests/Domain/data/process_invalid_status.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

return [
return [
'id' => 46069000,
'user' => 'johndoe/died',
'customer' => 'johndoe',
Expand Down
2 changes: 1 addition & 1 deletion tests/Domain/data/process_valid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

return [
return [
'id' => 46069000,
'user' => 'johndoe/died',
'customer' => 'johndoe',
Expand Down
2 changes: 1 addition & 1 deletion tests/Domain/data/process_valid_only_required.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

return [
return [
'id' => 46069000,
'user' => 'johndoe/died',
'customer' => 'johndoe',
Expand Down
2 changes: 1 addition & 1 deletion tests/Domain/data/transaction_valid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

return [
return [
'id' => 654563,
'customer' => 'johndoe',
'date' => '2021-08-11T06:17:15Z',
Expand Down

0 comments on commit 11dd0ea

Please sign in to comment.