Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RT-15782 Fallback to default limit #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RealtimeRegister\Api;

use RealtimeRegister\Exceptions\InvalidArgumentException;
use RealtimeRegister\Support\AuthorizedClient;

abstract class AbstractApi
Expand All @@ -12,4 +13,39 @@ public function __construct(AuthorizedClient $client)
{
$this->client = $client;
}

/**
* Default list query processing.
*
* @param int|null $limit
* @param int|null $offset
* @param string|null $search
* @param array|null $parameters
*
* @return array
*/
public function processListQuery(?int $limit, ?int $offset, ?string $search, ?array $parameters): array
{
$query = [];
if (! is_null($limit)) {
$query['limit'] = $limit;
}
if (! is_null($offset)) {
$query['offset'] = $offset;
}
if (! is_null($search)) {
$query['q'] = $search;
}

if (! is_null($parameters)) {
// Remove this special parameter, if it's used. It should only be used for the export calls
if (
array_key_exists('export', $parameters) && (array_key_exists('fields', $parameters) && ! empty($parameters['fields']))
) {
throw new InvalidArgumentException('Export parameter not allowed for this request, use the "export" request.');
PJEilers marked this conversation as resolved.
Show resolved Hide resolved
}
$query = array_merge($parameters, $query);
}
return $query;
}
}
46 changes: 11 additions & 35 deletions src/Api/BrandsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class BrandsApi extends AbstractApi
/* @see https://dm.realtimeregister.com/docs/api/brands/get */
public function get(string $customer, string $handle): Brand
{
$response = $this->client->get("/v2/customers/{$customer}/brands/{$handle}");
$response = $this->client->get(sprintf('/v2/customers/%s/brands/%s', urlencode($customer), urlencode($handle)));
return Brand::fromArray($response->json());
}

Expand All @@ -28,21 +28,9 @@ public function list(
?string $search = null,
?array $parameters = null
): BrandCollection {
$query = [];
if (! is_null($limit)) {
$query['limit'] = $limit;
}
if (! is_null($offset)) {
$query['offset'] = $offset;
}
if (! is_null($search)) {
$query['q'] = $search;
}
if (! is_null($parameters)) {
$query = array_merge($parameters, $query);
}
$query = $this->processListQuery($limit, $offset, $search, $parameters);

$response = $this->client->get("/v2/customers/{$customer}/brands", $query);
$response = $this->client->get(sprintf('/v2/customers/%s/brands', urlencode($customer)), $query);
return BrandCollection::fromArray($response->json());
}

Expand All @@ -52,7 +40,7 @@ public function export(
): array {
$query = $parameters;
$query['export'] = 'true';
$response = $this->client->get("/v2/customers/{$customer}/brands", $query);
$response = $this->client->get(sprintf('/v2/customers/%s/brands', urlencode($customer)), $query);
return $response->json()['entities'];
}

Expand Down Expand Up @@ -111,7 +99,7 @@ public function create(
$payload['updatedDate'] = $updatedDate;
}

$this->client->post("/v2/customers/{$customer}/brands/{$handle}", $payload);
$this->client->post(sprintf('/v2/customers/%s/brands/%s', urlencode($customer), urlencode($handle)), $payload);
}

/**
Expand Down Expand Up @@ -200,7 +188,7 @@ public function update(
$payload['updatedDate'] = $updatedDate;
}

$this->client->post("/v2/customers/{$customer}/brands/{$handle}/update", $payload);
$this->client->post(sprintf('/v2/customers/%s/brands/%s/update', urlencode($customer), urlencode($handle)), $payload);
}

/* @see https://dm.realtimeregister.com/docs/api/brands/delete */
Expand All @@ -214,7 +202,7 @@ public function getTemplate(string $customer, string $brand, string $name): Temp
{
TemplateNameEnum::validate($name);

return Template::fromArray($this->client->get("/v2/customers/{$customer}/brands/{$brand}/templates/{$name}")->json());
return Template::fromArray($this->client->get(sprintf('/v2/customers/%s/brands/%s/templates/%s', urlencode($customer), urlencode($brand), urlencode($name)))->json());
}

