コード例 #1
0
        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");
        }
コード例 #2
0
 protected T Post <T>(string uri, BaseOptions options = null)
 {
     return(Request <T>(uri, "POST", options));
 }
コード例 #3
0
 protected async Task <T> PostAsync <T>(string uri, BaseOptions options = null)
 {
     return(await RequestAsync <T>(uri, "POST", options));
 }
コード例 #4
0
 protected T Get <T>(string uri, BaseOptions options = null)
 {
     return(Request <T>(uri, "GET", options));
 }
コード例 #5
0
 protected T Delete <T>(string uri, BaseOptions options = null)
 {
     return(Request <T>(uri, "DELETE", options));
 }
コード例 #6
0
 protected async Task <T> DeleteAsync <T>(string uri, BaseOptions options = null)
 {
     return(await RequestAsync <T>(uri, "DELETE", options));
 }