示例#1
0
        public ValidationFailure TestConnection(LidarrIndexer indexer, LidarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <LidarrIndexer>(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, Lidarr 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
        public LidarrIndexer AddIndexer(LidarrIndexer indexer, LidarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            return(Execute <LidarrIndexer>(request));
        }
示例#3
0
        public LidarrIndexer UpdateIndexer(LidarrIndexer indexer, LidarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/{indexer.Id}", HttpMethod.Put);

            request.SetContent(indexer.ToJson());

            return(Execute <LidarrIndexer>(request));
        }
示例#4
0
        private HttpRequest BuildRequest(LidarrSettings 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
        public LidarrIndexer GetIndexer(int indexerId, LidarrSettings settings)
        {
            try
            {
                var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Get);
                return(Execute <LidarrIndexer>(request));
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            return(null);
        }
示例#6
0
        public List <LidarrIndexer> GetIndexerSchema(LidarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v1/indexer/schema", HttpMethod.Get);

            return(Execute <List <LidarrIndexer> >(request));
        }
示例#7
0
        public void RemoveIndexer(int indexerId, LidarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Delete);

            _httpClient.Execute(request);
        }
示例#8
0
        public LidarrStatus GetStatus(LidarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v1/system/status", HttpMethod.Get);

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