/* @see https://dm.realtimeregister.com/docs/api/brands/templates/list */
Expand All @@ -226,21 +214,9 @@ public function listTemplates(
?string $search = null,
?array $parameters = null
): TemplateCollection {
$query = [];
if (! is_null($limit)) {
$query['limit'] = $limit;
}
if (! is_null($offset)) {
$query['offset'] = $offset;
}
if (! is_null($search)) {
$query['q'] = $search;
}
if (! is_null($parameters)) {
$query = array_merge($parameters, $query);
}
$query = $this->processListQuery($limit, $offset, $search, $parameters);

$response = $this->client->get("/v2/customers/{$customer}/brands/{$brand}/templates", $query);
$response = $this->client->get(sprintf('/v2/customers/%s/brands/%s/templates', urlencode($customer), urlencode($brand)), $query);
return TemplateCollection::fromArray($response->json());
}

Expand All @@ -265,7 +241,7 @@ public function updateTemplate(
$payload['html'] = $html;
}

$this->client->post("/v2/customers/{$customer}/brands/{$brand}/templates/{$name}/update", $payload);
$this->client->post(sprintf('/v2/customers/%s/brands/%s/templates/%s/update', urlencode($customer), urlencode($brand), urlencode($name)), $payload);
}

/**
Expand Down Expand Up @@ -295,7 +271,7 @@ public function previewTemplate(string $customer, string $brand, string $name, ?
}

return TemplatePreview::fromArray(
$this->client->get("/v2/customers/{$customer}/brands/{$brand}/templates/{$name}/preview", $payload)->json()
$this->client->get(sprintf('/v2/customers/%s/brands/%s/templates/%s/preview', urlencode($customer), urlencode($brand), urlencode($name)), $payload)->json()
);
}
}
68 changes: 22 additions & 46 deletions src/Api/CertificatesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CertificatesApi extends AbstractApi
/* @see https://dm.realtimeregister.com/docs/api/ssl/get */
public function getCertificate(int $certificateId): Certificate
{
$response = $this->client->get('/v2/ssl/certificates/' . $certificateId);
$response = $this->client->get(sprintf('/v2/ssl/certificates/%s', $certificateId));

return Certificate::fromArray($response->json());
}
Expand All @@ -28,23 +28,7 @@ public function listCertificates(
?string $search = null,
?array $parameters = null
): CertificateCollection {
$query = [];

if (! is_null($limit)) {
$query['limit'] = $limit;
}

if (! is_null($offset)) {
$query['offset'] = $offset;
}

if (! is_null($search)) {
$query['q'] = $search;
}

if (! is_null($parameters)) {
$query = array_merge($parameters, $query);
}
$query = $this->processListQuery($limit, $offset, $search, $parameters);

$response = $this->client->get('/v2/ssl/certificates', $query);

Expand All @@ -56,7 +40,7 @@ public function downloadCertificate(int $certificateId, string $format = 'CRT'):
{
DownloadFormatEnum::validate($format);

$response = $this->client->get('/v2/ssl/certificates/' . $certificateId . '/download', ['format' => $format]);
$response = $this->client->get(sprintf('/v2/ssl/certificates/%s/download', $certificateId), ['format' => $format]);

return $response->text();
}
Expand All @@ -65,15 +49,15 @@ public function downloadCertificate(int $certificateId, string $format = 'CRT'):
public function listDcvEmailAddresses(string $domainName, string $product = null): array
{

$response = $this->client->get('/v2/ssl/dcvemailaddresslist/' . $domainName . ($product ? '?product=' . $product : ''));
$response = $this->client->get(sprintf('/v2/ssl/dcvemailaddresslist/%s', urlencode($domainName)) . ($product ? sprintf('?product=%s', urlencode($product)) : ''));

return $response->json();
}

/* @see https://dm.realtimeregister.com/docs/api/ssl/products/get */
public function getProduct(string $product): Product
{
$response = $this->client->get('/v2/ssl/products/' . $product);
$response = $this->client->get(sprintf('/v2/ssl/products/%s', urlencode($product)));

return Product::fromArray($response->json());
}
Expand All @@ -85,29 +69,21 @@ public function listProducts(
?string $search = null,
?array $parameters = null
): ProductCollection {
$query = [];

if (! is_null($limit)) {
$query['limit'] = $limit;
}

if (! is_null($offset)) {
$query['offset'] = $offset;
}

if (! is_null($search)) {
$query['q'] = $search;
}

if (! is_null($parameters)) {
$query = array_merge($parameters, $query);
}
$query = $this->processListQuery($limit, $offset, $search, $parameters);

$response = $this->client->get('/v2/ssl/products', $query);

return ProductCollection::fromArray($response->json());
}

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

/* @see https://dm.realtimeregister.com/docs/api/ssl/request */
public function requestCertificate(
string $customer,
Expand Down Expand Up @@ -293,7 +269,7 @@ public function renewCertificate(
$payload['product'] = $product;
}

$response = $this->client->post('/v2/ssl/certificates/' . $certificateId . '/renew', $payload);
$response = $this->client->post(sprintf('/v2/ssl/certificates/%s/renew', $certificateId), $payload);

return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));
}
Expand Down Expand Up @@ -377,7 +353,7 @@ public function reissueCertificate(
$payload['state'] = $state;
}

