Skip to content

Feature/new request handling logic inter 767 #96

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 37 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
26e984f
feat: only generate models and docs from swagger codegen
Orkuncakilkaya Jul 10, 2024
ec7c274
chore: remove templates for api client and api doc
Orkuncakilkaya Jul 10, 2024
0016822
feat: rewrite request logic
Orkuncakilkaya Jul 15, 2024
dfcea98
chore(ci): update minimum php version to 8.1
Orkuncakilkaya Jul 15, 2024
a3157a8
docs(api): add fingerprint api doc
Orkuncakilkaya Jul 15, 2024
d62eac6
refactor: add return for methods
Orkuncakilkaya Jul 15, 2024
9b01ba6
feat: introduce rawResponse for getVisits and getEvent methods
Orkuncakilkaya Jul 16, 2024
8726f6b
refactor: set integration info on constructor
Orkuncakilkaya Jul 16, 2024
f7bb343
refactor: introduce with raw response trait
Orkuncakilkaya Jul 16, 2024
a3df26c
refactor: rename duplicate variables
Orkuncakilkaya Jul 16, 2024
8989f57
chore(generator): update raw response models to an array
Orkuncakilkaya Jul 16, 2024
650b7b5
chore: merge from develop
Orkuncakilkaya Jul 17, 2024
90f3bb1
docs(api): add fingerprint api doc
Orkuncakilkaya Jul 17, 2024
91c550e
docs(api): fix styling
Orkuncakilkaya Jul 17, 2024
5daa81c
refactor: remove redundant functions from api
Orkuncakilkaya Jul 19, 2024
a6b7a7d
refactor: fix body params condition
Orkuncakilkaya Jul 23, 2024
3f6aabc
refactor: generate fingerprint api for temp body fix
Orkuncakilkaya Jul 23, 2024
0c9aca8
docs(api): fix spacings
Orkuncakilkaya Jul 23, 2024
36d6f9e
chore: add php cs fixer cache to gitignore
Orkuncakilkaya Jul 23, 2024
a31a1eb
chore: add php cs fixer to pre commit
Orkuncakilkaya Jul 23, 2024
151f7cc
chore: add unknown field tests
Orkuncakilkaya Jul 23, 2024
fe587ee
chore: extend unknown field from event test case
Orkuncakilkaya Jul 23, 2024
9578f1e
refactor: remove header selector
Orkuncakilkaya Jul 23, 2024
ce2fedf
feat: remove raw response and introduce with http info
Orkuncakilkaya Jul 23, 2024
9da81d3
chore: php cs fixer
Orkuncakilkaya Jul 23, 2024
cce2ee4
chore: add style fixer to generate script
Orkuncakilkaya Jul 23, 2024
66d9015
chore: style fix to tests
Orkuncakilkaya Jul 23, 2024
62e4ad3
feat: change api to return tuple instead of serialized model
Orkuncakilkaya Jul 24, 2024
f6b7659
refactor: remove discriminator from object serializer and remove its …
Orkuncakilkaya Jul 24, 2024
bfea23a
feat: introduce serialization exception
Orkuncakilkaya Jul 24, 2024
6e0d193
refactor: add previous exception for serialization exception
Orkuncakilkaya Jul 25, 2024
7e154d9
refactor: change error handling
Orkuncakilkaya Jul 25, 2024
abb338b
refactor: code style and error handling
Orkuncakilkaya Jul 26, 2024
b8a89cf
refactor: update pre commit
Orkuncakilkaya Jul 26, 2024
ae7c93a
refactor: update composer dependencies
Orkuncakilkaya Jul 26, 2024
15b71da
refactor: update model comment header
Orkuncakilkaya Jul 26, 2024
c2c3d14
refactor: remove psr 1 and psr 2 from cs fixer
Orkuncakilkaya Jul 26, 2024
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: 2 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Most files in the project are autogenerated by [swagger-codegen](https://swagger.io/tools/swagger-codegen/) for php.

- [template](./template) - folder contains redefined templates of `swagger-codegen`. Original templates you can find in [swagger-codegen repo](https://github.com/swagger-api/swagger-codegen/tree/751e59df060b1c3ecf54921e104f2086dfa9f820/modules/swagger-codegen/src/main/resources/php).
- [docs](./docs) - generated documentation for models and [API Client](./docs/Api/FingerprintApi.md).
- [src](./src) - API Client code is generated automatically.
- [docs](./docs) - generated documentation for models and [API Client](docs/Api/FingerprintApi.md).
- [src](./src) - API Client code and generated models.

## Code generation

Expand Down
16 changes: 8 additions & 8 deletions docs/Api/FingerprintApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ use GuzzleHttp\Client;
// Create new Configuration instance with defaultValues, added our API Secret and our Region
$config = Configuration::getDefaultConfiguration(FPJS_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
new Client(),
$config
new Client(),
$config
);

$request_id = "request_id_example"; // string | The unique [identifier](https://dev.fingerprint.com/docs/js-agent#requestid) of each analysis request.

try {
$result = $client->getEvent($request_id);
$result = $client->getEvent($request_id);
echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
echo 'Exception when calling FingerprintApi->getEvent: ', $e->getMessage(), PHP_EOL;
echo 'Exception when calling FingerprintApi->getEvent: ', $e->getMessage(), PHP_EOL;
}
?>
```
Expand Down Expand Up @@ -89,8 +89,8 @@ use GuzzleHttp\Client;
// Create new Configuration instance with defaultValues, added our API Secret and our Region
$config = Configuration::getDefaultConfiguration(FPJS_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
new Client(),
$config
new Client(),
$config
);

$visitor_id = "visitor_id_example"; // string | Unique identifier of the visitor issued by Fingerprint Pro.
Expand All @@ -101,10 +101,10 @@ $pagination_key = "pagination_key_example"; // string | Use `paginationKey` to g
$before = 789; // int | ⚠️ Deprecated pagination method, please use `paginationKey` instead. Timestamp (in milliseconds since epoch) used to paginate results.

try {
$result = $client->getVisits($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before);
$result = $client->getVisits($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before);
echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
echo 'Exception when calling FingerprintApi->getVisits: ', $e->getMessage(), PHP_EOL;
echo 'Exception when calling FingerprintApi->getVisits: ', $e->getMessage(), PHP_EOL;
}
?>
```
Expand Down
18 changes: 14 additions & 4 deletions run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,32 @@

try {
$result = $client->getVisits($visitor_id);
fwrite(STDOUT, sprintf("Got visits: %s \n", $result));
$rawResponseDecoded = json_decode($result->getRawResponse(), true);
if ($rawResponseDecoded['visitorId'] !== $visitor_id) {
fwrite(STDERR, sprintf("Raw response for getVisits not working"));
exit(1);
}
fwrite(STDOUT, sprintf("Got visits: %s \n", $result->getRawResponse()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

try {
$result = $client->getEvent($request_id);
fwrite(STDOUT, sprintf("Got event: %s \n", $result));
$rawResponseDecoded = json_decode($result->getRawResponse(), true);
if ($rawResponseDecoded['products']['identification']['data']['requestId'] !== $request_id) {
fwrite(STDERR, sprintf("Raw response for getEvent not working"));
exit(1);
}
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $result->getRawResponse()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "Checks passed\n");
fwrite(STDOUT, "\n\nChecks passed\n");
exit(0);
13 changes: 13 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ mv -f src/README.md ./README.md
mv -f src/composer.json composer.json
find ./docs -type f ! -name "DecryptionKey.md" ! -name "Sealed.md" -exec rm {} +
mv -f src/docs/* ./docs

declare -a modelsWithRawResponse=("./src/Model/EventResponse.php" "./src/Model/Response.php")

for model in "${modelsWithRawResponse[@]}"; do
# enable WithRawResponse trait for the model
(
if [ "$platform" = "Darwin" ]; then
sed -i '' 's/\/\/ use \\/use \\/' $model
else
sed -i 's/\/\/ use \\/use \\/' $model
fi
)
done
61 changes: 37 additions & 24 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,9 @@
*/
class FingerprintApi
{
/**
* @var ClientInterface
*/
protected $client;

/**
* @var Configuration
*/
protected $config;

/**
* @var HeaderSelector
*/
protected $headerSelector;
protected ClientInterface $client;
protected Configuration $config;
protected HeaderSelector $headerSelector;

protected $integration_info = 'fingerprint-pro-server-php-sdk/4.1.0';

Expand Down Expand Up @@ -159,36 +148,45 @@ public function getEventWithHttpInfo($request_id)
}
}

$serialized = ObjectSerializer::deserialize($content, $returnType, []);
$serialized->setRawResponse($responseBody);

return [
ObjectSerializer::deserialize($content, $returnType, []),
$serialized,
$response->getStatusCode(),
$response->getHeaders()
];

} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\EventResponse',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 403:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\ErrorEvent403Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 404:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\ErrorEvent404Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
}
Expand Down Expand Up @@ -245,8 +243,11 @@ function ($response) use ($returnType) {
}
}

$serialized = ObjectSerializer::deserialize($content, $returnType, []);
$serialized->setRawResponse($responseBody);

return [
ObjectSerializer::deserialize($content, $returnType, []),
$serialized,
$response->getStatusCode(),
$response->getHeaders()
];
Expand Down Expand Up @@ -457,36 +458,45 @@ public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_i
}
}

