Skip to content

Commit

Permalink
feat: remove raw response and introduce with http info
Browse files Browse the repository at this point in the history
  • Loading branch information
Orkuncakilkaya committed Jul 23, 2024
1 parent 9578f1e commit ce2fedf
Show file tree
Hide file tree
Showing 84 changed files with 745 additions and 460 deletions.
18 changes: 4 additions & 14 deletions run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,16 @@
error_reporting(error_reporting() & ~E_DEPRECATED);

try {
$result = $client->getVisits($visitor_id);
$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()));
list($result, $body) = $client->getVisitsWithHttpInfo($visitor_id);
fwrite(STDOUT, sprintf("Got visits: %s \n", $body));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

try {
$result = $client->getEvent($request_id);
$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()));
list($result, $body) = $client->getEventWithHttpInfo($request_id);
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $body));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
Expand Down
12 changes: 0 additions & 12 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,3 @@ 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
60 changes: 44 additions & 16 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function getConfig()
public function getEvent($request_id)
{
list($response) = $this->getEventWithHttpInfo($request_id);
if ($response === null) {
throw new \Exception("SerializationError, please get full response body with getEventWithHttpInfo");
}
return $response;
}

Expand All @@ -97,7 +100,7 @@ public function getEvent($request_id)
*
* @throws \Fingerprint\ServerAPI\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \Fingerprint\ServerAPI\Model\EventResponse, HTTP status code, HTTP response headers (array of strings)
* @return array of \Fingerprint\ServerAPI\Model\EventResponse, HTTP Response body contents, HTTP status code, HTTP response headers (array of strings)
*/
public function getEventWithHttpInfo($request_id)
{
Expand Down Expand Up @@ -134,11 +137,16 @@ public function getEventWithHttpInfo($request_id)

$responseBody = $response->getBody()->getContents();

$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
$serialized->setRawResponse($responseBody);
$serialized = null;
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
return [null, $responseBody, $response->getStatusCode(), $response->getHeaders()];
}

return [
$serialized,
$responseBody,
$response->getStatusCode(),
$response->getHeaders()
];
Expand All @@ -152,7 +160,6 @@ public function getEventWithHttpInfo($request_id)
'\Fingerprint\ServerAPI\Model\EventResponse',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 403:
Expand All @@ -162,7 +169,6 @@ public function getEventWithHttpInfo($request_id)
'\Fingerprint\ServerAPI\Model\ErrorEvent403Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 404:
Expand All @@ -172,7 +178,6 @@ public function getEventWithHttpInfo($request_id)
'\Fingerprint\ServerAPI\Model\ErrorEvent404Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
}
Expand All @@ -195,6 +200,10 @@ public function getEventAsync($request_id)
return $this->getEventAsyncWithHttpInfo($request_id)
->then(
function ($response) {
list($result) = $response;
if ($result === null) {
throw new \Exception("SerializationError, please get full response body with getEventWithHttpInfo");
}
return $response[0];
}
);
Expand All @@ -221,11 +230,16 @@ public function getEventAsyncWithHttpInfo($request_id)
function ($response) use ($returnType) {
$responseBody = $response->getBody()->getContents();

$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
$serialized->setRawResponse($responseBody);
$serialized = null;
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
return [null, $responseBody, $response->getStatusCode(), $response->getHeaders()];
}

return [
$serialized,
$responseBody,
$response->getStatusCode(),
$response->getHeaders()
];
Expand Down Expand Up @@ -334,6 +348,9 @@ protected function getEventRequest($request_id)
public function getVisits($visitor_id, $request_id = null, $linked_id = null, $limit = null, $pagination_key = null, $before = null)
{
list($response) = $this->getVisitsWithHttpInfo($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before);
if ($response === null) {
throw new \Exception("SerializationError, please get full response body with getVisitsWithHttpInfo");
}
return $response;
}

Expand All @@ -351,7 +368,7 @@ public function getVisits($visitor_id, $request_id = null, $linked_id = null, $l
*
* @throws \Fingerprint\ServerAPI\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of \Fingerprint\ServerAPI\Model\Response, HTTP status code, HTTP response headers (array of strings)
* @return array of \Fingerprint\ServerAPI\Model\Response, HTTP Response body contents, HTTP status code, HTTP response headers (array of strings)
*/
public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_id = null, $limit = null, $pagination_key = null, $before = null)
{
Expand Down Expand Up @@ -388,11 +405,16 @@ public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_i

$responseBody = $response->getBody()->getContents();

$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
$serialized->setRawResponse($responseBody);
$serialized = null;
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
return [null, $responseBody, $response->getStatusCode(), $response->getHeaders()];
}

