Пример #1
0
        public List <Series> GetSeries(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/series", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);
            try
            {
                var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(5)
                });

                var series = policy.Execute(() => Api.ExecuteJson <List <Series> >(request, baseUrl));

                // Remove the 'specials from the object'
                foreach (var s in series)
                {
                    var seasonToRemove = s.seasons.FirstOrDefault(x => x.seasonNumber == 0);
                    if (seasonToRemove != null)
                    {
                        s.seasons.Remove(seasonToRemove);
                    }
                }
                return(series);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when getting the Sonarr Series");
                return(null);
            }
        }
Пример #2
0
        public SonarrSeriesSearchResult SearchForSeries(int seriesId, string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/Command", Method = Method.POST
            };

            request.AddHeader("X-Api-Key", apiKey);

            var body = new SonarrSearchCommand
            {
                name     = "SeriesSearch",
                seriesId = seriesId
            };

            request.AddJsonBody(body);

            try
            {
                var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
                                                             Log.Error(exception, "Exception when calling SearchForSeries for Sonarr, Retrying {0}", timespan));

                return(policy.Execute(() => Api.ExecuteJson <SonarrSeriesSearchResult>(request, baseUrl)));
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when put the Sonarr SearchForSeries");
                return(null);
            }
        }
Пример #3
0
        public Series GetSeries(string seriesId, string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/series/{seriesId}", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);
            request.AddUrlSegment("seriesId", seriesId);
            try
            {
                var policy =
                    RetryHandler.RetryAndWaitPolicy(
                        (exception, timespan) =>
                        Log.Error(exception, "Exception when calling GetSeries by ID for Sonarr, Retrying {0}",
                                  timespan));

                var series = policy.Execute(() => Api.ExecuteJson <Series>(request, baseUrl));

                // Remove the specials season
                var toRemove = series.seasons.FirstOrDefault(x => x.seasonNumber == 0);
                if (toRemove != null)
                {
                    series.seasons.Remove(toRemove);
                }
                return(series);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when getting the Sonarr Series by ID");
                return(null);
            }
        }
Пример #4
0
        public PlexSearch GetAllEpisodes(string authToken, Uri host, string section, int startPage, int returnCount)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "/library/sections/{section}/all"
            };

            request.AddQueryParameter("type", 4.ToString());
            AddLimitHeaders(ref request, startPage, returnCount);
            request.AddUrlSegment("section", section);
            AddHeaders(ref request, authToken, false);

            try
            {
                var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch>(request, host),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetAllEpisodes for Plex, Retrying {0}", timespan));

                return(lib);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been a API Exception when attempting to get GetAllEpisodes");
                return(new PlexSearch());
            }
        }
Пример #5
0
        public EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri)
        {
            var request = new RestRequest
            {
                Resource = "emby/users/authenticatebyname",
                Method   = Method.POST
            };

            var body = new
            {
                username,
                password    = StringHasher.GetSha1Hash(password).ToLower(),
                passwordMd5 = StringHasher.CalcuateMd5Hash(password)
            };

            request.AddJsonBody(body);

            request.AddHeader("X-Emby-Authorization",
                              $"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"{AssemblyHelper.GetProductVersion()}\", Version=\"{AssemblyHelper.GetAssemblyVersion()}\"");
            AddHeaders(request, apiKey);


            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling LogInfor Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1)
            });

            var obj = policy.Execute(() => Api.Execute(request, baseUri));

            if (obj.StatusCode == HttpStatusCode.Unauthorized)
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <EmbyUserLogin>(obj.Content)?.User);
        }
Пример #6
0
        public PlexRecentlyAddedModel RecentlyAdded(string authToken, Uri plexFullHost, string sectionId)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "library/sections/{sectionId}/recentlyAdded"
            };

            request.AddUrlSegment("sectionId", sectionId);
            AddHeaders(ref request, authToken, true);
            AddLimitHeaders(ref request, 0, 25);

            try
            {
                var lib = RetryHandler.Execute(() => Api.ExecuteJson <PlexRecentlyAddedModel>(request, plexFullHost),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling PlexRecentlyAddedModel for Plex, Retrying {0}", timespan), new[] {
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(30)
                });

                return(lib);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been a API Exception when attempting to get the Plex RecentlyAddedModel");
                return(new PlexRecentlyAddedModel());
            }
        }
