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

@ -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;
}