Initial Commit
This commit is contained in:
13
Proxies/IRadarrProxy.cs
Normal file
13
Proxies/IRadarrProxy.cs
Normal 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
53
Proxies/RadarrProxy.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user