Exemple #1
0
        private void ProcessNotification(StringDictionary message, NotifiarrSettings settings)
        {
            try
            {
                var requestBuilder = new HttpRequestBuilder(URL).Post();
                requestBuilder.AddFormParameter("api", settings.APIKey).Build();

                foreach (string key in message.Keys)
                {
                    requestBuilder.AddFormParameter(key, message[key]);
                }

                var request = requestBuilder.Build();

                _httpClient.Post(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    _logger.Error(ex, "API key is invalid");
                    throw;
                }

                throw new NotifiarrException("Unable to send notification", ex);
            }
        }
Exemple #2
0
        public ValidationFailure Test(NotifiarrSettings settings)
        {
            try
            {
                var variables = new StringDictionary();
                variables.Add("Readarr_EventType", "Test");

                SendNotification(variables, settings);
                return(null);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API key is invalid: " + ex.Message);
                    return(new ValidationFailure("APIKey", "API key is invalid"));
                }

                _logger.Error(ex, "Unable to send test message: " + ex.Message);
                return(new ValidationFailure("APIKey", "Unable to send test notification"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test notification: " + ex.Message);
                return(new ValidationFailure("", "Unable to send test notification"));
            }
        }
Exemple #3
0
 public void SendNotification(StringDictionary message, NotifiarrSettings settings)
 {
     try
     {
         ProcessNotification(message, settings);
     }
     catch (NotifiarrException ex)
     {
         _logger.Error(ex, "Unable to send notification");
         throw new NotifiarrException("Unable to send notification");
     }
 }
Exemple #4
0
        private void ProcessNotification(StringDictionary message, NotifiarrSettings settings)
        {
            try
            {
                var url            = settings.Environment == (int)NotifiarrEnvironment.Development ? "https://dev.notifiarr.com" : "https://notifiarr.com";
                var requestBuilder = new HttpRequestBuilder(url + "/notifier.php").Post();
                requestBuilder.AddFormParameter("api", settings.APIKey).Build();
                requestBuilder.AddFormParameter("instanceName", settings.InstanceName).Build();

                foreach (string key in message.Keys)
                {
                    requestBuilder.AddFormParameter(key, message[key]);
                }

                var request = requestBuilder.Build();

                _httpClient.Post(request);
            }
            catch (HttpException ex)
            {
                switch ((int)ex.Response.StatusCode)
                {
                case 401:
                    _logger.Error(ex, "API key is invalid");
                    throw;

                case 400:
                case 520:
                case 521:
                case 522:
                case 523:
                case 524:
                    _logger.Error(ex, "Unable to send notification");
                    throw;
                }

                throw new NotifiarrException("Unable to send notification", ex);
            }
        }
Exemple #5
0
        public ValidationFailure Test(NotifiarrSettings settings)
        {
            try
            {
                var variables = new StringDictionary();
                variables.Add("Radarr_EventType", "Test");

                SendNotification(variables, settings);
                return(null);
            }
            catch (HttpException ex)
            {
                switch ((int)ex.Response.StatusCode)
                {
                case 401:
                    _logger.Error(ex, "API key is invalid: " + ex.Message);
                    return(new ValidationFailure("APIKey", "API key is invalid"));

                case 400:
                case 520:
                case 521:
                case 522:
                case 523:
                case 524:
                    _logger.Error(ex, "Unable to send test notification: " + ex.Message);
                    return(new ValidationFailure("", "Unable to send test notification"));
                }

                _logger.Error(ex, "Unable to send test message: " + ex.Message);
                return(new ValidationFailure("APIKey", "Unable to send test notification"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test notification: " + ex.Message);
                return(new ValidationFailure("", "Unable to send test notification"));
            }
        }