Exemplo n.º 1
0
        public ValidationFailure TestConnection(WhisparrIndexer indexer, WhisparrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <WhisparrIndexer>(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, Whisparr cannot connect to Prowlarr"));
                }

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

                _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);
        }
Exemplo n.º 2
0
        public bool Equals(WhisparrIndexer other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            var baseUrl = (string)Fields.FirstOrDefault(x => x.Name == "baseUrl").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "baseUrl").Value;
            var apiPath = (string)Fields.FirstOrDefault(x => x.Name == "apiPath").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "apiPath").Value;
            var apiKey  = (string)Fields.FirstOrDefault(x => x.Name == "apiKey").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "apiKey").Value;
            var cats    = JToken.DeepEquals((JArray)Fields.FirstOrDefault(x => x.Name == "categories").Value, (JArray)other.Fields.FirstOrDefault(x => x.Name == "categories").Value);

            return(other.EnableRss == EnableRss &&
                   other.EnableAutomaticSearch == EnableAutomaticSearch &&
                   other.EnableInteractiveSearch == EnableInteractiveSearch &&
                   other.Name == Name &&
                   other.Implementation == Implementation &&
                   other.Priority == Priority &&
                   other.Id == Id &&
                   apiKey && apiPath && baseUrl && cats);
        }