tgstation-server 6.12.3
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Tgstation.Server.Client.ApiClient Class Reference

More...

Inheritance diagram for Tgstation.Server.Client.ApiClient:
Inheritance graph
[legend]
Collaboration diagram for Tgstation.Server.Client.ApiClient:
Collaboration graph
[legend]

Public Member Functions

 ApiClient (IHttpClient httpClient, Uri url, ApiHeaders apiHeaders, ApiHeaders? tokenRefreshHeaders, bool authless)
 Initializes a new instance of the ApiClient class.
 
async ValueTask DisposeAsync ()
 
ValueTask< TResultCreate< TResult > (string route, CancellationToken cancellationToken)
 Run an HTTP PUT request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultRead< TResult > (string route, CancellationToken cancellationToken)
 Run an HTTP GET request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultUpdate< TResult > (string route, CancellationToken cancellationToken)
 Run an HTTP POST request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultUpdate< TBody, TResult > (string route, TBody body, CancellationToken cancellationToken)
 Run an HTTP POST request.
Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask Patch (string route, CancellationToken cancellationToken)
 Run an HTTP PATCH request.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask Update< TBody > (string route, TBody body, CancellationToken cancellationToken)
 Run an HTTP POST request.
Template Parameters
TBodyThe type to of the request body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask< TResultCreate< TBody, TResult > (string route, TBody body, CancellationToken cancellationToken)
 Run an HTTP PUT request.
Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask Delete (string route, CancellationToken cancellationToken)
 Run an HTTP DELETE request.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask< TResultCreate< TBody, TResult > (string route, TBody body, long instanceId, CancellationToken cancellationToken)
 Run an HTTP PUT request.
Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultRead< TResult > (string route, long instanceId, CancellationToken cancellationToken)
 Run an HTTP GET request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultUpdate< TBody, TResult > (string route, TBody body, long instanceId, CancellationToken cancellationToken)
 Run an HTTP POST request.
Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask Delete (string route, long instanceId, CancellationToken cancellationToken)
 Run an HTTP DELETE request.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask Delete< TBody > (string route, TBody body, long instanceId, CancellationToken cancellationToken)
 Run an HTTP DELETE request.
Template Parameters
TBodyThe type to of the request body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask< TResultDelete< TResult > (string route, long instanceId, CancellationToken cancellationToken)
 Run an HTTP DELETE request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultDelete< TBody, TResult > (string route, TBody body, long instanceId, CancellationToken cancellationToken)
 Run an HTTP DELETE request.
Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
ValueTask< TResultCreate< TResult > (string route, long instanceId, CancellationToken cancellationToken)
 Run an HTTP PUT request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
ValueTask< TResultPatch< TResult > (string route, long instanceId, CancellationToken cancellationToken)
 Run an HTTP PATCH request.
Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

 
void AddRequestLogger (IRequestLogger requestLogger)
 Adds a requestLogger to the request pipeline.
Parameters
requestLoggerThe IRequestLogger to add.

 
ValueTask< StreamDownload (FileTicketResponse ticket, CancellationToken cancellationToken)
 Downloads a file Stream for a given ticket .
Parameters
ticketThe FileTicketResponse to download.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the downloaded Stream.

 
async ValueTask Upload (FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken)
 Uploads a given uploadStream for a given ticket .
Parameters
ticketThe FileTicketResponse to download.
uploadStreamThe Stream to upload. null represents an empty file.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

 
async ValueTask< bool > RefreshToken (CancellationToken cancellationToken)
 Attempt to refresh the stored Bearer token in Headers.
 
async ValueTask< IAsyncDisposableCreateHubConnection< THubImplementation > (THubImplementation hubImplementation, IRetryPolicy? retryPolicy, Action< ILoggingBuilder >? loggingConfigureAction, CancellationToken cancellationToken)
 Subscribe to all job updates available to the IRestServerClient.
Template Parameters
THubImplementationThe Type of the hub being implemented.
Parameters
hubImplementationThe THubImplementation to use for proxying the methods of the hub connection.
retryPolicyThe optional IRetryPolicy to use for the backing connection. The default retry policy waits for 1, 2, 4, 8, and 16 seconds, then 30s repeatedly.
loggingConfigureActionThe optional Action<T1> used to configure a ILoggingBuilder.
cancellationTokenThe CancellationToken for the operation.
Returns
An IAsyncDisposable representing the lifetime of the subscription.

 

Protected Member Functions

virtual async ValueTask< TResultRunRequest< TResult > (string route, HttpContent? content, HttpMethod method, long? instanceId, bool tokenRefresh, CancellationToken cancellationToken)
 Main request method.
 

Properties

Uri Url [get]
 The Uri pointing the tgstation-server.
 
ApiHeaders Headers [get, set]
 The ApiHeaders the IApiClient uses.
 
TimeSpan Timeout [get, set]
 The request timeout.
 
- Properties inherited from Tgstation.Server.Client.IApiClient

Private Member Functions

ValueTask< TResult > TResult (route, new object(), HttpMethod.Put, null, false, cancellationToken)
 
ValueTask< TResult > TResult (route, null, HttpMethod.Get, null, false, cancellationToken)
 
