-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListPatGrantRequests.php
More file actions
136 lines (116 loc) · 7.04 KB
/
ListPatGrantRequests.php
File metadata and controls
136 lines (116 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
declare(strict_types=1);
namespace ApiClients\Client\GitHub\Internal\Operation\Orgs;
use ApiClients\Client\GitHub\Error as ErrorSchemas;
use ApiClients\Client\GitHub\Internal;
use ApiClients\Client\GitHub\Schema;
use cebe\openapi\Reader;
use League\OpenAPIValidation\Schema\SchemaValidator;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use RingCentral\Psr7\Request;
use RuntimeException;
use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;
use Throwable;
use function explode;
use function json_decode;
use function str_replace;
final class ListPatGrantRequests
{
public const OPERATION_ID = 'orgs/list-pat-grant-requests';
public const OPERATION_MATCH = 'GET /orgs/{org}/personal-access-token-requests';
/**The organization name. The name is not case sensitive. **/
private string $org;
/**A list of owner usernames to use to filter the results. **/
private array $owner;
/**The name of the repository to use to filter the results. **/
private string $repository;
/**The permission to use to filter the results. **/
private string $permission;
/**Only show fine-grained personal access tokens used before the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. **/
private string $lastUsedBefore;
/**Only show fine-grained personal access tokens used after the given time. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`. **/
private string $lastUsedAfter;
/**The ID of the token **/
private array $tokenId;
/**The number of results per page (max 100). For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." **/
private int $perPage;
/**The page number of the results to fetch. For more information, see "[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api)." **/
private int $page;
/**The property by which to sort the results. **/
private string $sort;
/**The direction to sort the results by. **/
private string $direction;
public function __construct(private readonly SchemaValidator $responseSchemaValidator, private readonly Internal\Hydrator\Operation\Orgs\Org\PersonalAccessTokenRequests $hydrator, string $org, array $owner, string $repository, string $permission, string $lastUsedBefore, string $lastUsedAfter, array $tokenId, int $perPage = 30, int $page = 1, string $sort = 'created_at', string $direction = 'desc')
{
$this->org = $org;
$this->owner = $owner;
$this->repository = $repository;
$this->permission = $permission;
$this->lastUsedBefore = $lastUsedBefore;
$this->lastUsedAfter = $lastUsedAfter;
$this->tokenId = $tokenId;
$this->perPage = $perPage;
$this->page = $page;
$this->sort = $sort;
$this->direction = $direction;
}
public function createRequest(): RequestInterface
{
return new Request('GET', str_replace(['{org}', '{owner}', '{repository}', '{permission}', '{last_used_before}', '{last_used_after}', '{token_id}', '{per_page}', '{page}', '{sort}', '{direction}'], [$this->org, $this->owner, $this->repository, $this->permission, $this->lastUsedBefore, $this->lastUsedAfter, $this->tokenId, $this->perPage, $this->page, $this->sort, $this->direction], '/orgs/{org}/personal-access-token-requests' . '?owner={owner}&repository={repository}&permission={permission}&last_used_before={last_used_before}&last_used_after={last_used_after}&token_id={token_id}&per_page={per_page}&page={page}&sort={sort}&direction={direction}'));
}
/** @return Observable<Schema\OrganizationProgrammaticAccessGrantRequest> */
public function createResponse(ResponseInterface $response): Observable
{
$code = $response->getStatusCode();
[$contentType] = explode(';', $response->getHeaderLine('Content-Type'));
switch ($contentType) {
case 'application/json':
$body = json_decode($response->getBody()->getContents(), true);
switch ($code) {
/**
* Internal Error
**/
case 500:
$this->responseSchemaValidator->validate($body, Reader::readFromJson(Schema\BasicError::SCHEMA_JSON, \cebe\openapi\spec\Schema::class));
throw new ErrorSchemas\BasicError(500, $this->hydrator->hydrateObject(Schema\BasicError::class, $body));
/**
* Validation failed, or the endpoint has been spammed.
**/
case 422:
$this->responseSchemaValidator->validate($body, Reader::readFromJson(Schema\ValidationError::SCHEMA_JSON, \cebe\openapi\spec\Schema::class));
throw new ErrorSchemas\ValidationError(422, $this->hydrator->hydrateObject(Schema\ValidationError::class, $body));
/**
* Resource not found
**/
case 404:
$this->responseSchemaValidator->validate($body, Reader::readFromJson(Schema\BasicError::SCHEMA_JSON, \cebe\openapi\spec\Schema::class));
throw new ErrorSchemas\BasicError(404, $this->hydrator->hydrateObject(Schema\BasicError::class, $body));
/**
* Forbidden
**/
case 403:
$this->responseSchemaValidator->validate($body, Reader::readFromJson(Schema\BasicError::SCHEMA_JSON, \cebe\openapi\spec\Schema::class));
throw new ErrorSchemas\BasicError(403, $this->hydrator->hydrateObject(Schema\BasicError::class, $body));
/**
* Response
**/
case 200:
return Observable::fromArray($body, new ImmediateScheduler())->map(function (array $body): Schema\OrganizationProgrammaticAccessGrantRequest {
$error = new RuntimeException();
try {
$this->responseSchemaValidator->validate($body, Reader::readFromJson(Schema\OrganizationProgrammaticAccessGrantRequest::SCHEMA_JSON, '\\cebe\\openapi\\spec\\Schema'));
return $this->hydrator->hydrateObject(Schema\OrganizationProgrammaticAccessGrantRequest::class, $body);
} catch (Throwable $error) {
goto items_application_json_two_hundred_aaaaa;
}
items_application_json_two_hundred_aaaaa:
throw $error;
});
}
break;
}
throw new RuntimeException('Unable to find matching response code and content type');
}
}