public async Task <T> APICallAsync <T>( HttpMethod method, APIEndpoint endpoint, object queryStringContent = null, object bodyContent = null, IDictionary <string, string> headers = null, Func <HttpResponseMessage, Task <T> > onResponse = null, CancellationToken cancellationToken = default(CancellationToken) ) { using (var request = await RequestAsync(method, endpoint.Endpoint, queryStringContent, bodyContent, headers: headers)) using (var response = await Client.SendAsync( request, HttpCompletionOption.ResponseHeadersRead, cancellationToken )) { if (onResponse != null) { return(await onResponse.Invoke(response)); } return(await DefaultResponseHandler <T>(response)); } }
public async Task ConnectAsync(CancellationToken cancellationToken = default(CancellationToken)) { Socket = await APIClient.ConnectWebSocket( APIEndpoint.PlayerConnect(WorldName), cancellationToken : cancellationToken ); if (OnConnected != null) { await OnConnected(); } }
public Task <ClientWebSocket> ConnectWebSocket( APIEndpoint apiEndpoint, object querystring = null, Action <ClientWebSocket> configure = null, CancellationToken cancellationToken = default(CancellationToken)) => ConnectWebSocket(apiEndpoint.Endpoint, querystring, configure, cancellationToken);