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) ) { int retries = 0; int maxRetries = 0; switch (method.ToString()) { case "GET": case "PUT": case "DELETE": maxRetries = 2; break; } while (retries <= maxRetries) { try { 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)); } } catch (Exception) { retries++; if (retries >= maxRetries) { throw; } } } // won't ever reach here return(default(T)); }
public RESTBase(Connection connection, APIEndpoint endpoint) { this.Connection = connection; this.Endpoint = endpoint; }
public Task <ClientWebSocket> ConnectWebSocket( APIEndpoint apiEndpoint, object querystring = null, Action <ClientWebSocket> configure = null, CancellationToken cancellationToken = default(CancellationToken)) => ConnectWebSocket(apiEndpoint.Endpoint, querystring, configure, cancellationToken);