Exemple #1
0
        public ValidationFailure Test(LidarrSettings settings)
        {
            try
            {
                GetArtists(settings);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API Key is invalid");
                    return(new ValidationFailure("ApiKey", "API Key is invalid"));
                }

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

            return(null);
        }
Exemple #2
0
        private List <TResource> Execute <TResource>(string resource, LidarrSettings settings)
        {
            if (settings.BaseUrl.IsNullOrWhiteSpace() || settings.ApiKey.IsNullOrWhiteSpace())
            {
                return(new List <TResource>());
            }

            var baseUrl = settings.BaseUrl.TrimEnd('/');

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

            var response = _httpClient.Get(request);

            var results = JsonConvert.DeserializeObject <List <TResource> >(response.Content);

            return(results);
        }
Exemple #3
0
 public List <LidarrProfile> GetProfiles(LidarrSettings settings)
 {
     return(Execute <LidarrProfile>("/api/v1/qualityprofile", settings));
 }
Exemple #4
0
 public List <LidarrTag> GetTags(LidarrSettings settings)
 {
     return(Execute <LidarrTag>("/api/v1/tag", settings));
 }
Exemple #5
0
 public List <LidarrArtist> GetArtists(LidarrSettings settings)
 {
     return(Execute <LidarrArtist>("/api/v1/artist", settings));
 }