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