-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bc6d9a
commit 6314d2e
Showing
21 changed files
with
553 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
<?php | ||
|
||
use Saloon\RateLimitPlugin\Limit; | ||
|
||
return [ | ||
/** | ||
* The API key to be used for authenticating with the Plytix API. | ||
*/ | ||
'api_key' => env('PLYTIX_API_KEY'), | ||
|
||
/** | ||
* The API password to be used for authenticating with the Plytix API. | ||
*/ | ||
'api_password' => env('PLYTIX_API_PASSWORD'), | ||
|
||
'authenticator_cache' => [ | ||
/** | ||
* The key that will be used to cache the Plytix access token. | ||
*/ | ||
'key' => 'esign.plytix.authenticator', | ||
|
||
/** | ||
* The cache store to be used for the Plytix access token. | ||
* Use null to utilize the default cache store from the cache.php config file. | ||
* To disable caching, you can use the 'array' store. | ||
*/ | ||
'store' => null, | ||
], | ||
|
||
'rate_limiting' => [ | ||
/** | ||
* The rate limits to be used for the Plytix API. | ||
*/ | ||
'limits' => [ | ||
Limit::allow(20)->everySeconds(10), | ||
Limit::allow(2000)->everyHour(), | ||
], | ||
|
||
/** | ||
* The cache store to be used for the Plytix rate limits. | ||
* Use null to utilize the default cache store from the cache.php config file. | ||
* To disable caching, you can use the 'array' store. | ||
*/ | ||
'cache_store' => null, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Esign Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Esign Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
<env name="PLYTIX_API_KEY" value="fake-api-key"/> | ||
<env name="PLYTIX_API_PASSWORD" value="fake-api-password"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix; | ||
|
||
use Saloon\Http\Connector; | ||
use Saloon\Traits\Plugins\AcceptsJson; | ||
|
||
class PlytixAuth extends Connector | ||
{ | ||
use AcceptsJson; | ||
|
||
public function resolveBaseUrl(): string | ||
{ | ||
return 'https://auth.plytix.com'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix; | ||
|
||
use DateTimeImmutable; | ||
use Saloon\Contracts\Authenticator; | ||
use Saloon\Http\PendingRequest; | ||
|
||
class PlytixTokenAuthenticator implements Authenticator | ||
{ | ||
public function __construct( | ||
public readonly string $token, | ||
public readonly DateTimeImmutable $expiresAt = new DateTimeImmutable('+15 minutes'), | ||
) { | ||
} | ||
|
||
public function set(PendingRequest $pendingRequest): void | ||
{ | ||
$pendingRequest->headers()->add('Authorization', 'Bearer ' . $this->token); | ||
} | ||
|
||
public function hasExpired(): bool | ||
{ | ||
return $this->expiresAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateProductRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected array $payload) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/products'; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class TokenRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected string $apiKey, | ||
protected string $apiPassword, | ||
) { | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/auth/api/get-token'; | ||
} | ||
|
||
protected function defaultBody(): array | ||
{ | ||
return [ | ||
'api_key' => $this->apiKey, | ||
'api_password' => $this->apiPassword, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class UpdateProductRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::PATCH; | ||
|
||
public function __construct(protected string $productId, protected array $payload) | ||
{} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/products/' . $this->productId; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
} |
Oops, something went wrong.