ValueTask< TResult > TResult (route, new object(), HttpMethod.Post, null, false, cancellationToken)
 
ValueTask< TResult > TResult (route, new object(), HttpMethod.Put, instanceId, false, cancellationToken)
 
ValueTask< TResult > TResult (route, new object(), HttpPatch, instanceId, false, cancellationToken)
 
async ValueTask< HubConnection > WrapHubInitialConnectAuthRefresh (Func< ValueTask< HubConnection > > connectFunc, CancellationToken cancellationToken)
 Wrap a hub connection attempt via a connectFunc with proper token refreshing.
 
async ValueTask< TResultRunRequest< TBody, TResult > (string route, TBody? body, HttpMethod method, long? instanceId, bool tokenRefresh, CancellationToken cancellationToken)
 Main request method.
 
async ValueTask RunResultlessRequest< TBody > (string route, TBody? body, HttpMethod method, long? instanceId, bool tokenRefresh, CancellationToken cancellationToken)
 Main request method.
 
ValueTask RunRequest (string route, HttpMethod method, long? instanceId, bool tokenRefresh, CancellationToken cancellationToken)
 Main request method.
 

Static Private Member Functions

static void HandleBadResponse (HttpResponseMessage response, string json)
 Handle a bad HTTP response .
 

Private Attributes

readonly IHttpClient httpClient
 The IHttpClient for the ApiClient.
 
readonly List< IRequestLoggerrequestLoggers
 The IRequestLoggers used by the ApiClient.
 
readonly List< HubConnection > hubConnections
 List of HubConnections created by the ApiClient.
 
readonly? ApiHeaders tokenRefreshHeaders
 Backing field for Headers.
 
readonly SemaphoreSlim semaphoreSlim
 The SemaphoreSlim for TokenResponse refreshes.
 
readonly bool authless
 If the authentication header should be stripped from requests.
 
ApiHeaders headers
 Backing field for Headers.
 
bool disposed
 If the ApiClient is disposed.
 

Static Private Attributes

static readonly HttpMethod HttpPatch = new("PATCH")
 PATCH HttpMethod.
 
static readonly JsonSerializerSettings SerializerSettings
 The JsonSerializerSettings to use.
 

Detailed Description

Definition at line 34 of file ApiClient.cs.

Constructor & Destructor Documentation

◆ ApiClient()

Tgstation.Server.Client.ApiClient.ApiClient ( IHttpClient  httpClient,
Uri  url,
ApiHeaders  apiHeaders,
ApiHeaders tokenRefreshHeaders,
bool  authless 
)

Initializes a new instance of the ApiClient class.

Parameters
httpClientThe value of httpClient.
urlThe value of Url.
apiHeadersThe value of Headers.
tokenRefreshHeadersThe value of tokenRefreshHeaders.
authlessThe value of authless.

Definition at line 168 of file ApiClient.cs.

174 {
175 this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
176 Url = url ?? throw new ArgumentNullException(nameof(url));
177 headers = apiHeaders ?? throw new ArgumentNullException(nameof(apiHeaders));
178 this.tokenRefreshHeaders = tokenRefreshHeaders;
179 this.authless = authless;
180
181 requestLoggers = new List<IRequestLogger>();
182 hubConnections = new List<HubConnection>();
183 semaphoreSlim = new SemaphoreSlim(1);
184 }
readonly? ApiHeaders tokenRefreshHeaders
Backing field for Headers.
Definition ApiClient.cs:89
readonly IHttpClient httpClient
The IHttpClient for the ApiClient.
Definition ApiClient.cs:74
Uri Url
The Uri pointing the tgstation-server.
Definition ApiClient.cs:43
ApiHeaders headers
Backing field for Headers.
Definition ApiClient.cs:104
readonly List< IRequestLogger > requestLoggers
The IRequestLoggers used by the ApiClient.
Definition ApiClient.cs:79
readonly bool authless
If the authentication header should be stripped from requests.
Definition ApiClient.cs:99
readonly SemaphoreSlim semaphoreSlim
The SemaphoreSlim for TokenResponse refreshes.
Definition ApiClient.cs:94
readonly List< HubConnection > hubConnections
List of HubConnections created by the ApiClient.
Definition ApiClient.cs:84

References Tgstation.Server.Client.ApiClient.authless, Tgstation.Server.Client.ApiClient.headers, Tgstation.Server.Client.ApiClient.httpClient, Tgstation.Server.Client.ApiClient.hubConnections, Tgstation.Server.Client.ApiClient.requestLoggers, Tgstation.Server.Client.ApiClient.semaphoreSlim, Tgstation.Server.Client.ApiClient.tokenRefreshHeaders, and Tgstation.Server.Client.ApiClient.Url.

Member Function Documentation

◆ AddRequestLogger()

void Tgstation.Server.Client.ApiClient.AddRequestLogger ( IRequestLogger  requestLogger)

Adds a requestLogger to the request pipeline.

Parameters
requestLoggerThe IRequestLogger to add.

Implements Tgstation.Server.Client.IApiClient.

