1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | namespace NxSys\Library\Clients\Brex\API\Team\Endpoint; |
12: | |
13: | class CreateUser extends \NxSys\Library\Clients\Brex\API\Team\Runtime\Client\BaseEndpoint implements \NxSys\Library\Clients\Brex\API\Team\Runtime\Client\Endpoint |
14: | { |
15: | use \NxSys\Library\Clients\Brex\API\Team\Runtime\Client\EndpointTrait; |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | public function __construct(\NxSys\Library\Clients\Brex\API\Team\Model\CreateUserRequest $requestBody, array $headerParameters = []) |
28: | { |
29: | $this->body = $requestBody; |
30: | $this->headerParameters = $headerParameters; |
31: | } |
32: | |
33: | public function getMethod(): string |
34: | { |
35: | return 'POST'; |
36: | } |
37: | |
38: | public function getUri(): string |
39: | { |
40: | return '/v2/users'; |
41: | } |
42: | |
43: | public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array |
44: | { |
45: | if ($this->body instanceof \NxSys\Library\Clients\Brex\API\Team\Model\CreateUserRequest) { |
46: | return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')]; |
47: | } |
48: | |
49: | return [[], null]; |
50: | } |
51: | |
52: | public function getExtraHeaders(): array |
53: | { |
54: | return ['Accept' => ['application/json']]; |
55: | } |
56: | |
57: | protected function getHeadersOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver |
58: | { |
59: | $optionsResolver = parent::getHeadersOptionsResolver(); |
60: | $optionsResolver->setDefined(['Idempotency-Key']); |
61: | $optionsResolver->setRequired([]); |
62: | $optionsResolver->setDefaults([]); |
63: | $optionsResolver->addAllowedTypes('Idempotency-Key', ['string', 'null']); |
64: | |
65: | return $optionsResolver; |
66: | } |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) |
78: | { |
79: | $status = $response->getStatusCode(); |
80: | $body = (string) $response->getBody(); |
81: | if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { |
82: | return $serializer->deserialize($body, 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\UserResponse', 'json'); |
83: | } |
84: | if (400 === $status) { |
85: | throw new \NxSys\Library\Clients\Brex\API\Team\Exception\CreateUserBadRequestException($response); |
86: | } |
87: | if (401 === $status) { |
88: | throw new \NxSys\Library\Clients\Brex\API\Team\Exception\CreateUserUnauthorizedException($response); |
89: | } |
90: | if (403 === $status) { |
91: | throw new \NxSys\Library\Clients\Brex\API\Team\Exception\CreateUserForbiddenException($response); |
92: | } |
93: | } |
94: | |
95: | public function getAuthenticationScopes(): array |
96: | { |
97: | return ['OAuth2']; |
98: | } |
99: | } |
100: | |