$serialized = ObjectSerializer::deserialize($content, $returnType, []);
$serialized->setRawResponse($responseBody);

return [
ObjectSerializer::deserialize($content, $returnType, []),
$serialized,
$response->getStatusCode(),
$response->getHeaders()
];

} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 403:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\ErrorVisits403',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 429:
$responseBody = $e->getResponseBody();
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
$responseBody,
'\Fingerprint\ServerAPI\Model\ManyRequestsResponse',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
}
Expand Down Expand Up @@ -553,8 +563,11 @@ function ($response) use ($returnType) {
}
}

$serialized = ObjectSerializer::deserialize($content, $returnType, []);
$serialized->setRawResponse($responseBody);

return [
ObjectSerializer::deserialize($content, $returnType, []),
$serialized,
$response->getStatusCode(),
$response->getHeaders()
];
Expand Down
1 change: 1 addition & 0 deletions src/Model/ASN.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ASN implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/BotdDetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
class BotdDetectionResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/BotdResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
class BotdResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/BrowserDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class BrowserDetails implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ClonedAppResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ClonedAppResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/Confidence.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class Confidence implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/DataCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class DataCenter implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/DeprecatedIPLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
class DeprecatedIPLocation implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/DeprecatedIPLocationCity.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class DeprecatedIPLocationCity implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/EmulatorResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class EmulatorResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ErrorEvent403Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ErrorEvent403Response implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ErrorEvent403ResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ErrorEvent403ResponseError implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ErrorEvent404Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ErrorEvent404Response implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ErrorEvent404ResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ErrorEvent404ResponseError implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/ErrorVisits403.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class ErrorVisits403 implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/EventResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
class EventResponse implements ModelInterface, ArrayAccess
{
use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/FactoryResetResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
class FactoryResetResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
const DISCRIMINATOR = null;

/**
Expand Down
Loading
Loading