Пример #7
0
        public PlexSeasonMetadata GetSeasons(string authToken, Uri plexFullHost, string ratingKey)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "library/metadata/{ratingKey}/children"
            };

            request.AddUrlSegment("ratingKey", ratingKey);
            AddHeaders(ref request, authToken, false);

            try
            {
                var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSeasonMetadata>(request, plexFullHost),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetMetadata for Plex, Retrying {0}", timespan), new[] {
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(30)
                });

                return(lib);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been a API Exception when attempting to get the Plex GetMetadata");
                return(new PlexSeasonMetadata());
            }
        }
Пример #8
0
        public PlexEpisodeMetadata GetEpisodeMetaData(string authToken, Uri host, string ratingKey)
        {
            //192.168.1.69:32400/library/metadata/3662/allLeaves
            // The metadata ratingkey should be in the Cache
            // Search for it and then call the above with the Directory.RatingKey
            // THEN! We need the episode metadata using result.Vide.Key ("/library/metadata/3664")
            // We then have the GUID which contains the TVDB ID plus the season and episode number: guid="com.plexapp.agents.thetvdb://269586/2/8?lang=en"
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "/library/metadata/{ratingKey}"
            };

            request.AddUrlSegment("ratingKey", ratingKey);
            AddHeaders(ref request, authToken, false);

            try
            {
                var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexEpisodeMetadata>(request, host),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetEpisodeMetaData for Plex, Retrying {0}", timespan));

                return(lib);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been a API Exception when attempting to get GetEpisodeMetaData");
                return(new PlexEpisodeMetadata());
            }
        }
Пример #9
0
        public PlexSearch GetLibrary(string authToken, Uri plexFullHost, string libraryId)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "library/sections/{libraryId}/all"
            };

            request.AddUrlSegment("libraryId", libraryId);
            AddHeaders(ref request, authToken, false);

            try
            {
                var lib = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch> (request, plexFullHost),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan), new TimeSpan[] {
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(30)
                });

                return(lib);
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been a API Exception when attempting to get the Plex Library");
                return(new PlexSearch());
            }
        }
Пример #10
0
        public CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status)
        {
            var request = new RestRequest
            {
                Resource = "/api/{apikey}/movie.list?status={status}",
                OnBeforeDeserialization = (x =>
                {
                    x.Content = x.Content.Replace("[]", "{}");
                })
            };

            request.AddUrlSegment("apikey", apiKey);
            request.AddUrlSegment("status", string.Join(",", status));
            try
            {
                var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoMovies>(request, baseUrl),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan), new[] {
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(30)
                });

                return(obj);
            }
            catch (Exception e) // Request error is already logged in the ApiRequest class
            {
                Log.Error("Error when attempting to GetMovies.");
                Log.Error(e);
                return(new CouchPotatoMovies());
            }
        }
Пример #11
0
        public SickRagePing Ping(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/{apiKey}/?cmd=sb.ping", Method = Method.GET
            };

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling Ping for SR, Retrying {0}", timespan), null);

            request.AddUrlSegment("apiKey", apiKey);
            var obj = policy.Execute(() => Api.ExecuteJson <SickRagePing>(request, baseUrl));

            return(obj);
        }
Пример #12
0
        public PlexStatus GetStatus(string authToken, Uri uri)
        {
            var request = new RestRequest
            {
                Method = Method.GET,
            };

            AddHeaders(ref request, authToken, false);

            var users = RetryHandler.Execute(() => Api.ExecuteXml <PlexStatus> (request, uri),
                                             (exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan), null);

            return(users);
        }
Пример #13
0
        public PlexAccount GetAccount(string authToken)
        {
            var request = new RestRequest
            {
                Method = Method.GET,
            };

            AddHeaders(ref request, authToken, false);

            var account = RetryHandler.Execute(() => Api.ExecuteXml <PlexAccount> (request, new Uri(GetAccountUri)),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetAccount for Plex, Retrying {0}", timespan), null);

            return(account);
        }
Пример #14
0
        public CouchPotatoProfiles GetProfiles(Uri url, string apiKey)
        {
            var request = new RestRequest
            {
                Resource = "api/{apikey}/profile.list/",
                Method   = Method.GET
            };

            request.AddUrlSegment("apikey", apiKey);

            var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoProfiles>(request, url),
                                           (exception, timespan) => Log.Error(exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan), null);

            return(obj);
        }
