Skip to content

refactor: introduce async method and wip inline types #100

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

Merged
merged 15 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ You can use below code to verify signature:
```php
<?php

use Fingerprint\ServerAPI\Webhook\WebhookVerifier;

// Your webhook signing secret.
$webhookSecret = "secret";

Expand All @@ -191,7 +193,7 @@ $webhookData = "data";
// Value of the "fpjs-event-signature" header.
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";

$isValidWebhookSign = \Fingerprint\ServerAPI\Webhook\WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);

if(!$isValidWebhookSign) {
fwrite(STDERR, sprintf("Webhook signature verification failed\n"));
Expand Down
3 changes: 2 additions & 1 deletion run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use GuzzleHttp\Client;
use Fingerprint\ServerAPI\Webhook\WebhookVerifier;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

Expand Down Expand Up @@ -91,7 +92,7 @@
$webhookSecret = "secret";
$webhookData = "data";
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";
$isValidWebhookSign = \Fingerprint\ServerAPI\Webhook\WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
if($isValidWebhookSign) {
fwrite(STDOUT, sprintf("\n\nVerified webhook signature\n"));
} else {
Expand Down
20 changes: 16 additions & 4 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ rm -f ./src/Model/*

java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/fingerprint-server-api.yaml -o ./ -c config.json

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
fi

# fix invalid code generated for structure with additionalProperties
(
# Model file fix
Expand All @@ -50,6 +54,18 @@ java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/f
fi
)

# fix invalid code generated for SignalResponseRawDeviceAttributes
(
# Model file fix
if [ "$platform" = "Darwin" ]; then
sed -i '' 's/public function setData(?RawDeviceAttributesResult $data): self/public function setData(?array $data): self/' ./src/Model/SignalResponseRawDeviceAttributes.php
sed -i '' 's/public function getData(): ?RawDeviceAttributesResult/public function getData(): array/' ./src/Model/SignalResponseRawDeviceAttributes.php
else
sed -i 's/public function setData(?RawDeviceAttributesResult $data): self/public function setData(?array $data): self/' ./src/Model/SignalResponseRawDeviceAttributes.php
sed -i 's/public function getData(): ?RawDeviceAttributesResult/public function getData(): array/' ./src/Model/SignalResponseRawDeviceAttributes.php
fi
)

(
# Readme file fix
replacement=$(printf 'The rawAttributes object follows this general shape: `{ value: any } | { error: { name: string; message: string; } }`\n')
Expand All @@ -67,7 +83,3 @@ mv -f src/README.md ./README.md
mv -f src/composer.json composer.json
find ./docs -type f ! -name "DecryptionKey.md" ! -name "Sealed.md" ! -name "Webhook.md" -exec rm {} +
mv -f src/docs/* ./docs

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
fi
3 changes: 3 additions & 0 deletions sealed_results_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

require_once(__DIR__ . '/vendor/autoload.php');

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? "");
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? "");

Expand Down
24 changes: 24 additions & 0 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,22 @@ public function getEvent(string $request_id): array

switch ($e->getCode()) {
case 200:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\EventResponse');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 403:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent403Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 404:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent404Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;
Expand Down Expand Up @@ -192,16 +198,22 @@ function ($e) {

switch ($e->getCode()) {
case 200:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\EventResponse');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 403:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent403Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 404:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent404Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;
Expand Down Expand Up @@ -275,16 +287,22 @@ public function getVisits(string $visitor_id, ?string $request_id = null, ?strin

switch ($e->getCode()) {
case 200:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 403:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisits403');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 429:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ManyRequestsResponse');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;
Expand Down Expand Up @@ -344,16 +362,22 @@ function ($e) {

switch ($e->getCode()) {
case 200:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\Response');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 403:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisits403');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;

case 429:
$errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ManyRequestsResponse');
$e->setErrorDetails($errorDetail);
$e->setResponseObject($response);

break;
Expand Down
12 changes: 12 additions & 0 deletions src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

namespace Fingerprint\ServerAPI;

use Fingerprint\ServerAPI\Model\ModelInterface;
use Psr\Http\Message\ResponseInterface;

/**
Expand All @@ -42,6 +43,7 @@
class ApiException extends \Exception
{
protected ResponseInterface $responseObject;
protected ModelInterface $errorDetails;

public function __construct(?string $message = '', ?int $code = 0)
{
Expand All @@ -60,4 +62,14 @@ public function getResponseObject(): ResponseInterface
{
return $this->responseObject;
}

public function getErrorDetails(): ModelInterface
{
return $this->errorDetails;
}

public function setErrorDetails(ModelInterface $errorDetails): void
{
$this->errorDetails = $errorDetails;
}
}
20 changes: 8 additions & 12 deletions src/Model/ASN.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ public function valid(): bool

/**
* Gets asn.
*
* @return string
*/
public function getAsn()
public function getAsn(): string
{
return $this->container['asn'];
}
Expand All @@ -227,7 +225,7 @@ public function getAsn()
*
* @return $this
*/
public function setAsn($asn): self
public function setAsn(string $asn): self
{
$this->container['asn'] = $asn;

Expand All @@ -236,10 +234,8 @@ public function setAsn($asn): self

/**
* Gets network.
*
* @return string
*/
public function getNetwork()
public function getNetwork(): string
{
return $this->container['network'];
}
Expand All @@ -251,7 +247,7 @@ public function getNetwork()
*
* @return $this
*/
public function setNetwork($network): self
public function setNetwork(string $network): self
{
$this->container['network'] = $network;

Expand All @@ -261,21 +257,21 @@ public function setNetwork($network): self
/**
* Gets name.
*
* @return string
* @return ?string
*/
public function getName()
public function getName(): ?string
{
return $this->container['name'];
}

/**
* Sets name.
*
* @param string $name name
* @param ?string $name name
*
* @return $this
*/
public function setName($name): self
public function setName(?string $name): self
{
$this->container['name'] = $name;

Expand Down
14 changes: 6 additions & 8 deletions src/Model/BotdDetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,8 @@ public function valid(): bool

/**
* Gets result.
*
* @return string
*/
public function getResult()
public function getResult(): string
{
return $this->container['result'];
}
Expand All @@ -244,7 +242,7 @@ public function getResult()
*
* @return $this
*/
public function setResult($result): self
public function setResult(string $result): self
{
$allowedValues = $this->getResultAllowableValues();
if (!in_array($result, $allowedValues, true)) {
Expand All @@ -263,21 +261,21 @@ public function setResult($result): self
/**
* Gets type.
*
* @return string
* @return ?string
*/
public function getType()
public function getType(): ?string
{
return $this->container['type'];
}

/**
* Sets type.
*
* @param string $type type
* @param ?string $type type
*
* @return $this
*/
public function setType($type): self
public function setType(?string $type): self
{
$this->container['type'] = $type;

Expand Down
Loading
Loading