$response = $this->client->post('/v2/ssl/certificates/' . $certificateId . '/reissue', $payload);
$response = $this->client->post(sprintf('/v2/ssl/certificates/%s/reissue', $certificateId), $payload);

return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));
}
Expand All @@ -391,7 +367,7 @@ public function revokeCertificate(int $certificateId, ?string $reason = null): v
$payload['reason'] = $reason;
}

$this->client->delete('/v2/ssl/certificates/' . $certificateId, $payload);
$this->client->delete(sprintf('/v2/ssl/certificates/%s', $certificateId), $payload);
}

public function sendSubscriberAgreement(int $processId, string $email, ?string $language): void
Expand All @@ -404,7 +380,7 @@ public function sendSubscriberAgreement(int $processId, string $email, ?string $
$payload['language'] = $language;
}

$this->client->post('/v2/processes/' . $processId . '/send-subscriber-agreement', $payload);
$this->client->post(sprintf('/v2/processes/%s/send-subscriber-agreement', $processId), $payload);
}

/** @see https://dm.realtimeregister.com/docs/api/ssl/add-note */
Expand All @@ -414,7 +390,7 @@ public function addNote(int $processId, string $message): void
'message' => $message,
];

$this->client->post('/v2/processes/' . $processId . '/add-note', $payload);
$this->client->post(sprintf('/v2/processes/%s/add-note', $processId), $payload);
}

/** @see https://dm.realtimeregister.com/docs/api/ssl/schedule-validation-call */
Expand All @@ -424,13 +400,13 @@ public function scheduleValidationCall(int $processId, DateTimeImmutable $date):
'date' => $date,
];

$this->client->post('/v2/processes/' . $processId . '/schedule-validation-call', $payload);
$this->client->post(sprintf('/v2/processes/%s/schedule-validation-call', $processId), $payload);
}

/** @see https://dm.realtimeregister.com/docs/api/processes/info */
public function info(int $processId): CertificateInfoProcess
{
$response = $this->client->get('/v2/processes/' . $processId . '/info');
$response = $this->client->get(sprintf('/v2/processes/%s/info', $processId));

return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));

Expand Down Expand Up @@ -479,7 +455,7 @@ public function generateAuthKey(string $product, string $csr): array
/** @see https://dm.yoursrs-ote.com/docs/api/ssl/resenddcv */
public function resendDcv(int $processId, ResendDcvCollection $resendDcvCollection): ?array
{
$response = $this->client->post('/v2/processes/' . $processId . '/resend', $resendDcvCollection->toArray());
$response = $this->client->post(sprintf('/v2/processes/%s/resend', $processId), $resendDcvCollection->toArray());

if (
is_array($response->headers()) && array_key_exists('content-type', $response->headers())
Expand Down
Loading
Loading