return [
$serialized,
$responseBody,
$response->getStatusCode(),
$response->getHeaders()
];
Expand All @@ -406,7 +428,6 @@ public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_i
'\Fingerprint\ServerAPI\Model\Response',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 403:
Expand All @@ -416,7 +437,6 @@ public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_i
'\Fingerprint\ServerAPI\Model\ErrorVisits403',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
case 429:
Expand All @@ -426,7 +446,6 @@ public function getVisitsWithHttpInfo($visitor_id, $request_id = null, $linked_i
'\Fingerprint\ServerAPI\Model\ManyRequestsResponse',
$e->getResponseHeaders()
);
$data->setRawResponse($responseBody);
$e->setResponseObject($data);
break;
}
Expand Down Expand Up @@ -454,6 +473,10 @@ public function getVisitsAsync($visitor_id, $request_id = null, $linked_id = nul
return $this->getVisitsAsyncWithHttpInfo($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before)
->then(
function ($response) {
list($result) = $response;
if ($result === null) {
throw new \Exception("SerializationError, please get full response body with getVisitsWithHttpInfo");
}
return $response[0];
}
);
Expand Down Expand Up @@ -485,11 +508,16 @@ public function getVisitsAsyncWithHttpInfo($visitor_id, $request_id = null, $lin
function ($response) use ($returnType) {
$responseBody = $response->getBody()->getContents();

$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
$serialized->setRawResponse($responseBody);
$serialized = null;
try {
$serialized = ObjectSerializer::deserialize($responseBody, $returnType, []);
} catch (\Exception $e) {
return [null, $responseBody, $response->getStatusCode(), $response->getHeaders()];
}

return [
$serialized,
$responseBody,
$response->getStatusCode(),
$response->getHeaders()
];
Expand Down
3 changes: 2 additions & 1 deletion src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Fingerprint\ServerAPI;

use Exception;
use \Exception;

/**
* ApiException Class Doc Comment
Expand All @@ -39,6 +39,7 @@
*/
class ApiException extends Exception
{

/**
* The HTTP body of the server response either as Json or string.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ public function getApiKeyWithPrefix($apiKeyIdentifier)

return $keyWithPrefix;
}
}
}
9 changes: 4 additions & 5 deletions src/Model/ASN.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

namespace Fingerprint\ServerAPI\Model;

use ArrayAccess;
use Fingerprint\ServerAPI\ObjectSerializer;
use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;

/**
* ASN Class Doc Comment
Expand All @@ -41,8 +41,7 @@
*/
class ASN implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
public const DISCRIMINATOR = null;
const DISCRIMINATOR = null;

/**
* The original name of the model.
Expand Down Expand Up @@ -163,7 +162,7 @@ public function getModelName()
return self::$swaggerModelName;
}



/**
* Associative array for storing property values
Expand Down
13 changes: 6 additions & 7 deletions src/Model/BotdDetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

namespace Fingerprint\ServerAPI\Model;

use ArrayAccess;
use Fingerprint\ServerAPI\ObjectSerializer;
use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;

/**
* BotdDetectionResult Class Doc Comment
Expand All @@ -42,8 +42,7 @@
*/
class BotdDetectionResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
public const DISCRIMINATOR = null;
const DISCRIMINATOR = null;

/**
* The original name of the model.
Expand Down Expand Up @@ -159,9 +158,9 @@ public function getModelName()
return self::$swaggerModelName;
}

public const RESULT_NOT_DETECTED = 'notDetected';
public const RESULT_GOOD = 'good';
public const RESULT_BAD = 'bad';
const RESULT_NOT_DETECTED = 'notDetected';
const RESULT_GOOD = 'good';
const RESULT_BAD = 'bad';

/**
* Gets allowable values of the enum
Expand Down
9 changes: 4 additions & 5 deletions src/Model/BotdResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

namespace Fingerprint\ServerAPI\Model;

use ArrayAccess;
use Fingerprint\ServerAPI\ObjectSerializer;
use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;

/**
* BotdResult Class Doc Comment
Expand All @@ -42,8 +42,7 @@
*/
class BotdResult implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
public const DISCRIMINATOR = null;
const DISCRIMINATOR = null;

/**
* The original name of the model.
Expand Down Expand Up @@ -184,7 +183,7 @@ public function getModelName()
return self::$swaggerModelName;
}



/**
* Associative array for storing property values
Expand Down
9 changes: 4 additions & 5 deletions src/Model/BrowserDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

namespace Fingerprint\ServerAPI\Model;

use ArrayAccess;
use Fingerprint\ServerAPI\ObjectSerializer;
use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;

/**
* BrowserDetails Class Doc Comment
Expand All @@ -41,8 +41,7 @@
*/
class BrowserDetails implements ModelInterface, ArrayAccess
{
// use \Fingerprint\ServerAPI\Traits\WithRawResponse;
public const DISCRIMINATOR = null;
const DISCRIMINATOR = null;

/**
* The original name of the model.
Expand Down Expand Up @@ -188,7 +187,7 @@ public function getModelName()
return self::$swaggerModelName;
}



/**
* Associative array for storing property values
Expand Down
Loading

0 comments on commit ce2fedf

Please sign in to comment.