Пример #15
0
        public PlexServer GetServer(string authToken)
        {
            var request = new RestRequest
            {
                Method = Method.GET,
            };

            AddHeaders(ref request, authToken, false);

            var servers = RetryHandler.Execute(() => Api.ExecuteXml <PlexServer>(request, new Uri(ServerUri)),
                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetServer for Plex, Retrying {0}", timespan));


            return(servers);
        }
Пример #16
0
        public CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
        {
            var request = new RestRequest
            {
                Resource = "getkey/?u={username}&p={password}",
                Method   = Method.GET
            };

            request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
            request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));

            var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoApiKey>(request, baseUrl),
                                           (exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);

            return(obj);
        }
Пример #17
0
        public List <SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/rootfolder", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);
            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Radarr, Retrying {0}", timespan), new TimeSpan[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2)
            });

            var obj = policy.Execute(() => Api.ExecuteJson <List <SonarrRootFolder> >(request, baseUrl));

            return(obj);
        }
Пример #18
0
        /// <summary>
        /// Gets the users.
        /// </summary>
        /// <param name="authToken">The authentication token.</param>
        /// <param name="searchTerm">The search term.</param>
        /// <param name="plexFullHost">The full plex host.</param>
        /// <returns></returns>
        public PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = "search?query={searchTerm}"
            };

            request.AddUrlSegment("searchTerm", searchTerm);
            AddHeaders(ref request, authToken, false);

            var search = RetryHandler.Execute(() => Api.ExecuteXml <PlexSearch> (request, plexFullHost),
                                              (exception, timespan) => Log.Error(exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan), null);

            return(search);
        }
Пример #19
0
        public List <RadarrMovieResponse> GetMovies(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/movie", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(10)
            });

            var obj = policy.Execute(() => Api.Execute(request, baseUrl));

            return(JsonConvert.DeserializeObject <List <RadarrMovieResponse> >(obj.Content));
        }
Пример #20
0
        /// <summary>
        /// Returns all users from the Emby Instance
        /// </summary>
        /// <param name="baseUri"></param>
        /// <param name="apiKey"></param>
        public List <EmbyUser> GetUsers(Uri baseUri, string apiKey)
        {
            var request = new RestRequest
            {
                Resource = "emby/users",
                Method   = Method.GET
            };

            AddHeaders(request, apiKey);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetUsers for Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1),
            });

            var obj = policy.Execute(() => Api.ExecuteJson <List <EmbyUser> >(request, baseUri));

            return(obj);
        }
Пример #21
0
        public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/system/status", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling SystemStatus for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(10)
            });

            var obj = policy.Execute(() => Api.ExecuteJson <SystemStatus>(request, baseUrl));

            return(obj);
        }
Пример #22
0
        public EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl)
        {
            var request = new RestRequest
            {
                Resource = "emby/System/Info",
                Method   = Method.GET
            };

            AddHeaders(request, apiKey);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(5)
            });

            var obj = policy.Execute(() => Api.ExecuteJson <EmbySystemInfo>(request, baseUrl));

            return(obj);
        }
Пример #23
0
        public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileId = default(string))
        {
            RestRequest request;

            request = string.IsNullOrEmpty(profileId)
                ? new RestRequest {
                Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}"
            }
                : new RestRequest {
                Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}&profile_id={profileId}"
            };

            if (!string.IsNullOrEmpty(profileId))
            {
                request.AddUrlSegment("profileId", profileId);
            }

            request.AddUrlSegment("apikey", apiKey);
            request.AddUrlSegment("imdbid", imdbid);
            request.AddUrlSegment("title", title);

            var obj = RetryHandler.Execute(() => Api.ExecuteJson <JObject>(request, baseUrl),
                                           (exception, timespan) => Log.Error(exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(2)
            });


            if (obj.Count > 0)
            {
                try
                {
                    var result = (bool)obj["success"];
                    return(result);
                }
                catch (Exception e)
                {
                    Log.Fatal(e);
                    return(false);
                }
            }
            return(false);
        }
Пример #24
0
        //https://ci.appveyor.com/api/projects/tidusjar/requestplex/history?recordsNumber=10&branch=eap
        public AppveyorProjects GetProjectHistory(string branchName, int records = 10)
        {
            var request = new RestRequest
            {
                Resource = "projects/tidusjar/requestplex/history?recordsNumber={records}&branch={branch}",
                Method   = Method.GET
            };

            request.AddUrlSegment("records", records.ToString());
            request.AddUrlSegment("branch", branchName);
            AddHeaders(request);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetProjectHistory for Appveyor, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1),
            });

            var obj = policy.Execute(() => Api.ExecuteJson <AppveyorProjects>(request, new Uri(AppveyorApiUrl)));

            return(obj);
        }