◆ Create< TBody, TResult >() [1/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Create< TBody, TResult > ( string  route,
TBody  body,
CancellationToken  cancellationToken 
)

Run an HTTP PUT request.

Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunRequest 
TBody :TBody 
TBody :TResult 
TBody :route 
TBody :body 
TBody :HttpMethod.Put 
TBody :null 
TBody :false 
TBody :cancellationToken 

◆ Create< TBody, TResult >() [2/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Create< TBody, TResult > ( string  route,
TBody  body,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP PUT request.

Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunRequest 
TBody :TBody 
TBody :TResult 
TBody :route 
TBody :body 
TBody :HttpMethod.Put 
TBody :instanceId 
TBody :false 
TBody :cancellationToken 

◆ Create< TResult >() [1/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Create< TResult > ( string  route,
CancellationToken  cancellationToken 
)

Run an HTTP PUT request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ Create< TResult >() [2/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Create< TResult > ( string  route,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP PUT request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ CreateHubConnection< THubImplementation >()

async ValueTask< IAsyncDisposable > Tgstation.Server.Client.ApiClient.CreateHubConnection< THubImplementation > ( THubImplementation  hubImplementation,
IRetryPolicy retryPolicy,
Action< ILoggingBuilder >?  loggingConfigureAction,
CancellationToken  cancellationToken 
)

Subscribe to all job updates available to the IRestServerClient.

Template Parameters
THubImplementationThe Type of the hub being implemented.
Parameters
hubImplementationThe THubImplementation to use for proxying the methods of the hub connection.
retryPolicyThe optional IRetryPolicy to use for the backing connection. The default retry policy waits for 1, 2, 4, 8, and 16 seconds, then 30s repeatedly.
loggingConfigureActionThe optional Action<T1> used to configure a ILoggingBuilder.
cancellationTokenThe CancellationToken for the operation.
Returns
An IAsyncDisposable representing the lifetime of the subscription.

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
THubImplementation :class 

Definition at line 360 of file ApiClient.cs.

365 : class
366 {
367 if (hubImplementation == null)
368 throw new ArgumentNullException(nameof(hubImplementation));
369
370 retryPolicy ??= new InfiniteThirtySecondMaxRetryPolicy();
371
372 var wrappedPolicy = new ApiClientTokenRefreshRetryPolicy(this, retryPolicy);
373
374 HubConnection? hubConnection = null;
375 var hubConnectionBuilder = new HubConnectionBuilder()
376 .AddNewtonsoftJsonProtocol(options =>
377 {
378 options.PayloadSerializerSettings = SerializerSettings;
379 })
380 .WithAutomaticReconnect(wrappedPolicy)
381 .WithUrl(
382 new Uri(Url, Routes.JobsHub),
383 HttpTransportType.ServerSentEvents,
384 options =>
385 {
386 options.AccessTokenProvider = async () =>
387 {
388 // DCT: None available.
389 if (Headers.Token == null
390 || (Headers.Token.ParseJwt().ValidTo <= DateTime.UtcNow
391 && !await RefreshToken(CancellationToken.None)))
392 {
393 _ = hubConnection!.StopAsync(); // DCT: None available.
394 return null;
395 }
396
397 return Headers.Token.Bearer;
398 };
399
400 options.CloseTimeout = Timeout;
401
402 Headers.SetHubConnectionHeaders(options.Headers);
403 });
404
405 if (loggingConfigureAction != null)
406 hubConnectionBuilder.ConfigureLogging(loggingConfigureAction);
407
408 async ValueTask<HubConnection> AttemptConnect()
409 {
410 hubConnection = hubConnectionBuilder.Build();
411 try
412 {
413 hubConnection.Closed += async (error) =>
414 {
415 if (error is HttpRequestException httpRequestException)
416 {
417 // .StatusCode isn't in netstandard but fuck the police
418 var property = error.GetType().GetProperty("StatusCode");
419 if (property != null)
420 {
421 var statusCode = (HttpStatusCode?)property.GetValue(error);
422 if (statusCode == HttpStatusCode.Unauthorized
423 && !await RefreshToken(CancellationToken.None))
424 _ = hubConnection!.StopAsync();
425 }
426 }
427 };
428
429 hubConnection.ProxyOn(hubImplementation);
430
431 Task startTask;
432 lock (hubConnections)
433 {
434 if (disposed)
435 throw new ObjectDisposedException(nameof(ApiClient));
436
437 hubConnections.Add(hubConnection);
438 startTask = hubConnection.StartAsync(cancellationToken);
439 }
440
441 await startTask;
442
443 return hubConnection;
444 }
445 catch
446 {
447 bool needsDispose;
448 lock (hubConnections)
449 needsDispose = hubConnections.Remove(hubConnection);
450
451 if (needsDispose)
452 await hubConnection.DisposeAsync();
453 throw;
454 }
455 }
456
457 return await WrapHubInitialConnectAuthRefresh(AttemptConnect, cancellationToken);
458 }
void SetHubConnectionHeaders(IDictionary< string, string > headers)
Adds the headers necessary for a SignalR hub connection.
Routes to a server actions.
Definition Routes.cs:9
const string JobsHub
The root route of all hubs.
Definition Routes.cs:118
TimeSpan Timeout
The request timeout.
Definition ApiClient.cs:54
static readonly JsonSerializerSettings SerializerSettings
The JsonSerializerSettings to use.
Definition ApiClient.cs:62
bool disposed
If the ApiClient is disposed.
Definition ApiClient.cs:109
async ValueTask< HubConnection > WrapHubInitialConnectAuthRefresh(Func< ValueTask< HubConnection > > connectFunc, CancellationToken cancellationToken)
Wrap a hub connection attempt via a connectFunc with proper token refreshing.
Definition ApiClient.cs:585
async ValueTask< bool > RefreshToken(CancellationToken cancellationToken)
Attempt to refresh the stored Bearer token in Headers.
Definition ApiClient.cs:336
ApiHeaders Headers
The ApiHeaders the IApiClient uses.
Definition ApiClient.cs:47

References Tgstation.Server.Client.ApiClient.Headers, Tgstation.Server.Api.Routes.JobsHub, Tgstation.Server.Client.ApiClient.SerializerSettings, Tgstation.Server.Api.ApiHeaders.SetHubConnectionHeaders(), Tgstation.Server.Client.ApiClient.Timeout, and Tgstation.Server.Client.ApiClient.Url.

Here is the call graph for this function:

◆ Delete() [1/2]

ValueTask Tgstation.Server.Client.ApiClient.Delete ( string  route,
CancellationToken  cancellationToken 
)

Run an HTTP DELETE request.

Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

◆ Delete() [2/2]

ValueTask Tgstation.Server.Client.ApiClient.Delete ( string  route,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP DELETE request.

Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

◆ Delete< TBody >()

ValueTask Tgstation.Server.Client.ApiClient.Delete< TBody > ( string  route,
TBody  body,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP DELETE request.

Template Parameters
TBodyThe type to of the request body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunResultlessRequest 
TBody :route 
TBody :body 
TBody :HttpMethod.Delete 
TBody :instanceId 
TBody :false 
TBody :cancellationToken 

◆ Delete< TBody, TResult >()

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Delete< TBody, TResult > ( string  route,
TBody  body,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP DELETE request.

Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunRequest 
TBody :TBody 
TBody :TResult 
TBody :route 
TBody :body 
TBody :HttpMethod.Delete 
TBody :instanceId 
TBody :false 
TBody :cancellationToken 

◆ Delete< TResult >()

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Delete< TResult > ( string  route,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP DELETE request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ DisposeAsync()

async ValueTask Tgstation.Server.Client.ApiClient.DisposeAsync ( )

Definition at line 187 of file ApiClient.cs.

188 {
189 List<HubConnection> localHubConnections;
190 lock (hubConnections)
191 {
192 if (disposed)
193 return;
194
195 disposed = true;
196
197 localHubConnections = [.. hubConnections];
198 hubConnections.Clear();
199 }
200
201 await ValueTaskExtensions.WhenAll(hubConnections.Select(connection => connection.DisposeAsync()));
202
203 httpClient.Dispose();
204 semaphoreSlim.Dispose();
205 }
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .

References Tgstation.Server.Client.ApiClient.disposed, Tgstation.Server.Client.ApiClient.httpClient, Tgstation.Server.Client.ApiClient.hubConnections, Tgstation.Server.Client.ApiClient.semaphoreSlim, and Tgstation.Server.Common.Extensions.ValueTaskExtensions.WhenAll().

Here is the call graph for this function:

◆ Download()

ValueTask< Stream > Tgstation.Server.Client.ApiClient.Download ( FileTicketResponse  ticket,
CancellationToken  cancellationToken 
)

Downloads a file Stream for a given ticket .

Parameters
ticketThe FileTicketResponse to download.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the downloaded Stream.

Implements Tgstation.Server.Client.ITransferClient.

Definition at line 285 of file ApiClient.cs.

286 {
287 if (ticket == null)
288 throw new ArgumentNullException(nameof(ticket));
289
290 return RunRequest<Stream>(
291 $"{Routes.Transfer}?ticket={HttpUtility.UrlEncode(ticket.FileTicket)}",
292 null,
293 HttpMethod.Get,
294 null,
295 false,
296 cancellationToken);
297 }

Referenced by Tgstation.Server.Client.AdministrationClient.GetLog(), and Tgstation.Server.Client.Components.ConfigurationClient.Read().

Here is the caller graph for this function:

◆ HandleBadResponse()

static void Tgstation.Server.Client.ApiClient.HandleBadResponse ( HttpResponseMessage  response,
string  json 
)
staticprivate

Handle a bad HTTP response .

Parameters
responseThe HttpResponseMessage.
jsonThe JSON string if any.

Definition at line 116 of file ApiClient.cs.

117 {
118 ErrorMessageResponse? errorMessage = null;
119 try
120 {
121 // check if json serializes to an error message
122 errorMessage = JsonConvert.DeserializeObject<ErrorMessageResponse>(json, SerializerSettings);
123 }
124 catch (JsonException)
125 {
126 }
127
128#pragma warning disable IDE0010 // Add missing cases
129 switch (response.StatusCode)
130#pragma warning restore IDE0010 // Add missing cases
131 {
132 case HttpStatusCode.Unauthorized:
133 throw new UnauthorizedException(errorMessage, response);
134 case HttpStatusCode.InternalServerError:
135 throw new ServerErrorException(errorMessage, response);
136 case HttpStatusCode.NotImplemented:
137 // unprocessable entity
138 case (HttpStatusCode)422:
139 throw new MethodNotSupportedException(errorMessage, response);
140 case HttpStatusCode.NotFound:
141 case HttpStatusCode.Gone:
142 case HttpStatusCode.Conflict:
143 throw new ConflictException(errorMessage, response);
144 case HttpStatusCode.Forbidden:
145 throw new InsufficientPermissionsException(response);
146 case HttpStatusCode.ServiceUnavailable:
147 throw new ServiceUnavailableException(response);
148 case HttpStatusCode.RequestTimeout:
149 throw new RequestTimeoutException(response);
150 case (HttpStatusCode)429:
151 throw new RateLimitException(errorMessage, response);
152 default:
153 if (errorMessage?.ErrorCode == ErrorCode.ApiMismatch)
154 throw new VersionMismatchException(errorMessage, response);
155
156 throw new ApiConflictException(errorMessage, response);
157 }
158 }
Represents an error message returned by the server.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12

References Tgstation.Server.Client.ApiClient.SerializerSettings.

◆ Patch()

ValueTask Tgstation.Server.Client.ApiClient.Patch ( string  route,
CancellationToken  cancellationToken 
)

Run an HTTP PATCH request.

Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

◆ Patch< TResult >()

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Patch< TResult > ( string  route,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP PATCH request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ Read< TResult >() [1/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Read< TResult > ( string  route,
CancellationToken  cancellationToken 
)

Run an HTTP GET request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ Read< TResult >() [2/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Read< TResult > ( string  route,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP GET request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ RefreshToken()

async ValueTask< bool > Tgstation.Server.Client.ApiClient.RefreshToken ( CancellationToken  cancellationToken)

Attempt to refresh the stored Bearer token in Headers.

Parameters
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in true if the refresh was successful, false if a refresh is unable to be performed.

Definition at line 336 of file ApiClient.cs.

337 {
338 if (tokenRefreshHeaders == null)
339 return false;
340
341 var startingToken = headers.Token;
342 await semaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false);
343 try
344 {
345 if (startingToken != headers.Token)
346 return true;
347
348 var token = await RunRequest<object, TokenResponse>(Routes.ApiRoot, new object(), HttpMethod.Post, null, true, cancellationToken).ConfigureAwait(false);
349 headers = new ApiHeaders(headers.UserAgent!, token);
350 }
351 finally
352 {
353 semaphoreSlim.Release();
354 }
355
356 return true;
357 }
Represents the header that must be present for every server request.
Definition ApiHeaders.cs:25
ProductHeaderValue? UserAgent
The client's user agent as a ProductHeaderValue if valid.
Definition ApiHeaders.cs:89
TokenResponse? Token
The client's TokenResponse.
const string ApiRoot
The root of API methods.
Definition Routes.cs:13

References Tgstation.Server.Api.Routes.ApiRoot, Tgstation.Server.Client.ApiClient.headers, Tgstation.Server.Client.ApiClient.semaphoreSlim, Tgstation.Server.Api.ApiHeaders.Token, Tgstation.Server.Client.ApiClient.tokenRefreshHeaders, and Tgstation.Server.Api.ApiHeaders.UserAgent.

Referenced by Tgstation.Server.Client.ApiClientTokenRefreshRetryPolicy.AttemptTokenRefresh().

Here is the caller graph for this function:

◆ RunRequest()

ValueTask Tgstation.Server.Client.ApiClient.RunRequest ( string  route,
HttpMethod  method,
long?  instanceId,
bool  tokenRefresh,
CancellationToken  cancellationToken 
)
private

Main request method.

Parameters
routeThe route to run.
methodThe method of the request.
instanceIdThe optional instance EntityId.Id for the request.
tokenRefreshIf this is a token refresh operation.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response on success.

◆ RunRequest< TBody, TResult >()

async ValueTask< TResult > Tgstation.Server.Client.ApiClient.RunRequest< TBody, TResult > ( string  route,
TBody?  body,
HttpMethod  method,
long?  instanceId,
bool  tokenRefresh,
CancellationToken  cancellationToken 
)
private

Main request method.

Template Parameters
TBodyThe body Type.
TResultThe resulting POCO type.
Parameters
routeThe route to run.
bodyThe body of the request.
methodThe method of the request.
instanceIdThe optional instance EntityId.Id for the request.
tokenRefreshIf this is a token refresh operation.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response on success.
Type Constraints
TBody :class 

Definition at line 620 of file ApiClient.cs.

627 : class
628 {
629 HttpContent? content = null;
630 if (body != null)
631 content = new StringContent(
632 JsonConvert.SerializeObject(body, typeof(TBody), Formatting.None, SerializerSettings),
633 Encoding.UTF8,
635
636 using (content)
637 return await RunRequest<TResult>(
638 route,
639 content,
640 method,
641 instanceId,
642 tokenRefresh,
643 cancellationToken)
644 .ConfigureAwait(false);
645 }
const string ApplicationJsonMime
Added to MediaTypeNames.Application in netstandard2.1. Can't use because of lack of ....
Definition ApiHeaders.cs:59
virtual async ValueTask< TResult > RunRequest< TResult >(string route, HttpContent? content, HttpMethod method, long? instanceId, bool tokenRefresh, CancellationToken cancellationToken)
Main request method.
Definition ApiClient.cs:472

References Tgstation.Server.Api.ApiHeaders.ApplicationJsonMime.

◆ RunRequest< TResult >()

virtual async ValueTask< TResult > Tgstation.Server.Client.ApiClient.RunRequest< TResult > ( string  route,
HttpContent?  content,
HttpMethod  method,
long?  instanceId,
bool  tokenRefresh,
CancellationToken  cancellationToken 
)
protectedvirtual

Main request method.

Template Parameters
TResultThe resulting POCO type.
Parameters
routeThe route to run.
contentThe HttpContent of the request if any.
methodThe method of the request.
instanceIdThe optional instance EntityId.Id for the request.
tokenRefreshIf this is a token refresh operation.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response on success.

Definition at line 472 of file ApiClient.cs.

479 {
480 if (route == null)
481 throw new ArgumentNullException(nameof(route));
482 if (method == null)
483 throw new ArgumentNullException(nameof(method));
484 if (content == null && (method == HttpMethod.Post || method == HttpMethod.Put))
485 throw new InvalidOperationException("content cannot be null for POST or PUT!");
486
487 if (disposed)
488 throw new ObjectDisposedException(nameof(ApiClient));
489
490 HttpResponseMessage response;
491 var fullUri = new Uri(Url, route);
492 var serializerSettings = SerializerSettings;
493 var fileDownload = typeof(TResult) == typeof(Stream);
494 using (var request = new HttpRequestMessage(method, fullUri))
495 {
496 if (content != null)
497 request.Content = content;
498
499 try
500 {
501 var headersToUse = tokenRefresh ? tokenRefreshHeaders! : headers;
502 headersToUse.SetRequestHeaders(request.Headers, instanceId);
503
504 if (authless)
505 request.Headers.Remove(HeaderNames.Authorization);
506 else
507 {
508 var bearer = headersToUse.Token?.Bearer;
509 if (bearer != null)
510 {
511 var parsed = headersToUse.Token!.ParseJwt();
512 var nbf = parsed.ValidFrom;
513 var now = DateTime.UtcNow;
514 if (nbf >= now)
515 {
516 var delay = (nbf - now).Add(TimeSpan.FromMilliseconds(1));
517 await Task.Delay(delay, cancellationToken);
518 }
519 }
520 }
521
522 if (fileDownload)
523 request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Octet));
524
525 await ValueTaskExtensions.WhenAll(requestLoggers.Select(x => x.LogRequest(request, cancellationToken))).ConfigureAwait(false);
526
527 response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
528 }
529 finally
530 {
531 // prevent content param from getting disposed
532 request.Content = null;
533 }
534 }
535
536 try
537 {
538 await ValueTaskExtensions.WhenAll(requestLoggers.Select(x => x.LogResponse(response, cancellationToken))).ConfigureAwait(false);
539
540 // just stream
541 if (fileDownload && response.IsSuccessStatusCode)
542 return (TResult)(object)await CachedResponseStream.Create(response).ConfigureAwait(false);
543 }
544 catch
545 {
546 response.Dispose();
547 throw;
548 }
549
550 using (response)
551 {
552 var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
553
554 if (!response.IsSuccessStatusCode)
555 {
556 if (!tokenRefresh
557 && response.StatusCode == HttpStatusCode.Unauthorized
558 && await RefreshToken(cancellationToken).ConfigureAwait(false))
559 return await RunRequest<TResult>(route, content, method, instanceId, false, cancellationToken).ConfigureAwait(false);
560 HandleBadResponse(response, json);
561 }
562
563 if (String.IsNullOrWhiteSpace(json))
564 json = JsonConvert.SerializeObject(new object());
565
566 try
567 {
568 var result = JsonConvert.DeserializeObject<TResult>(json, serializerSettings);
569 return result!;
570 }
571 catch (JsonException)
572 {
573 throw new UnrecognizedResponseException(response);
574 }
575 }
576 }
void SetRequestHeaders(HttpRequestHeaders headers, long? instanceId=null)
Set HttpRequestHeaders using the ApiHeaders. This initially clears headers .
static void HandleBadResponse(HttpResponseMessage response, string json)
Handle a bad HTTP response .
Definition ApiClient.cs:116
ValueTask< TResult > TResult(route, new object(), HttpMethod.Put, null, false, cancellationToken)
Caches the Stream from a HttpResponseMessage for later use.
static async ValueTask< CachedResponseStream > Create(HttpResponseMessage response)
Asyncronously creates a new CachedResponseStream.
Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
Send an HTTP request.

References Tgstation.Server.Common.Http.CachedResponseStream.Create(), Tgstation.Server.Api.ApiHeaders.SetRequestHeaders(), and Tgstation.Server.Common.Extensions.ValueTaskExtensions.WhenAll().

Here is the call graph for this function:

◆ RunResultlessRequest< TBody >()

async ValueTask Tgstation.Server.Client.ApiClient.RunResultlessRequest< TBody > ( string  route,
TBody?  body,
HttpMethod  method,
long?  instanceId,
bool  tokenRefresh,
CancellationToken  cancellationToken 
)
private

Main request method.

Template Parameters
TBodyThe body Type.
Parameters
routeThe route to run.
bodyThe body of the request.
methodThe method of the request.
instanceIdThe optional instance EntityId.Id for the request.
tokenRefreshIf this is a token refresh operation.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response on success.
Type Constraints
TBody :class 
TBody :await 
TBody :RunRequest 
TBody :TBody 
TBody :object 
TBody :route 
TBody :body 
TBody :method 
TBody :instanceId 
TBody :tokenRefresh 
TBody :cancellationToken 

◆ TResult() [1/5]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.TResult ( route  ,
new   object(),
HttpMethod.  Post,
null  ,
false  ,
cancellationToken   
)
private

◆ TResult() [2/5]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.TResult ( route  ,
new   object(),
HttpMethod.  Put,
instanceId  ,
false  ,
cancellationToken   
)
private

◆ TResult() [3/5]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.TResult ( route  ,
new   object(),
HttpMethod.  Put,
null  ,
false  ,
cancellationToken   
)
private

◆ TResult() [4/5]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.TResult ( route  ,
new   object(),
HttpPatch  ,
instanceId  ,
false  ,
cancellationToken   
)
private

◆ TResult() [5/5]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.TResult ( route  ,
null  ,
HttpMethod.  Get,
null  ,
false  ,
cancellationToken   
)
private

◆ Update< TBody >()

ValueTask Tgstation.Server.Client.ApiClient.Update< TBody > ( string  route,
TBody  body,
CancellationToken  cancellationToken 
)

Run an HTTP POST request.

Template Parameters
TBodyThe type to of the request body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunResultlessRequest 
TBody :route 
TBody :body 
TBody :HttpMethod.Post 
TBody :null 
TBody :false 
TBody :cancellationToken 

◆ Update< TBody, TResult >() [1/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Update< TBody, TResult > ( string  route,
TBody  body,
CancellationToken  cancellationToken 
)

Run an HTTP POST request.

Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunRequest 
TBody :TBody 
TBody :TResult 
TBody :route 
TBody :body 
TBody :HttpMethod.Post 
TBody :null 
TBody :false 
TBody :cancellationToken 

◆ Update< TBody, TResult >() [2/2]

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Update< TBody, TResult > ( string  route,
TBody  body,
long  instanceId,
CancellationToken  cancellationToken 
)

Run an HTTP POST request.

Template Parameters
TBodyThe type to of the request body.
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
bodyThe request body.
instanceIdThe instance EntityId.Id to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

Type Constraints
TBody :class 
TBody :RunRequest 
TBody :TBody 
TBody :TResult 
TBody :route 
TBody :body 
TBody :HttpMethod.Post 
TBody :instanceId 
TBody :false 
TBody :cancellationToken 

◆ Update< TResult >()

ValueTask< TResult > Tgstation.Server.Client.ApiClient.Update< TResult > ( string  route,
CancellationToken  cancellationToken 
)

Run an HTTP POST request.

Template Parameters
TResultThe type of the response body.
Parameters
routeThe server route to make the request to.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the response body as a TResult .

Implements Tgstation.Server.Client.IApiClient.

◆ Upload()

async ValueTask Tgstation.Server.Client.ApiClient.Upload ( FileTicketResponse  ticket,
Stream uploadStream,
CancellationToken  cancellationToken 
)

Uploads a given uploadStream for a given ticket .

Parameters
ticketThe FileTicketResponse to download.
uploadStreamThe Stream to upload. null represents an empty file.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask representing the running operation.

Implements Tgstation.Server.Client.ITransferClient.

Definition at line 300 of file ApiClient.cs.

301 {
302 if (ticket == null)
303 throw new ArgumentNullException(nameof(ticket));
304
305 MemoryStream? memoryStream = null;
306 if (uploadStream == null)
307 memoryStream = new MemoryStream();
308
309 using (memoryStream)
310 {
311 var streamContent = new StreamContent(uploadStream ?? memoryStream);
312 try
313 {
314 await RunRequest<object>(
315 $"{Routes.Transfer}?ticket={HttpUtility.UrlEncode(ticket.FileTicket)}",
316 streamContent,
317 HttpMethod.Put,
318 null,
319 false,
320 cancellationToken)
321 .ConfigureAwait(false);
322 streamContent = null;
323 }
324 finally
325 {
326 streamContent?.Dispose();
327 }
328 }
329 }

Referenced by Tgstation.Server.Client.Components.EngineClient.SetActiveVersion(), Tgstation.Server.Client.AdministrationClient.Update(), and Tgstation.Server.Client.Components.ConfigurationClient.Write().

Here is the caller graph for this function:

◆ WrapHubInitialConnectAuthRefresh()

async ValueTask< HubConnection > Tgstation.Server.Client.ApiClient.WrapHubInitialConnectAuthRefresh ( Func< ValueTask< HubConnection > >  connectFunc,
CancellationToken  cancellationToken 
)
private

Wrap a hub connection attempt via a connectFunc with proper token refreshing.

Parameters
connectFuncThe HubConnection Func<TResult>.
cancellationTokenThe CancellationToken for the operation.
Returns
A ValueTask<TResult> resulting in the connected HubConnection.

Definition at line 585 of file ApiClient.cs.

586 {
587 try
588 {
589 return await connectFunc();
590 }
591 catch (HttpRequestException ex)
592 {
593 // status code is not in netstandard
594 var propertyInfo = ex.GetType().GetProperty("StatusCode");
595 if (propertyInfo != null)
596 {
597 var statusCode = (HttpStatusCode)propertyInfo.GetValue(ex);
598 if (statusCode != HttpStatusCode.Unauthorized)
599 throw;
600 }
601
602 await RefreshToken(cancellationToken);
603
604 return await connectFunc();
605 }
606 }

Member Data Documentation

◆ authless

readonly bool Tgstation.Server.Client.ApiClient.authless
private

If the authentication header should be stripped from requests.

Definition at line 99 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient().

◆ disposed

bool Tgstation.Server.Client.ApiClient.disposed
private

If the ApiClient is disposed.

Definition at line 109 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.DisposeAsync().

◆ headers

ApiHeaders Tgstation.Server.Client.ApiClient.headers
private

Backing field for Headers.

Definition at line 104 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient(), and Tgstation.Server.Client.ApiClient.RefreshToken().

◆ httpClient

readonly IHttpClient Tgstation.Server.Client.ApiClient.httpClient
private

The IHttpClient for the ApiClient.

Definition at line 74 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient(), and Tgstation.Server.Client.ApiClient.DisposeAsync().

◆ HttpPatch

readonly HttpMethod Tgstation.Server.Client.ApiClient.HttpPatch = new("PATCH")
staticprivate

PATCH HttpMethod.

HOW IS THIS NOT INCLUDED IN THE FRAMEWORK??!?!?

Definition at line 40 of file ApiClient.cs.

◆ hubConnections

readonly List<HubConnection> Tgstation.Server.Client.ApiClient.hubConnections
private

List of HubConnections created by the ApiClient.

Definition at line 84 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient(), and Tgstation.Server.Client.ApiClient.DisposeAsync().

◆ requestLoggers

readonly List<IRequestLogger> Tgstation.Server.Client.ApiClient.requestLoggers
private

The IRequestLoggers used by the ApiClient.

Definition at line 79 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient().

◆ semaphoreSlim

readonly SemaphoreSlim Tgstation.Server.Client.ApiClient.semaphoreSlim
private

◆ SerializerSettings

readonly JsonSerializerSettings Tgstation.Server.Client.ApiClient.SerializerSettings
staticprivate
Initial value:
= new()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new[]
{
new VersionConverter(),
},
}

The JsonSerializerSettings to use.

Definition at line 62 of file ApiClient.cs.

63 {
64 ContractResolver = new CamelCasePropertyNamesContractResolver(),
65 Converters = new[]
66 {
67 new VersionConverter(),
68 },
69 };

Referenced by Tgstation.Server.Client.ApiClient.CreateHubConnection< THubImplementation >(), and Tgstation.Server.Client.ApiClient.HandleBadResponse().

◆ tokenRefreshHeaders

readonly? ApiHeaders Tgstation.Server.Client.ApiClient.tokenRefreshHeaders
private

Backing field for Headers.

Definition at line 89 of file ApiClient.cs.

Referenced by Tgstation.Server.Client.ApiClient.ApiClient(), and Tgstation.Server.Client.ApiClient.RefreshToken().

Property Documentation

◆ Headers

ApiHeaders Tgstation.Server.Client.ApiClient.Headers
getset

The ApiHeaders the IApiClient uses.

Implements Tgstation.Server.Client.IApiClient.

Definition at line 46 of file ApiClient.cs.

47 {
48 get => headers;
49 set => headers = value ?? throw new InvalidOperationException("Cannot set null headers!");
50 }

Referenced by Tgstation.Server.Client.ApiClient.CreateHubConnection< THubImplementation >().

◆ Timeout

TimeSpan Tgstation.Server.Client.ApiClient.Timeout
getset

The request timeout.

Implements Tgstation.Server.Client.IApiClient.

Definition at line 53 of file ApiClient.cs.

54 {
55 get => httpClient.Timeout;
56 set => httpClient.Timeout = value;
57 }
TimeSpan Timeout
The request timeout.

Referenced by Tgstation.Server.Client.ApiClient.CreateHubConnection< THubImplementation >().

◆ Url

Uri Tgstation.Server.Client.ApiClient.Url
get

The Uri pointing the tgstation-server.

Implements Tgstation.Server.Client.IApiClient.

Definition at line 43 of file ApiClient.cs.

43{ get; }

Referenced by Tgstation.Server.Client.ApiClient.ApiClient(), and Tgstation.Server.Client.ApiClient.CreateHubConnection< THubImplementation >().


The documentation for this class was generated from the following file: