Initial Commit
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing

This commit is contained in:
2022-01-18 12:09:42 -08:00
commit 46e403f880
63 changed files with 5482 additions and 0 deletions

13
Proxies/IRadarrProxy.cs Normal file
View File

@@ -0,0 +1,13 @@
using System.Net.Http;
using System.Threading.Tasks;
namespace RadarrSharp.Proxies
{
internal interface IRadarrProxy
{
Task<T> GetAsync<T>(string url);
Task<T> PostAsync<T, U>(string rootUrl, U data);
Task<T> PutAsync<T, U>(string rootUrl, U data);
Task<HttpResponseMessage> DeleteAsync(string rootUrl);
}
}

53
Proxies/RadarrProxy.cs Normal file
View File

@@ -0,0 +1,53 @@
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<T> GetAsync<T>(string rootUrl)
{
var resp = await _client.GetAsync(rootUrl);
var content = await resp.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(content);
}
public async Task<T> PostAsync<T, U>(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<T>(resp);
}
public async Task<T> PutAsync<T, U>(string rootUrl, U data)
{
var jsonPayload = JsonConvert.SerializeObject(data);
var response = await _client.PutAsync(rootUrl, PrepJsonForPost(jsonPayload));
return JsonConvert.DeserializeObject<T>(await response.Content.ReadAsStringAsync());
}
public async Task<HttpResponseMessage> DeleteAsync(string rootUrl)
{
var resp = await _client.DeleteAsync(rootUrl);
return resp;
}
private StringContent PrepJsonForPost(string jsonObj)
{
return new StringContent(jsonObj, Encoding.UTF8, "application/json");
}
}
}