1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | namespace NxSys\Library\Clients\Brex\API\Webhooks\Endpoint; |
12: | |
13: | class UpdateSubscription 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: | protected $id; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | public function __construct(string $id, \NxSys\Library\Clients\Brex\API\Webhooks\Model\UpdateWebhookSubscriptionRequest $requestBody) |
23: | { |
24: | $this->id = $id; |
25: | $this->body = $requestBody; |
26: | } |
27: | |
28: | public function getMethod(): string |
29: | { |
30: | return 'PUT'; |
31: | } |
32: | |
33: | public function getUri(): string |
34: | { |
35: | return str_replace(['{id}'], [$this->id], '/v1/webhooks/{id}'); |
36: | } |
37: | |
38: | public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array |
39: | { |
40: | if ($this->body instanceof \NxSys\Library\Clients\Brex\API\Webhooks\Model\UpdateWebhookSubscriptionRequest) { |
41: | return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')]; |
42: | } |
43: | |
44: | return [[], null]; |
45: | } |
46: | |
47: | public function getExtraHeaders(): array |
48: | { |
49: | return ['Accept' => ['application/json']]; |
50: | } |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) |
63: | { |
64: | $status = $response->getStatusCode(); |
65: | $body = (string) $response->getBody(); |
66: | if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { |
67: | return $serializer->deserialize($body, 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\WebhookSubscription', 'json'); |
68: | } |
69: | if (400 === $status) { |
70: | throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\UpdateSubscriptionBadRequestException($response); |
71: | } |
72: | if (401 === $status) { |
73: | throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\UpdateSubscriptionUnauthorizedException($response); |
74: | } |
75: | if (403 === $status) { |
76: | throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\UpdateSubscriptionForbiddenException($response); |
77: | } |
78: | if (500 === $status) { |
79: | throw new \NxSys\Library\Clients\Brex\API\Webhooks\Exception\UpdateSubscriptionInternalServerErrorException($response); |
80: | } |
81: | } |
82: | |
83: | public function getAuthenticationScopes(): array |
84: | { |
85: | return ['OAuth2']; |
86: | } |
87: | } |
88: | |