コード例 #1
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public ValidationFailure TestConnection(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <SonarrIndexer>(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API Key is invalid");
                    return(new ValidationFailure("ApiKey", "API Key is invalid"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    _logger.Error(ex, "Prowlarr URL is invalid");
                    return(new ValidationFailure("ProwlarrUrl", "Prowlarr url is invalid, Sonarr cannot connect to Prowlarr"));
                }

                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("BaseUrl", "Unable to complete application test"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("", "Unable to send test message"));
            }

            return(null);
        }
コード例 #2
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public SonarrIndexer UpdateIndexer(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/{indexer.Id}", HttpMethod.Put);

            request.SetContent(indexer.ToJson());

            return(Execute <SonarrIndexer>(request));
        }
コード例 #3
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public SonarrIndexer AddIndexer(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            return(Execute <SonarrIndexer>(request));
        }
コード例 #4
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        private HttpRequest BuildRequest(SonarrSettings settings, string resource, HttpMethod method)
        {
            var baseUrl = settings.BaseUrl.TrimEnd('/');

            var request = new HttpRequestBuilder(baseUrl).Resource(resource)
                          .SetHeader("X-Api-Key", settings.ApiKey)
                          .Build();

            request.Headers.ContentType = "application/json";

            request.Method            = method;
            request.AllowAutoRedirect = true;

            return(request);
        }
コード例 #5
0
ファイル: SonarrV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public ValidationFailure TestConnection(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <SonarrIndexer>(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API Key is invalid");
                    return(new ValidationFailure("ApiKey", "API Key is invalid"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    _logger.Error(ex, "Prowlarr URL is invalid");
                    return(new ValidationFailure("ProwlarrUrl", "Prowlarr url is invalid, Sonarr cannot connect to Prowlarr"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.SeeOther)
                {
                    _logger.Error(ex, "Sonarr returned redirect and is invalid");
                    return(new ValidationFailure("BaseUrl", "Sonarr url is invalid, Prowlarr cannot connect to Sonarr - are you missing a url base?"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    _logger.Error(ex, "Sonarr not found");
                    return(new ValidationFailure("BaseUrl", "Sonarr url is invalid, Prowlarr cannot connect to Sonarr. Is Sonarr running and accessible? Sonarr v2 is not supported."));
                }

                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("BaseUrl", "Unable to complete application test"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("", "Unable to send test message"));
            }

            return(null);
        }
コード例 #6
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public SonarrIndexer GetIndexer(int indexerId, SonarrSettings settings)
        {
            try
            {
                var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Get);
                return(Execute <SonarrIndexer>(request));
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            return(null);
        }
コード例 #7
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public List <SonarrIndexer> GetIndexerSchema(SonarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v3/indexer/schema", HttpMethod.Get);

            return(Execute <List <SonarrIndexer> >(request));
        }
コード例 #8
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public void RemoveIndexer(int indexerId, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Delete);

            _httpClient.Execute(request);
        }
コード例 #9
0
ファイル: SonarrV3Proxy.cs プロジェクト: Prowlarr/Prowlarr
        public SonarrStatus GetStatus(SonarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v3/system/status", HttpMethod.Get);

            return(Execute <SonarrStatus>(request));
        }