private T Request <T>(string uri, string method, BaseOptions options = null) { var request = new HttpRequestMessage(new HttpMethod(method), uri) { Content = options != null ? new StringContent(options.ToJson(), Encoding.UTF8, "application/json") : new StringContent(string.Empty, Encoding.UTF8, "application/json") }; var response = _client.SendAsync(request).GetAwaiter().GetResult(); var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.Accepted) { return(JsonConvert.DeserializeObject <T>(content)); } if (content.Contains("errors")) { throw new OneSignalException("There was a problem with the OneSignal request", JsonConvert.DeserializeObject <OneSignalError>(content)); } throw new OneSignalException("There was a problem with the OneSignal request"); }
protected T Post <T>(string uri, BaseOptions options = null) { return(Request <T>(uri, "POST", options)); }
protected async Task <T> PostAsync <T>(string uri, BaseOptions options = null) { return(await RequestAsync <T>(uri, "POST", options)); }
protected T Get <T>(string uri, BaseOptions options = null) { return(Request <T>(uri, "GET", options)); }
protected T Delete <T>(string uri, BaseOptions options = null) { return(Request <T>(uri, "DELETE", options)); }
protected async Task <T> DeleteAsync <T>(string uri, BaseOptions options = null) { return(await RequestAsync <T>(uri, "DELETE", options)); }