using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace RadarrSharp.Proxies { public class RadarrProxy : IRadarrProxy { private HttpClient _client; public RadarrProxy() { _client = new HttpClient(); } public async Task GetAsync(string rootUrl) { var resp = await _client.GetAsync(rootUrl); var content = await resp.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(content); } public async Task PostAsync(string rootUrl, U data) { var jsonPayload = JsonConvert.SerializeObject(data); var response = await _client.PostAsync(rootUrl, PrepJsonForPost(jsonPayload)); var resp = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(resp); } public async Task PutAsync(string rootUrl, U data) { var jsonPayload = JsonConvert.SerializeObject(data); var response = await _client.PutAsync(rootUrl, PrepJsonForPost(jsonPayload)); return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); } public async Task DeleteAsync(string rootUrl) { var resp = await _client.DeleteAsync(rootUrl); return resp; } private StringContent PrepJsonForPost(string jsonObj) { return new StringContent(jsonObj, Encoding.UTF8, "application/json"); } } }