Lidarr/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs

70 lines
2.2 KiB
C#
Raw Normal View History

2016-12-23 21:45:24 +00:00
using NLog;
2014-08-03 07:26:55 +00:00
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
2016-12-28 07:52:20 +00:00
namespace NzbDrone.Core.Notifications.Emby
2014-08-03 07:26:55 +00:00
{
public class MediaBrowserProxy
{
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
public MediaBrowserProxy(IHttpClient httpClient, Logger logger)
{
_httpClient = httpClient;
_logger = logger;
}
public void Notify(MediaBrowserSettings settings, string title, string message)
{
var path = "/Notifications/Admin";
var request = BuildRequest(path, settings);
request.Headers.ContentType = "application/json";
2014-08-03 07:26:55 +00:00
request.SetContent(new
2014-08-03 07:26:55 +00:00
{
Name = title,
Description = message,
ImageUrl = "https://raw.github.com/NzbDrone/NzbDrone/develop/Logo/64.png"
}.ToJson());
2014-08-03 07:26:55 +00:00
ProcessRequest(request, settings);
}
public void Update(MediaBrowserSettings settings, int tvdbId)
2014-08-03 07:26:55 +00:00
{
var path = string.Format("/Library/Series/Updated?tvdbid={0}", tvdbId);
2014-08-03 07:26:55 +00:00
var request = BuildRequest(path, settings);
request.Headers.Add("Content-Length", "0");
2014-08-03 07:26:55 +00:00
ProcessRequest(request, settings);
}
private string ProcessRequest(HttpRequest request, MediaBrowserSettings settings)
2014-08-03 07:26:55 +00:00
{
request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);
var response = _httpClient.Post(request);
_logger.Trace("Response: {0}", response.Content);
CheckForError(response);
return response.Content;
}
private HttpRequest BuildRequest(string path, MediaBrowserSettings settings)
{
var url = string.Format(@"http://{0}/mediabrowser", settings.Address);
2014-08-03 07:26:55 +00:00
return new HttpRequestBuilder(url).Resource(path).Build();
2014-08-03 07:26:55 +00:00
}
private void CheckForError(HttpResponse response)
{
_logger.Debug("Looking for error in response: {0}", response);
//TODO: actually check for the error
}
}
}