protected static async Task <HttpResponseMessage> PatchObjectToAPI <T>(string apiUrl, T data) { var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false); var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); var httpRequest = new HttpRequestMessage { Method = new HttpMethod("PATCH"), RequestUri = new Uri(apiUrl), Content = httpContent }; try { UpdateActivityIndicatorStatus(true); return(await Client.SendAsync(httpRequest).ConfigureAwait(false)); } catch (Exception e) { AppCenterHelpers.LogException(e); return(null); } finally { UpdateActivityIndicatorStatus(false); } }
protected static async Task <HttpResponseMessage> DeleteObjectFromAPI(string apiUrl) { var httpRequest = new HttpRequestMessage(HttpMethod.Delete, new Uri(apiUrl)); try { UpdateActivityIndicatorStatus(true); return(await Client.SendAsync(httpRequest)); } catch (Exception e) { AppCenterHelpers.LogException(e); return(null); } finally { UpdateActivityIndicatorStatus(false); } }
protected static async Task <TDataObject> GetDataObjectFromAPI <TDataObject, TPayloadData>(string apiUrl, TPayloadData data = default(TPayloadData)) { var stringPayload = string.Empty; if (data != null) { stringPayload = await Task.Run(() => JsonConvert.SerializeObject(data)).ConfigureAwait(false); } var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); try { UpdateActivityIndicatorStatus(true); using (var stream = await Client.GetStreamAsync(apiUrl).ConfigureAwait(false)) using (var reader = new StreamReader(stream)) using (var json = new JsonTextReader(reader)) { if (json == null) { return(default(TDataObject)); } return(await Task.Run(() => Serializer.Deserialize <TDataObject>(json)).ConfigureAwait(false)); } } catch (Exception e) { AppCenterHelpers.LogException(e); return(default(TDataObject)); } finally { UpdateActivityIndicatorStatus(false); } }