1: <?php
2:
3: declare(strict_types=1);
4:
5: /*
6: * This file has been auto generated by Jane,
7: *
8: * Do no edit it directly.
9: */
10:
11: namespace NxSys\Library\Clients\Brex\API\Webhooks\Endpoint;
12:
13: class CreateSubscription extends \NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Client\BaseEndpoint implements \NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Client\Endpoint
14: {
15: use \NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Client\EndpointTrait;
16:
17: /**
18: * Register an endpoint to start receiving selected webhook events.
19: *
20: * @param array $headerParameters {
21: *
22: * @var string $Idempotency-Key
23: * }
24: */
25: public function __construct(\NxSys\Library\Clients\Brex\API\Webhooks\Model\CreateWebhookSubscriptionRequest $requestBody, array $headerParameters = [])
26: {
27: $this->body = $requestBody;
28: $this->headerParameters = $headerParameters;
29: }
30:
31: public function getMethod(): string
32: {
33: return 'POST';
34: }
35:
36: public function getUri(): string
37: {
38: return '/v1/webhooks';
39: }
40:
41: public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
42: {
43: if ($this->body instanceof \NxSys\Library\Clients\Brex\API\Webhooks\Model\CreateWebhookSubscriptionRequest) {
44: return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')];
45: }
46:
47: return [[], null];
48: }
49:
50: public function getExtraHeaders(): array
51: {
52: return ['Accept' => ['application/json']];
53: }
54:
55: protected function getHeadersOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
56: {
57: $optionsResolver = parent::getHeadersOptionsResolver();
58: $optionsResolver->setDefined(['Idempotency-Key']);
59: $optionsResolver->setRequired(['Idempotency-Key']);
60: $optionsResolver->setDefaults([]);
61: $optionsResolver->addAllowedTypes('Idempotency-Key', ['string']);
62:
63: return $optionsResolver;
64: }
65:
66: /**
67: * {@inheritdoc}
68: *
69: * @return \NxSys\Library\Clients\Brex\API\Webhooks\Model\WebhookSubscription|null
70: *
71: * @throws \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionBadRequestException
72: * @throws \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionUnauthorizedException
73: * @throws \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionForbiddenException
74: * @throws \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionInternalServerErrorException
75: */
76: protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
77: {
78: $status = $response->getStatusCode();
79: $body = (string) $response->getBody();
80: if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) {
81: return $serializer->deserialize($body, 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\WebhookSubscription', 'json');
82: }
83: if (400 === $status) {
84: throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionBadRequestException($response);
85: }
86: if (401 === $status) {
87: throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionUnauthorizedException($response);
88: }
89: if (403 === $status) {
90: throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionForbiddenException($response);
91: }
92: if (500 === $status) {
93: throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\CreateSubscriptionInternalServerErrorException($response);
94: }
95: }
96:
97: public function getAuthenticationScopes(): array
98: {
99: return ['OAuth2'];
100: }
101: }
102: