Made the feedback from Sonarr better when Sonarr already has the series #85

This commit is contained in:
tidusjar 2016-03-29 10:34:20 +01:00
parent 5843dee2a5
commit fe0f6873e5
8 changed files with 66 additions and 19 deletions

View file

@ -26,13 +26,9 @@
#endregion
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
@ -99,17 +95,18 @@ namespace PlexRequests.Api
try
{
var json = JsonConvert.DeserializeObject<T>(response.Content);
return json;
}
catch (Exception e)
{
Log.Fatal(e);
Log.Info(response.Content);
Log.Error(e);
Log.Error(response.Content);
throw;
}
}
public T DeserializeXml<T>(string input)
private T DeserializeXml<T>(string input)
where T : class
{
var ser = new XmlSerializer(typeof(T));

View file

@ -30,6 +30,8 @@ using System.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Helpers;
using RestSharp;
namespace PlexRequests.Api
@ -56,7 +58,8 @@ namespace PlexRequests.Api
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
{
Log.Debug("Adding series {0}", title);
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
var request = new RestRequest
{
Resource = "/api/Series?",
@ -74,7 +77,6 @@ namespace PlexRequests.Api
rootFolderPath = rootPath
};
for (var i = 1; i <= seasonCount; i++)
{
var season = new Season
@ -85,11 +87,20 @@ namespace PlexRequests.Api
options.seasons.Add(season);
}
Log.Debug("Sonarr API Options:");
Log.Debug(options.DumpJson());
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options);
var obj = Api.ExecuteJson<SonarrAddSeries>(request, baseUrl);
if (obj == null)
{
var error = Api.ExecuteJson<SonarrError>(request, baseUrl);
obj = new SonarrAddSeries { ErrorMessage = error.errorMessage };
}
return obj;
}