Skip to content

Commit

Permalink
Merge branch 'sandwave-io:master' into premium-dns-missing-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zbrag authored Sep 6, 2024
2 parents b32e2ed + 11dd0ea commit 55f57ec
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 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']);
}
}
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);
}
}

0 comments on commit 55f57ec

Please sign in to comment.