Exemple #1
0
        private void ProcessNotification(string title, string message, BoxcarSettings settings)
        {
            try
            {
                var requestBuilder = new HttpRequestBuilder(URL).Post();

                var request = requestBuilder.AddFormParameter("user_credentials", settings.Token)
                              .AddFormParameter("notification[title]", title)
                              .AddFormParameter("notification[long_message]", message)
                              .AddFormParameter("notification[source_name]", BuildInfo.AppName)
                              .AddFormParameter("notification[icon_url]", "https://raw.githubusercontent.com/Sonarr/Sonarr/phantom-develop/Logo/64.png")
                              .Build();

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

                throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
            }
        }
Exemple #2
0
        public ValidationFailure Test(BoxcarSettings settings)
        {
            try
            {
                const string title = "Test Notification";
                const string body  = "This is a test message from Sonarr";

                SendNotification(title, body, settings);
                return(null);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "Access Token is invalid");
                    return(new ValidationFailure("Token", "Access Token is invalid"));
                }

                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("Token", "Unable to send test message"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("", "Unable to send test message"));
            }
        }
Exemple #3
0
 public void SendNotification(string title, string message, BoxcarSettings settings)
 {
     try
     {
         ProcessNotification(title, message, settings);
     }
     catch (BoxcarException ex)
     {
         _logger.Error(ex, "Unable to send message");
         throw new BoxcarException("Unable to send Boxcar notifications");
     }
 }
Exemple #4
0
        public void SendNotification(string title, string message, BoxcarSettings settings)
        {
            var request = new RestRequest(Method.POST);

            try
            {
                SendNotification(title, message, request, settings);
            }
            catch (BoxcarException ex)
            {
                _logger.Error(ex, "Unable to send message");
                throw new BoxcarException("Unable to send Boxcar notifications");
            }
        }
Exemple #5
0
        private void SendNotification(string title, string message, RestRequest request, BoxcarSettings settings)
        {
            try
            {
                var client = RestClientFactory.BuildClient(URL);

                request.AddParameter("user_credentials", settings.Token);
                request.AddParameter("notification[title]", title);
                request.AddParameter("notification[long_message]", message);
                request.AddParameter("notification[source_name]", BuildInfo.AppName);
                request.AddParameter("notification[icon_url]", "https://raw.githubusercontent.com/Sonarr/Sonarr/7818f0c59b787312f0bcbc5c0eafc3c9dd7e5451/Logo/64.png");

                client.ExecuteAndValidate(request);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "Access Token is invalid");
                    throw;
                }

                throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
            }
        }
Exemple #6
0
        private void SendNotification(string title, string message, RestRequest request, BoxcarSettings settings)
        {
            try
            {
                var client = RestClientFactory.BuildClient(URL);

                request.AddParameter("user_credentials", settings.Token);
                request.AddParameter("notification[title]", title);
                request.AddParameter("notification[long_message]", message);
                request.AddParameter("notification[source_name]", "Sonarr");

                client.ExecuteAndValidate(request);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.ErrorException("Access Token is invalid: " + ex.Message, ex);
                    throw;
                }

                throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
            }
        }