Пример #25
0
        public EmbyItemContainer <EmbyLibrary> ViewLibrary(string apiKey, string userId, Uri baseUri)
        {
            var request = new RestRequest
            {
                Resource = "emby/users/{userId}/items",
                Method   = Method.GET
            };

            request.AddUrlSegment("userId", userId);
            AddHeaders(request, apiKey);

            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling ViewLibrary for Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(5)
            });

            var obj = policy.Execute(() => Api.ExecuteJson <EmbyItemContainer <EmbyLibrary> >(request, baseUri));

            return(obj);
        }
Пример #26
0
        /// <summary>
        /// Gets the status.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="apiKey">The API key.</param>
        /// <returns></returns>
        public CouchPotatoStatus GetStatus(Uri url, string apiKey)
        {
            var request = new RestRequest
            {
                Resource = "api/{apikey}/app.available/",
                Method   = Method.GET
            };

            request.AddUrlSegment("apikey", apiKey);


            var obj = RetryHandler.Execute <CouchPotatoStatus>(() => Api.Execute <CouchPotatoStatus>(request, url),
                                                               (exception, timespan) => Log.Error(exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan), new TimeSpan[] {
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(10)
            });

            return(obj);
        }
Пример #27
0
        public EmbyItemContainer <EmbyMovieInformation> GetCollection(string mediaId, string apiKey, string userId, Uri baseUrl)
        {
            var request = new RestRequest
            {
                Resource = "emby/users/{userId}/items?parentId={mediaId}",
                Method   = Method.GET
            };

            request.AddUrlSegment("userId", userId);
            request.AddUrlSegment("mediaId", mediaId);

            AddHeaders(request, apiKey);


            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetCollections for Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(5)
            });

            return(policy.Execute(() => Api.ExecuteJson <EmbyItemContainer <EmbyMovieInformation> >(request, baseUrl)));
        }
Пример #28
0
        public SonarrEpisodes UpdateEpisode(SonarrEpisodes episodeInfo, string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/Episode", Method = Method.PUT
            };

            request.AddHeader("X-Api-Key", apiKey);
            request.AddJsonBody(episodeInfo);
            try
            {
                var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
                                                             Log.Error(exception, "Exception when calling UpdateEpisode for Sonarr, Retrying {0}", timespan));

                return(policy.Execute(() => Api.ExecuteJson <SonarrEpisodes>(request, baseUrl)));
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when put the Sonarr UpdateEpisode");
                return(null);
            }
        }
Пример #29
0
        /// <summary>
        /// Returns the episode with the matching id.
        /// </summary>
        /// <param name="episodeId">The episode identifier.</param>
        /// <param name="apiKey">The API key.</param>
        /// <param name="baseUrl">The base URL.</param>
        /// <returns></returns>
        public SonarrEpisode GetEpisode(string episodeId, string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/Episode/{episodeId}", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);
            request.AddUrlSegment("episodeId", episodeId);
            try
            {
                var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
                                                             Log.Error(exception, "Exception when calling GetEpisode by ID for Sonarr, Retrying {0}", timespan));

                return(policy.Execute(() => Api.ExecuteJson <SonarrEpisode>(request, baseUrl)));
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisode by ID");
                return(null);
            }
        }
Пример #30
0
        /// <summary>
        /// Returns all episodes for the given series.
        /// </summary>
        /// <param name="seriesId">The series identifier.</param>
        /// <param name="apiKey">The API key.</param>
        /// <param name="baseUrl">The base URL.</param>
        /// <returns></returns>
        public IEnumerable <SonarrEpisodes> GetEpisodes(string seriesId, string apiKey, Uri baseUrl)
        {
            var request = new RestRequest {
                Resource = "/api/Episode", Method = Method.GET
            };

            request.AddHeader("X-Api-Key", apiKey);
            request.AddQueryParameter("seriesId", seriesId);
            try
            {
                var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) =>
                                                             Log.Error(exception, "Exception when calling GetEpisodes for Sonarr, Retrying {0}", timespan));

                return(policy.Execute(() => Api.ExecuteJson <List <SonarrEpisodes> >(request, baseUrl)));
            }
            catch (Exception e)
            {
                Log.Error(e, "There has been an API exception when getting the Sonarr GetEpisodes");
                return(null);
            }
        }