Esempio n. 1
0
        private static string GetBaseURL(RadarrSettings settings)
        {
            var version  = settings.Version == "2" ? string.Empty : $"/v{settings.Version}";
            var protocol = settings.UseSSL ? "https" : "http";

            return($"{protocol}://{settings.Hostname}:{settings.Port}/api{version}");
        }
Esempio n. 2
0
        public static async Task <IList <JSONProfile> > GetProfiles(HttpClient httpClient, ILogger <Radarr> logger, RadarrSettings settings)
        {
            var retryCount = 0;

            while (retryCount <= 5)
            {
                try
                {
                    var profileUri = settings.Version == "2" ? "/profile" : $"/qualityprofile";
                    var response   = await HttpGetAsync(httpClient, settings, $"{GetBaseURL(settings)}{profileUri}");

                    var jsonResponse = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <IList <JSONProfile> >(jsonResponse));
                }
                catch (System.Exception ex)
                {
                    logger.LogWarning("An error while getting Radarr profiles: " + ex.Message);
                    retryCount++;
                    await Task.Delay(1000);
                }
            }

            throw new System.Exception("An error occurred while getting Radarr profiles");
        }
Esempio n. 3
0
        public static async Task <IList <JSONRootPath> > GetRootPaths(HttpClient httpClient, ILogger <Radarr> logger, RadarrSettings settings)
        {
            var retryCount = 0;

            while (retryCount <= 5)
            {
                try
                {
                    var response = await HttpGetAsync(httpClient, settings, $"{GetBaseURL(settings)}/rootfolder");

                    var jsonResponse = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <IList <JSONRootPath> >(jsonResponse));
                }
                catch (System.Exception ex)
                {
                    logger.LogWarning("An error while getting Radarr root paths: " + ex.Message);
                    retryCount++;
                    await Task.Delay(1000);
                }
            }

            throw new System.Exception("An error occurred while getting Radarr root paths");
        }
Esempio n. 4
0
        private static async Task <HttpResponseMessage> HttpGetAsync(HttpClient client, RadarrSettings settings, string url)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, url);

            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("X-Api-Key", settings.ApiKey);

            return(await client.SendAsync(request));
        }
Esempio n. 5
0
        public static async Task TestConnectionAsync(HttpClient httpClient, ILogger <Radarr> logger, RadarrSettings settings)
        {
            var testSuccessful = false;

            try
            {
                var response = await HttpGetAsync(httpClient, settings, $"{GetBaseURL(settings)}/system/status");

                testSuccessful = response.IsSuccessStatusCode;
            }
            catch (System.Exception ex)
            {
                logger.LogWarning("Error while testing Radarr connection: " + ex.Message);
                throw new Exception("Could not connect to Radarr");
            }

            if (!testSuccessful)
            {
                throw new Exception("Could not connect to Radarr");
            }
        }