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\Expenses\Endpoint;
12:
13: class UpdateExpense 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: * Update an expense. Admin and bookkeeper have access to any expense, and regular users can only access their own.
20: */
21: public function __construct(string $expenseId, \NxSys\Library\Clients\Brex\API\Expenses\Model\UpdateExpenseRequest $requestBody)
22: {
23: $this->expense_id = $expenseId;
24: $this->body = $requestBody;
25: }
26:
27: public function getMethod(): string
28: {
29: return 'PUT';
30: }
31:
32: public function getUri(): string
33: {
34: return str_replace(['{expense_id}'], [$this->expense_id], '/v1/expenses/card/{expense_id}');
35: }
36:
37: public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
38: {
39: if ($this->body instanceof \NxSys\Library\Clients\Brex\API\Expenses\Model\UpdateExpenseRequest) {
40: return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')];
41: }
42:
43: return [[], null];
44: }
45:
46: public function getExtraHeaders(): array
47: {
48: return ['Accept' => ['application/json']];
49: }
50:
51: /**
52: * {@inheritdoc}
53: *
54: * @return \NxSys\Library\Clients\Brex\API\Expenses\Model\Expense|null
55: *
56: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseBadRequestException
57: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseUnauthorizedException
58: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseForbiddenException
59: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseNotFoundException
60: */
61: protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
62: {
63: $status = $response->getStatusCode();
64: $body = (string) $response->getBody();
65: if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) {
66: return $serializer->deserialize($body, 'NxSys\\Library\\Clients\\Brex\\API\\Expenses\\Model\\Expense', 'json');
67: }
68: if (400 === $status) {
69: throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseBadRequestException($response);
70: }
71: if (401 === $status) {
72: throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseUnauthorizedException($response);
73: }
74: if (403 === $status) {
75: throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseForbiddenException($response);
76: }
77: if (404 === $status) {
78: throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\UpdateExpenseNotFoundException($response);
79: }
80: }
81:
82: public function getAuthenticationScopes(): array
83: {
84: return ['oAuth2ClientCredentials', 'OAuth2'];
85: }
86: }
87: