@ -30,6 +30,8 @@ using System.Linq;
using NLog ;
using NLog ;
using PlexRequests.Api.Interfaces ;
using PlexRequests.Api.Interfaces ;
using PlexRequests.Api.Models.Sonarr ;
using PlexRequests.Api.Models.Sonarr ;
using PlexRequests.Helpers ;
using RestSharp ;
using RestSharp ;
namespace PlexRequests.Api
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 )
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
var request = new RestRequest
{
{
Resource = "/api/Series?" ,
Resource = "/api/Series?" ,
@ -74,7 +77,6 @@ namespace PlexRequests.Api
rootFolderPath = rootPath
rootFolderPath = rootPath
} ;
} ;
for ( var i = 1 ; i < = seasonCount ; i + + )
for ( var i = 1 ; i < = seasonCount ; i + + )
{
{
var season = new Season
var season = new Season
@ -85,11 +87,20 @@ namespace PlexRequests.Api
options . seasons . Add ( season ) ;
options . seasons . Add ( season ) ;
}
}
Log . Debug ( "Sonarr API Options:" ) ;
Log . Debug ( options . DumpJson ( ) ) ;
request . AddHeader ( "X-Api-Key" , apiKey ) ;
request . AddHeader ( "X-Api-Key" , apiKey ) ;
request . AddJsonBody ( options ) ;
request . AddJsonBody ( options ) ;
var obj = Api . ExecuteJson < SonarrAddSeries > ( request , baseUrl ) ;
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 ;
return obj ;
}
}