diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 82a9f0b..25e08ba 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 43187d3e-7c3c-4c11-b5d4-4b2334fb6d96 management: - docChecksum: ebeafbab98f36580b94fa4a78ab949c3 + docChecksum: da455826be171d9d1ff0d376f0695b24 docVersion: 0.0.1 - speakeasyVersion: 1.448.2 - generationVersion: 2.467.4 - releaseVersion: 0.11.4 - configChecksum: d3f345e68c310c8a86cf9438f15617de + speakeasyVersion: 1.453.0 + generationVersion: 2.472.1 + releaseVersion: 0.11.5 + configChecksum: 7d70fbd2bde72316f690523b5ea79cd3 repoURL: https://github.com/dubinc/dub-php.git installationURL: https://github.com/dubinc/dub-php published: true @@ -273,6 +273,19 @@ generatedFiles: - src/DubBuilder.php - src/EmbedTokens.php - src/Events.php + - src/Hooks/AfterErrorContext.php + - src/Hooks/AfterErrorHook.php + - src/Hooks/AfterSuccessContext.php + - src/Hooks/AfterSuccessHook.php + - src/Hooks/BeforeRequestContext.php + - src/Hooks/BeforeRequestHook.php + - src/Hooks/ErrorResponseContext.php + - src/Hooks/FailEarlyException.php + - src/Hooks/HookContext.php + - src/Hooks/Hooks.php + - src/Hooks/SDKHooks.php + - src/Hooks/SDKInitHook.php + - src/Hooks/SDKRequestContext.php - src/Links.php - src/Metatags.php - src/Models/Components/AnalyticsBrowsers.php @@ -869,7 +882,7 @@ examples: idOrSlug: "" responses: "200": - application/json: {"id": "", "name": "", "slug": "", "logo": "", "inviteCode": "", "plan": "business extra", "stripeId": "", "billingCycleStart": "900.65", "paymentFailedAt": "", "stripeConnectId": "", "usage": "5588.34", "usageLimit": "8441.99", "linksUsage": "5442.21", "linksLimit": "8306.36", "salesUsage": "5212.35", "salesLimit": "785.92", "domainsLimit": "9699.61", "tagsLimit": "8661.61", "usersLimit": "4580.49", "aiUsage": "7352.87", "aiLimit": "4508.24", "referralLinkId": "", "conversionEnabled": true, "dotLinkClaimed": true, "createdAt": "", "users": [], "domains": [], "publishableKey": "", "bankAccountName": "", "partialAccountNumber": "", "routingNumber": "", "bankAccountVerified": false} + application/json: {"id": "", "name": "", "slug": "", "logo": "", "inviteCode": "", "plan": "business extra", "stripeId": "", "billingCycleStart": "900.65", "paymentFailedAt": "", "stripeConnectId": "", "usage": "5588.34", "usageLimit": "8441.99", "linksUsage": "5442.21", "linksLimit": "8306.36", "salesUsage": "5212.35", "salesLimit": "785.92", "domainsLimit": "9699.61", "tagsLimit": "8661.61", "usersLimit": "4580.49", "aiUsage": "7352.87", "aiLimit": "4508.24", "conversionEnabled": true, "dotLinkClaimed": true, "createdAt": "", "users": [], "domains": [], "publishableKey": "", "bankAccountName": "", "partialAccountNumber": "", "routingNumber": "", "bankAccountVerified": false} "400": application/json: {"error": {"code": "bad_request", "message": "The requested resource was not found.", "doc_url": "https://dub.co/docs/api-reference/errors#bad-request"}} "401": @@ -895,7 +908,7 @@ examples: idOrSlug: "" responses: "200": - application/json: {"id": "", "name": "", "slug": "", "logo": "", "inviteCode": "", "plan": "enterprise", "stripeId": "", "billingCycleStart": "245.55", "paymentFailedAt": "", "stripeConnectId": "", "usage": "5971.29", "usageLimit": "156.52", "linksUsage": "3446.2", "linksLimit": "7084.55", "salesUsage": "9914.64", "salesLimit": "2703.24", "domainsLimit": "6276.9", "tagsLimit": "6841.99", "usersLimit": "4888.52", "aiUsage": "4430.76", "aiLimit": "9840.08", "referralLinkId": "", "conversionEnabled": false, "dotLinkClaimed": false, "createdAt": "", "users": [], "domains": [], "publishableKey": "", "bankAccountName": "", "partialAccountNumber": "", "routingNumber": "", "bankAccountVerified": false} + application/json: {"id": "", "name": "", "slug": "", "logo": "", "inviteCode": "", "plan": "enterprise", "stripeId": "", "billingCycleStart": "245.55", "paymentFailedAt": "", "stripeConnectId": "", "usage": "5971.29", "usageLimit": "156.52", "linksUsage": "3446.2", "linksLimit": "7084.55", "salesUsage": "9914.64", "salesLimit": "2703.24", "domainsLimit": "6276.9", "tagsLimit": "6841.99", "usersLimit": "4888.52", "aiUsage": "4430.76", "aiLimit": "9840.08", "conversionEnabled": false, "dotLinkClaimed": false, "createdAt": "", "users": [], "domains": [], "publishableKey": "", "bankAccountName": "", "partialAccountNumber": "", "routingNumber": "", "bankAccountVerified": false} "400": application/json: {"error": {"code": "bad_request", "message": "The requested resource was not found.", "doc_url": "https://dub.co/docs/api-reference/errors#bad-request"}} "401": diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 5332e63..76ab564 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false php: - version: 0.11.4 + version: 0.11.5 clientServerStatusCodesAsErrors: true defaultErrorName: SDKException flattenGlobalSecurity: true diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 4322d2e..3c275f2 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,21 @@ -speakeasyVersion: 1.448.2 +speakeasyVersion: 1.453.0 sources: dub: sourceNamespace: dub - sourceRevisionDigest: sha256:9d15980874e61b0ff83224b26358510380a239a1c884e835d8e710bb70cd83ea - sourceBlobDigest: sha256:05e717ca7c8803f62c2536db9ec23d6f5c6ba9c19970b944c6500f280753d820 + sourceRevisionDigest: sha256:ff35145df9477779b92bd354179241024be114e1dcf82cc21e4ab364002f9c3f + sourceBlobDigest: sha256:98d898001f0ef6455618c09c8c6a368877c2fc520cb3d1ed70a17728d4775a9e tags: - latest - - speakeasy-sdk-regen-1732925995 + - speakeasy-sdk-regen-1733444459 - 0.0.1 targets: my-first-target: source: dub sourceNamespace: dub - sourceRevisionDigest: sha256:9d15980874e61b0ff83224b26358510380a239a1c884e835d8e710bb70cd83ea - sourceBlobDigest: sha256:05e717ca7c8803f62c2536db9ec23d6f5c6ba9c19970b944c6500f280753d820 + sourceRevisionDigest: sha256:ff35145df9477779b92bd354179241024be114e1dcf82cc21e4ab364002f9c3f + sourceBlobDigest: sha256:98d898001f0ef6455618c09c8c6a368877c2fc520cb3d1ed70a17728d4775a9e codeSamplesNamespace: code-samples-php-my-first-target - codeSamplesRevisionDigest: sha256:907fd062e7b363d3be59b05ffd7cd78def0567998d6f6fd2c84c1fe99cabd494 + codeSamplesRevisionDigest: sha256:58c5e4d251f54966916d98b7077a81c37ec03b04513dbb619f086377f667e3a4 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/RELEASES.md b/RELEASES.md index 061c001..de38737 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -490,4 +490,14 @@ Based on: ### Generated - [php v0.11.4] . ### Releases -- [Composer v0.11.4] https://packagist.org/packages/dub/dub-php#v0.11.4 - . \ No newline at end of file +- [Composer v0.11.4] https://packagist.org/packages/dub/dub-php#v0.11.4 - . + +## 2024-12-06 00:20:55 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.453.0 (2.472.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [php v0.11.5] . +### Releases +- [Composer v0.11.5] https://packagist.org/packages/dub/dub-php#v0.11.5 - . \ No newline at end of file diff --git a/composer.json b/composer.json index 817097e..3c59615 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "./vendor/bin/phpunit --testdox --display-warnings --colors=always" ], "stan": [ - "./vendor/bin/phpstan analyse --memory-limit=2g" + "./vendor/bin/phpstan analyse --memory-limit=2g --error-format=table" ] }, "script-descriptions": { diff --git a/docs/Models/Components/WorkspaceSchema.md b/docs/Models/Components/WorkspaceSchema.md index 0f70f48..bfd801a 100644 --- a/docs/Models/Components/WorkspaceSchema.md +++ b/docs/Models/Components/WorkspaceSchema.md @@ -31,7 +31,6 @@ | `stripeId` | *string* | :heavy_check_mark: | The Stripe ID of the workspace. | | `paymentFailedAt` | *string* | :heavy_check_mark: | The date and time when the payment failed for the workspace. | | `stripeConnectId` | *string* | :heavy_check_mark: | [BETA – Dub Conversions]: The Stripe Connect ID of the workspace. | -| `referralLinkId` | *string* | :heavy_check_mark: | The ID of the referral link of the workspace. | | `flags` | array | :heavy_minus_sign: | The feature flags of the workspace, indicating which features are enabled. | | `publishableKey` | *string* | :heavy_check_mark: | The publishable key of the workspace. | | `bankAccountName` | *string* | :heavy_check_mark: | [BETA – Dub Partners]: The name of the connected bank account. | diff --git a/src/Analytics.php b/src/Analytics.php index ce22133..be59b2d 100644 --- a/src/Analytics.php +++ b/src/Analytics.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -59,19 +60,35 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\RetrieveAnalyticsRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('retrieveAnalytics', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\AnalyticsCount|array<\Dub\Models\Components\AnalyticsTimeseries>|array<\Dub\Models\Components\AnalyticsContinents>|array<\Dub\Models\Components\AnalyticsCountries>|array<\Dub\Models\Components\AnalyticsCities>|array<\Dub\Models\Components\AnalyticsDevices>|array<\Dub\Models\Components\AnalyticsBrowsers>|array<\Dub\Models\Components\AnalyticsOS>|array<\Dub\Models\Components\AnalyticsTriggers>|array<\Dub\Models\Components\AnalyticsReferers>|array<\Dub\Models\Components\AnalyticsRefererUrls>|array<\Dub\Models\Components\AnalyticsTopLinks>|array<\Dub\Models\Components\AnalyticsTopUrls>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +104,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +115,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +126,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +137,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +148,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +159,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +170,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +181,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +192,8 @@ public function retrieve(?Operations\RetrieveAnalyticsRequest $request = null): } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Customers.php b/src/Customers.php index 30aeb37..4d55040 100644 --- a/src/Customers.php +++ b/src/Customers.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -59,14 +60,31 @@ public function list(): Operations\GetCustomersResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getCustomers', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Operations\ResponseBody>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -82,6 +100,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -91,6 +111,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -100,6 +122,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -109,6 +133,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -118,6 +144,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -127,6 +155,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -136,6 +166,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -145,6 +177,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -154,6 +188,8 @@ public function list(): Operations\GetCustomersResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -190,14 +226,31 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('createCustomer', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 201) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\CreateCustomerResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -213,6 +266,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -222,6 +277,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -231,6 +288,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -240,6 +299,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -249,6 +310,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -258,6 +321,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -267,6 +332,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -276,6 +343,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -285,6 +354,8 @@ public function create(?Operations\CreateCustomerRequestBody $request = null): O } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -320,14 +391,31 @@ public function get(string $id): Operations\GetCustomerResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getCustomer', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\GetCustomerResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -343,6 +431,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -352,6 +442,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -361,6 +453,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -370,6 +464,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -379,6 +475,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -388,6 +486,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -397,6 +497,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -406,6 +508,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -415,6 +519,8 @@ public function get(string $id): Operations\GetCustomerResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -456,14 +562,31 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('updateCustomer', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\UpdateCustomerResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -479,6 +602,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -488,6 +613,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -497,6 +624,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -506,6 +635,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -515,6 +646,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -524,6 +657,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -533,6 +668,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -542,6 +679,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -551,6 +690,8 @@ public function update(string $id, ?Operations\UpdateCustomerRequestBody $reques } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -586,14 +727,31 @@ public function delete(string $id): Operations\DeleteCustomerResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('DELETE', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('deleteCustomer', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\DeleteCustomerResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -609,6 +767,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -618,6 +778,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -627,6 +789,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -636,6 +800,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -645,6 +811,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -654,6 +822,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -663,6 +833,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -672,6 +844,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -681,6 +855,8 @@ public function delete(string $id): Operations\DeleteCustomerResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Domains.php b/src/Domains.php index 6b2472d..877149a 100644 --- a/src/Domains.php +++ b/src/Domains.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -64,14 +65,31 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('createDomain', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 201) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\DomainSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +105,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +116,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +127,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +138,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +149,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +160,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +171,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +182,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +193,8 @@ public function create(?Operations\CreateDomainRequestBody $request = null): Ope } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -199,19 +235,35 @@ private function listIndividual(?bool $archived = null, ?string $search = null, $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\ListDomainsRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('listDomains', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\DomainSchema>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -255,6 +307,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -264,6 +318,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -273,6 +329,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -282,6 +340,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -291,6 +351,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -300,6 +362,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -309,6 +373,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -318,6 +384,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -327,6 +395,8 @@ private function listIndividual(?bool $archived = null, ?string $search = null, } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -388,14 +458,31 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('updateDomain', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\DomainSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -411,6 +498,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -420,6 +509,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -429,6 +520,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -438,6 +531,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -447,6 +542,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -456,6 +553,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -465,6 +564,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -474,6 +575,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -483,6 +586,8 @@ public function update(string $slug, ?Operations\UpdateDomainRequestBody $reques } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -518,14 +623,31 @@ public function delete(string $slug): Operations\DeleteDomainResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('DELETE', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('deleteDomain', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\DeleteDomainResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -541,6 +663,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -550,6 +674,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -559,6 +685,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -568,6 +696,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -577,6 +707,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -586,6 +718,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -595,6 +729,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -604,6 +740,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -613,6 +751,8 @@ public function delete(string $slug): Operations\DeleteDomainResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Dub.php b/src/Dub.php index 63d25ea..44c9a59 100644 --- a/src/Dub.php +++ b/src/Dub.php @@ -67,5 +67,7 @@ public function __construct( $this->embedTokens = new EmbedTokens($this->sdkConfiguration); $this->qrCodes = new QRCodes($this->sdkConfiguration); $this->metatags = new Metatags($this->sdkConfiguration); + $this->sdkConfiguration->client = $this->sdkConfiguration->initHooks($this->sdkConfiguration->client); + } } \ No newline at end of file diff --git a/src/DubBuilder.php b/src/DubBuilder.php index 8368334..a8cbc2c 100644 --- a/src/DubBuilder.php +++ b/src/DubBuilder.php @@ -26,7 +26,7 @@ public function __construct( */ public function setClient(\GuzzleHttp\ClientInterface $client): DubBuilder { - $this->sdkConfig->defaultClient = $client; + $this->sdkConfig->client = $client; return $this; } @@ -95,16 +95,13 @@ public function setServerIndex(int $serverIdx): DubBuilder */ public function build(): Dub { - if ($this->sdkConfig->defaultClient === null) { - $this->sdkConfig->defaultClient = new \GuzzleHttp\Client([ + if ($this->sdkConfig->client === null) { + $this->sdkConfig->client = new \GuzzleHttp\Client([ 'timeout' => 60, ]); } if ($this->sdkConfig->hasSecurity()) { - $this->sdkConfig->securityClient = Utils\Utils::configureSecurityClient($this->sdkConfig->defaultClient, $this->sdkConfig->getSecurity()); - } - if ($this->sdkConfig->securityClient === null) { - $this->sdkConfig->securityClient = $this->sdkConfig->defaultClient; + $this->sdkConfig->client = Utils\Utils::configureSecurityClient($this->sdkConfig->client, $this->sdkConfig->getSecurity()); } return new Dub($this->sdkConfig); diff --git a/src/EmbedTokens.php b/src/EmbedTokens.php index 52db32a..cfffba0 100644 --- a/src/EmbedTokens.php +++ b/src/EmbedTokens.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -64,14 +65,31 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('createEmbedToken', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 201) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\CreateEmbedTokenResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +105,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +116,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +127,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +138,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +149,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +160,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +171,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +182,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +193,8 @@ public function create(?Operations\CreateEmbedTokenRequestBody $request = null): } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Events.php b/src/Events.php index 0706650..a394d20 100644 --- a/src/Events.php +++ b/src/Events.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -59,19 +60,35 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\ListEventsRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('listEvents', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\ClickEvent>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +104,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +115,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +126,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +137,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +148,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +159,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +170,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +181,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +192,8 @@ public function list(?Operations\ListEventsRequest $request = null): Operations\ } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Hooks/AfterErrorContext.php b/src/Hooks/AfterErrorContext.php new file mode 100644 index 0000000..f3dba86 --- /dev/null +++ b/src/Hooks/AfterErrorContext.php @@ -0,0 +1,18 @@ +operationID, $hookCtx->oauth2Scopes, $hookCtx->securitySource); + } +} diff --git a/src/Hooks/AfterErrorHook.php b/src/Hooks/AfterErrorHook.php new file mode 100644 index 0000000..c186d19 --- /dev/null +++ b/src/Hooks/AfterErrorHook.php @@ -0,0 +1,17 @@ +operationID, $hookCtx->oauth2Scopes, $hookCtx->securitySource); + } +} diff --git a/src/Hooks/AfterSuccessHook.php b/src/Hooks/AfterSuccessHook.php new file mode 100644 index 0000000..ba5fe4a --- /dev/null +++ b/src/Hooks/AfterSuccessHook.php @@ -0,0 +1,17 @@ +operationID, $hookCtx->oauth2Scopes, $hookCtx->securitySource); + } +} diff --git a/src/Hooks/BeforeRequestHook.php b/src/Hooks/BeforeRequestHook.php new file mode 100644 index 0000000..63c62d1 --- /dev/null +++ b/src/Hooks/BeforeRequestHook.php @@ -0,0 +1,17 @@ +response = $response; + $this->e = $e; + } +} diff --git a/src/Hooks/FailEarlyException.php b/src/Hooks/FailEarlyException.php new file mode 100644 index 0000000..6a505f2 --- /dev/null +++ b/src/Hooks/FailEarlyException.php @@ -0,0 +1,14 @@ + $oauth2Scopes; + */ + public ?array $oauth2Scopes; + /** + * @var ?\Closure(): ?mixed $securitySource + */ + public ?\Closure $securitySource; + + /** + * @param string $operationID + * @param ?array $oauth2Scopes + * @param ?\Closure(): ?mixed $securitySource + */ + public function __construct(string $operationID, ?array $oauth2Scopes, ?\Closure $securitySource) + { + $this->operationID = $operationID; + $this->oauth2Scopes = $oauth2Scopes; + $this->securitySource = $securitySource; + } +} diff --git a/src/Hooks/HookRegistration.php b/src/Hooks/HookRegistration.php new file mode 100644 index 0000000..4292357 --- /dev/null +++ b/src/Hooks/HookRegistration.php @@ -0,0 +1,28 @@ +registerSDKInitHook($myHook); + // $hooks->registerBeforeRequestHook($myHook); + // $hooks->registerAfterSuccessHook($myHook); + // $hooks->registerAfterErrorHook($myHook); + } +} diff --git a/src/Hooks/Hooks.php b/src/Hooks/Hooks.php new file mode 100644 index 0000000..cb0d55f --- /dev/null +++ b/src/Hooks/Hooks.php @@ -0,0 +1,20 @@ + $sdkInitHooks + */ + private array $sdkInitHooks = []; + /** + * @var array $beforeRequestHooks + */ + private array $beforeRequestHooks = []; + /** + * @var array $afterSuccessHooks + */ + private array $afterSuccessHooks = []; + /** + * @var array $afterErrorHooks + */ + private array $afterErrorHooks = []; + + public function __construct() + { + HookRegistration::initHooks($this); + } + + public function registerSDKInitHook(SDKInitHook $hook): void + { + $this->sdkInitHooks[] = $hook; + } + + public function registerBeforeRequestHook(BeforeRequestHook $hook): void + { + $this->beforeRequestHooks[] = $hook; + } + + public function registerAfterSuccessHook(AfterSuccessHook $hook): void + { + $this->afterSuccessHooks[] = $hook; + } + + public function registerAfterErrorHook(AfterErrorHook $hook): void + { + $this->afterErrorHooks[] = $hook; + } + + public function sdkInit(string $baseUrl, \GuzzleHttp\ClientInterface $client): SDKRequestContext + { + $rc = new SDKRequestContext($baseUrl, $client); + foreach ($this->sdkInitHooks as $hook) { + try { + $rc = $hook->sdkInit($rc->url, $rc->client); + } catch (\Exception $e) { + throw new \Exception('An error occurred while calling SDKInit hook.', $e->getCode(), $e); + } + + } + + return $rc; + } + + public function beforeRequest(BeforeRequestContext $context, RequestInterface $request): RequestInterface + { + foreach ($this->beforeRequestHooks as $hook) { + try { + $request = $hook->beforeRequest($context, $request); + } catch (\Exception $e) { + throw new \Exception('An error occurred while calling BeforeRequest hook.', $e->getCode(), $e); + } + } + + return $request; + } + + public function afterSuccess(AfterSuccessContext $context, ResponseInterface $response): ResponseInterface + { + foreach ($this->afterSuccessHooks as $hook) { + try { + $response = $hook->afterSuccess($context, $response); + } catch (\Exception $e) { + throw new \Exception('An error occurred while calling AfterSuccess hook.', $e->getCode(), $e); + } + } + + return $response; + } + + public function afterError(AfterErrorContext $context, ?ResponseInterface $response, ?\Throwable $exception): ResponseInterface + { + $errorContext = new ErrorResponseContext($response, $exception); + foreach ($this->afterErrorHooks as $hook) { + try { + $errorContext = $hook->afterError($context, $errorContext->response, $errorContext->e); + } catch (FailEarlyException $e) { + throw $e; + } catch (\Exception $e) { + throw new \Exception('An error occurred while calling AfterError hook.', $e->getCode(), $e); + } + } + if ($errorContext->e !== null) { + throw $errorContext->e; + } else { + return $errorContext->response; + } + } +} diff --git a/src/Hooks/SDKInitHook.php b/src/Hooks/SDKInitHook.php new file mode 100644 index 0000000..5c33430 --- /dev/null +++ b/src/Hooks/SDKInitHook.php @@ -0,0 +1,15 @@ +url = $url; + $this->client = $client; + } +} diff --git a/src/Links.php b/src/Links.php index 26b15d4..d63870e 100644 --- a/src/Links.php +++ b/src/Links.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -64,14 +65,31 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('createLink', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\LinkSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +105,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +116,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +127,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +138,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +149,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +160,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +171,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +182,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +193,8 @@ public function create(?Operations\CreateLinkRequestBody $request = null): Opera } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -190,19 +226,35 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\GetLinksRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getLinks', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\LinkSchema>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -255,6 +307,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -264,6 +318,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -273,6 +329,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -282,6 +340,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -291,6 +351,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -300,6 +362,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -309,6 +373,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -318,6 +384,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -327,6 +395,8 @@ private function listIndividual(?Operations\GetLinksRequest $request = null): Op } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -375,19 +445,35 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\GetLinksCountRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getLinksCount', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'float', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -403,6 +489,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -412,6 +500,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -421,6 +511,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -430,6 +522,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -439,6 +533,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -448,6 +544,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -457,6 +555,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -466,6 +566,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -475,6 +577,8 @@ public function count(?Operations\GetLinksCountRequest $request = null): Operati } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -515,19 +619,35 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\GetLinkInfoRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getLinkInfo', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\LinkSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -543,6 +663,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -552,6 +674,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -561,6 +685,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -570,6 +696,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -579,6 +707,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -588,6 +718,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -597,6 +729,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -606,6 +740,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -615,6 +751,8 @@ public function get(?string $domain = null, ?string $key = null, ?string $linkId } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -656,14 +794,31 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('updateLink', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\LinkSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -679,6 +834,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -688,6 +845,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -697,6 +856,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -706,6 +867,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -715,6 +878,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -724,6 +889,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -733,6 +900,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -742,6 +911,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -751,6 +922,8 @@ public function update(string $linkId, ?Operations\UpdateLinkRequestBody $reques } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -786,14 +959,31 @@ public function delete(string $linkId): Operations\DeleteLinkResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('DELETE', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('deleteLink', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\DeleteLinkResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -809,6 +999,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -818,6 +1010,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -827,6 +1021,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -836,6 +1032,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -845,6 +1043,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -854,6 +1054,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -863,6 +1065,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -872,6 +1076,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -881,6 +1087,8 @@ public function delete(string $linkId): Operations\DeleteLinkResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -917,14 +1125,31 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('bulkCreateLinks', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\LinkSchema>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -940,6 +1165,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -949,6 +1176,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -958,6 +1187,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -967,6 +1198,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -976,6 +1209,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -985,6 +1220,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -994,6 +1231,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1003,6 +1242,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1012,6 +1253,8 @@ public function createMany(?array $request = null): Operations\BulkCreateLinksRe } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1048,14 +1291,31 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('bulkUpdateLinks', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\LinkSchema>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1071,6 +1331,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1080,6 +1342,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1089,6 +1353,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1098,6 +1364,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1107,6 +1375,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1116,6 +1386,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1125,6 +1397,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1134,6 +1408,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1143,6 +1419,8 @@ public function updateMany(?Operations\BulkUpdateLinksRequestBody $request = nul } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1177,19 +1455,35 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\BulkDeleteLinksRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('DELETE', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('bulkDeleteLinks', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\BulkDeleteLinksResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1205,6 +1499,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1214,6 +1510,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1223,6 +1521,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1232,6 +1532,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1241,6 +1543,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1250,6 +1554,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1259,6 +1565,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1268,6 +1576,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1277,6 +1587,8 @@ public function deleteMany(array $linkIds): Operations\BulkDeleteLinksResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1313,14 +1625,31 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PUT', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('upsertLink', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\LinkSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1336,6 +1665,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1345,6 +1676,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1354,6 +1687,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1363,6 +1698,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1372,6 +1709,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1381,6 +1720,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1390,6 +1731,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1399,6 +1742,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -1408,6 +1753,8 @@ public function upsert(?Operations\UpsertLinkRequestBody $request = null): Opera } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Metatags.php b/src/Metatags.php index cd7a3b5..171a0cb 100644 --- a/src/Metatags.php +++ b/src/Metatags.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -62,19 +63,35 @@ public function get(string $url): Operations\GetMetatagsResponse $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\GetMetatagsRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getMetatags', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode >= 400 && $statusCode < 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\GetMetatagsResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Models/Components/WorkspaceSchema.php b/src/Models/Components/WorkspaceSchema.php index 78e241a..865f2aa 100644 --- a/src/Models/Components/WorkspaceSchema.php +++ b/src/Models/Components/WorkspaceSchema.php @@ -181,14 +181,6 @@ class WorkspaceSchema #[\Speakeasy\Serializer\Annotation\SerializedName('aiLimit')] public float $aiLimit; - /** - * The ID of the referral link of the workspace. - * - * @var ?string $referralLinkId - */ - #[\Speakeasy\Serializer\Annotation\SerializedName('referralLinkId')] - public ?string $referralLinkId; - /** * Whether the workspace has conversion tracking enabled (d.to/conversions). * @@ -308,7 +300,6 @@ class WorkspaceSchema * @param ?string $stripeId * @param ?string $paymentFailedAt * @param ?string $stripeConnectId - * @param ?string $referralLinkId * @param ?array $flags * @param ?string $publishableKey * @param ?string $bankAccountName @@ -316,7 +307,7 @@ class WorkspaceSchema * @param ?string $routingNumber * @param ?string $logo */ - public function __construct(string $id, string $name, string $slug, Plan $plan, float $billingCycleStart, float $usage, float $usageLimit, float $linksUsage, float $linksLimit, float $salesUsage, float $salesLimit, float $domainsLimit, float $tagsLimit, float $usersLimit, float $aiUsage, float $aiLimit, bool $conversionEnabled, bool $dotLinkClaimed, string $createdAt, array $users, array $domains, bool $bankAccountVerified, ?string $inviteCode = null, ?string $stripeId = null, ?string $paymentFailedAt = null, ?string $stripeConnectId = null, ?string $referralLinkId = null, ?array $flags = null, ?string $publishableKey = null, ?string $bankAccountName = null, ?string $partialAccountNumber = null, ?string $routingNumber = null, ?string $logo = null) + public function __construct(string $id, string $name, string $slug, Plan $plan, float $billingCycleStart, float $usage, float $usageLimit, float $linksUsage, float $linksLimit, float $salesUsage, float $salesLimit, float $domainsLimit, float $tagsLimit, float $usersLimit, float $aiUsage, float $aiLimit, bool $conversionEnabled, bool $dotLinkClaimed, string $createdAt, array $users, array $domains, bool $bankAccountVerified, ?string $inviteCode = null, ?string $stripeId = null, ?string $paymentFailedAt = null, ?string $stripeConnectId = null, ?array $flags = null, ?string $publishableKey = null, ?string $bankAccountName = null, ?string $partialAccountNumber = null, ?string $routingNumber = null, ?string $logo = null) { $this->id = $id; $this->name = $name; @@ -344,7 +335,6 @@ public function __construct(string $id, string $name, string $slug, Plan $plan, $this->stripeId = $stripeId; $this->paymentFailedAt = $paymentFailedAt; $this->stripeConnectId = $stripeConnectId; - $this->referralLinkId = $referralLinkId; $this->flags = $flags; $this->publishableKey = $publishableKey; $this->bankAccountName = $bankAccountName; diff --git a/src/QRCodes.php b/src/QRCodes.php index eec1944..29b6c22 100644 --- a/src/QRCodes.php +++ b/src/QRCodes.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -59,19 +60,35 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR $options = ['http_errors' => false]; $qp = Utils\Utils::getQueryParams(Operations\GetQRCodeRequest::class, $request, $urlOverride); - - $options = array_merge_recursive($options, $qp); $options['headers']['Accept'] = 'image/png'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getQRCode', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options['query'] = Utils\QueryParameters::standardizeQueryParams($httpRequest, $qp); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'image/png')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $obj = $httpResponse->getBody()->getContents(); return new Operations\GetQRCodeResponse( @@ -84,6 +101,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -93,6 +112,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -102,6 +123,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -111,6 +134,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -120,6 +145,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -129,6 +156,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -138,6 +167,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -147,6 +178,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -156,6 +189,8 @@ public function get(Operations\GetQRCodeRequest $request): Operations\GetQRCodeR } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/SDKConfiguration.php b/src/SDKConfiguration.php index e2a7674..1526b7c 100644 --- a/src/SDKConfiguration.php +++ b/src/SDKConfiguration.php @@ -8,17 +8,16 @@ namespace Dub; + class SDKConfiguration { - public ?\GuzzleHttp\ClientInterface $defaultClient = null; - - public ?\GuzzleHttp\ClientInterface $securityClient = null; + public ?\GuzzleHttp\ClientInterface $client = null; + public Hooks\SDKHooks $hooks; public ?Models\Components\Security $security = null; /** @var pure-Closure(): string */ public ?\Closure $securitySource = null; - public string $serverUrl = ''; public int $serverIndex = 0; @@ -27,11 +26,16 @@ class SDKConfiguration public string $openapiDocVersion = '0.0.1'; - public string $sdkVersion = '0.11.4'; + public string $sdkVersion = '0.11.5'; + + public string $genVersion = '2.472.1'; - public string $genVersion = '2.467.4'; + public string $userAgent = 'speakeasy-sdk/php 0.11.5 2.472.1 0.0.1 dub/dub-php'; - public string $userAgent = 'speakeasy-sdk/php 0.11.4 2.467.4 0.0.1 dub/dub-php'; + public function __construct() + { + $this->hooks = new Hooks\SDKHooks(); + } public function getServerUrl(): string { @@ -80,4 +84,23 @@ public function getServerDetails(): Utils\ServerDetails } -} \ No newline at end of file + public function getTemplatedServerUrl(): string + { + if ($this->serverUrl) { + return Utils\Utils::templateUrl($this->serverUrl.trim('/'), []); + } + + return Utils\Utils::templateUrl($this->getServerUrl(), []); + } + + public function initHooks(\GuzzleHttp\ClientInterface $client): \GuzzleHttp\ClientInterface + { + $preHooksUrl = $this->getTemplatedServerUrl(); + $ret = $this->hooks->sdkInit($preHooksUrl, $client); + if ($preHooksUrl != $ret->url) { + $this->serverUrl = $ret->url; + } + + return $ret->client; + } +} diff --git a/src/Tags.php b/src/Tags.php index 4a370f0..1ffac20 100644 --- a/src/Tags.php +++ b/src/Tags.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -64,14 +65,31 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('createTag', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 201) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\TagSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +105,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +116,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +127,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +138,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +149,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +160,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +171,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +182,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +193,8 @@ public function create(?Operations\CreateTagRequestBody $request = null): Operat } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -190,14 +226,31 @@ public function list(): Operations\GetTagsResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getTags', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, 'array<\Dub\Models\Components\TagSchema>', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -213,6 +266,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -222,6 +277,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -231,6 +288,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -240,6 +299,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -249,6 +310,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -258,6 +321,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -267,6 +332,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -276,6 +343,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -285,6 +354,8 @@ public function list(): Operations\GetTagsResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -326,14 +397,31 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('updateTag', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\TagSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -349,6 +437,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -358,6 +448,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -367,6 +459,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -376,6 +470,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -385,6 +481,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -394,6 +492,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -403,6 +503,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -412,6 +514,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -421,6 +525,8 @@ public function update(string $id, ?Operations\UpdateTagRequestBody $requestBody } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -456,14 +562,31 @@ public function delete(string $id): Operations\DeleteTagResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('DELETE', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('deleteTag', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\DeleteTagResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -479,6 +602,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -488,6 +613,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -497,6 +624,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -506,6 +635,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -515,6 +646,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -524,6 +657,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -533,6 +668,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -542,6 +679,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -551,6 +690,8 @@ public function delete(string $id): Operations\DeleteTagResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Track.php b/src/Track.php index 4d14504..ab19419 100644 --- a/src/Track.php +++ b/src/Track.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -64,14 +65,31 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('trackLead', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\TrackLeadResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -87,6 +105,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -96,6 +116,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -105,6 +127,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -114,6 +138,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -123,6 +149,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -132,6 +160,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -141,6 +171,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -150,6 +182,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -159,6 +193,8 @@ public function lead(?Operations\TrackLeadRequestBody $request = null): Operatio } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -195,14 +231,31 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('trackSale', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\TrackSaleResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -218,6 +271,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -227,6 +282,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -236,6 +293,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -245,6 +304,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -254,6 +315,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -263,6 +326,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -272,6 +337,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -281,6 +348,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -290,6 +359,8 @@ public function sale(?Operations\TrackSaleRequestBody $request = null): Operatio } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -328,14 +399,31 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('POST', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('trackCustomer', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Operations\TrackCustomerResponseBody', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -351,6 +439,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -360,6 +450,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -369,6 +461,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -378,6 +472,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -387,6 +483,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -396,6 +494,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -405,6 +505,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -414,6 +516,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -423,6 +527,8 @@ public function customer(?Operations\TrackCustomerRequestBody $request = null): } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); diff --git a/src/Utils/QueryParameters.php b/src/Utils/QueryParameters.php index 7a1154b..80f52fb 100644 --- a/src/Utils/QueryParameters.php +++ b/src/Utils/QueryParameters.php @@ -8,6 +8,7 @@ namespace Dub\Utils; +use Psr\Http\Message\RequestInterface; use ReflectionProperty; class QueryParameters @@ -17,9 +18,9 @@ class QueryParameters * @param mixed $queryParams * @param array $urlOverride * @param array>>|null $globals - * @return ?string + * @return array */ - public function parseQueryParams(string $type, mixed $queryParams, array $urlOverride, ?array $globals = null): ?string + public function parseQueryParams(string $type, mixed $queryParams, array $urlOverride, ?array $globals = null): array { $parts = []; @@ -58,9 +59,8 @@ public function parseQueryParams(string $type, mixed $queryParams, array $urlOve } $parts = array_merge($parts, $urlOverride); - $result = self::recursivelyBuildQueryString($parts); - return empty($parts) ? null : $result; + return $parts; } /** @@ -286,4 +286,21 @@ private function parseQueryParamsMetadata(ReflectionProperty $property): ?Params return $metadata; } + + /** + * @param RequestInterface $httpRequest + * @param array $queryParams + * @return string + */ + public static function standardizeQueryParams(RequestInterface $httpRequest, array $queryParams): string + { + $uri = $httpRequest->getUri(); + $query = $uri->getQuery(); + $requestQueryParams = Utils::proper_parse_str($query); + + $allParams = array_merge($queryParams, $requestQueryParams); + $uri = $uri->withQuery(QueryParameters::recursivelyBuildQueryString($allParams)); + + return $uri->getQuery(); + } } diff --git a/src/Utils/SecurityClient.php b/src/Utils/SecurityClient.php index 32fe0f3..74b65e1 100644 --- a/src/Utils/SecurityClient.php +++ b/src/Utils/SecurityClient.php @@ -92,7 +92,7 @@ private function addClientOptions(array $options): array } if (count($this->clientOptions['headers']) > 0) { - $options['headers'] = array_merge_recursive($options['headers'], $this->clientOptions['headers']); + $options['headers'] = array_merge($this->clientOptions['headers'], $options['headers']); } if (count($this->clientOptions['query']) > 0) { diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index 32ea4ba..b5dfc14 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -9,6 +9,7 @@ namespace Dub\Utils; use GuzzleHttp\ClientInterface; +use Psr\Http\Message\RequestInterface; class Utils { @@ -159,9 +160,7 @@ public static function getQueryParams(string $type, mixed $queryParams, ?string return []; } - return [ - 'query' => $query, - ]; + return $query; } /** @@ -193,6 +192,10 @@ public static function proper_parse_str($str) { $arr = []; + if (empty($str)) { + return $arr; + } + $pairs = explode('&', $str); foreach ($pairs as $i) { @@ -214,6 +217,40 @@ public static function proper_parse_str($str) return $arr; } + + /** + * convertHeadersToOptions will convert the headers from a request to options for a client. + * + * @param RequestInterface $request + * @param array $options + * @return array + */ + public static function convertHeadersToOptions(RequestInterface $request, array $options): array + { + $headers = $request->getHeaders(); + foreach ($request->getHeaders() as $name => $values) { + $options['headers'][$name] = $values; + } + + return $options; + } + + /** + * removeHeaders will remove all headers from a request + * + * @param RequestInterface $request + * @return RequestInterface + */ + public static function removeHeaders(RequestInterface $request): RequestInterface + { + $headers = $request->getHeaders(); + foreach ($request->getHeaders() as $name => $values) { + $request = $request->withoutHeader($name); + } + + return $request; + } + } function removePrefix(string $text, string $prefix): string diff --git a/src/Workspaces.php b/src/Workspaces.php index 88e4ef0..1656a6d 100644 --- a/src/Workspaces.php +++ b/src/Workspaces.php @@ -8,6 +8,7 @@ namespace Dub; +use Dub\Hooks\HookContext; use Dub\Models\Operations; use Speakeasy\Serializer\DeserializationContext; @@ -63,14 +64,31 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('GET', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('getWorkspace', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\WorkspaceSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -86,6 +104,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -95,6 +115,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -104,6 +126,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -113,6 +137,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -122,6 +148,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -131,6 +159,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -140,6 +170,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -149,6 +181,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -158,6 +192,8 @@ public function get(string $idOrSlug): Operations\GetWorkspaceResponse } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -199,14 +235,31 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody $options['headers']['Accept'] = 'application/json'; $options['headers']['user-agent'] = $this->sdkConfiguration->userAgent; $httpRequest = new \GuzzleHttp\Psr7\Request('PATCH', $url); - - - $httpResponse = $this->sdkConfiguration->securityClient->send($httpRequest, $options); + $hookContext = new HookContext('updateWorkspace', null, $this->sdkConfiguration->securitySource); + $httpRequest = $this->sdkConfiguration->hooks->beforeRequest(new Hooks\BeforeRequestContext($hookContext), $httpRequest); + $options = Utils\Utils::convertHeadersToOptions($httpRequest, $options); + $httpRequest = Utils\Utils::removeHeaders($httpRequest); + try { + $httpResponse = $this->sdkConfiguration->client->send($httpRequest, $options); + } catch (\GuzzleHttp\Exception\GuzzleException $error) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), null, $error); + if ($res !== null) { + $httpResponse = $res; + } + } $contentType = $httpResponse->getHeader('Content-Type')[0] ?? ''; $statusCode = $httpResponse->getStatusCode(); + if ($statusCode == 400 || $statusCode == 401 || $statusCode == 403 || $statusCode == 404 || $statusCode == 409 || $statusCode == 410 || $statusCode == 422 || $statusCode == 429 || $statusCode >= 400 && $statusCode < 500 || $statusCode == 500 || $statusCode >= 500 && $statusCode < 600) { + $res = $this->sdkConfiguration->hooks->afterError(new Hooks\AfterErrorContext($hookContext), $httpResponse, null); + if ($res !== null) { + $httpResponse = $res; + } + } if ($statusCode == 200) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Components\WorkspaceSchema', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -222,6 +275,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 400) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\BadRequest', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -231,6 +286,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 401) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Unauthorized', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -240,6 +297,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 403) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Forbidden', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -249,6 +308,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 404) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\NotFound', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -258,6 +319,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 409) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\Conflict', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -267,6 +330,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 410) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InviteExpired', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -276,6 +341,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 422) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\UnprocessableEntity', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -285,6 +352,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 429) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\RateLimitExceeded', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true)); @@ -294,6 +363,8 @@ public function update(string $idOrSlug, ?Operations\UpdateWorkspaceRequestBody } } elseif ($statusCode == 500) { if (Utils\Utils::matchContentType($contentType, 'application/json')) { + $httpResponse = $this->sdkConfiguration->hooks->afterSuccess(new Hooks\AfterSuccessContext($hookContext), $httpResponse); + $serializer = Utils\JSON::createSerializer(); $responseData = (string) $httpResponse->getBody(); $obj = $serializer->deserialize($responseData, '\Dub\Models\Errors\InternalServerError', 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true));