Пример #1
0
        public void SendNotification(string title, string message, PushoverSettings settings)
        {
            var requestBuilder = new HttpRequestBuilder(URL).Post();

            requestBuilder.AddFormParameter("token", settings.ApiKey)
            .AddFormParameter("user", settings.UserKey)
            .AddFormParameter("device", string.Join(",", settings.Devices))
            .AddFormParameter("title", title)
            .AddFormParameter("message", message)
            .AddFormParameter("priority", settings.Priority);

            if ((PushoverPriority)settings.Priority == PushoverPriority.Emergency)
            {
                requestBuilder.AddFormParameter("retry", settings.Retry);
                requestBuilder.AddFormParameter("expire", settings.Expire);
            }

            if (!settings.Sound.IsNullOrWhiteSpace())
            {
                requestBuilder.AddFormParameter("sound", settings.Sound);
            }

            var request = requestBuilder.Build();

            _httpClient.Post(request);
        }
Пример #2
0
        public void SendNotification(string title, string message, PushoverSettings settings)
        {
            var client  = RestClientFactory.BuildClient(URL);
            var request = new RestRequest(Method.POST);

            request.AddParameter("token", settings.ApiKey);
            request.AddParameter("user", settings.UserKey);
            request.AddParameter("device", string.Join(",", settings.Devices));
            request.AddParameter("title", title);
            request.AddParameter("message", message);
            request.AddParameter("priority", settings.Priority);

            if ((PushoverPriority)settings.Priority == PushoverPriority.Emergency)
            {
                request.AddParameter("retry", settings.Retry);
                request.AddParameter("expire", settings.Expire);
            }

            if (!settings.Sound.IsNullOrWhiteSpace())
            {
                request.AddParameter("sound", settings.Sound);
            }

            client.ExecuteAndValidate(request);
        }
Пример #3
0
        public ValidationFailure Test(PushoverSettings settings)
        {
            try
            {
                const string title = "Test Notification";
                const string body  = "This is a test message from Readarr";

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

            return(null);
        }
Пример #4
0
        public ValidationFailure Test(PushoverSettings settings)
        {
            try
            {
                const string title = "Test Notification";
                const string body  = "This is a test message from NzbDrone";

                SendNotification(title, body, settings.ApiKey, settings.UserKey, (PushoverPriority)settings.Priority, settings.Sound);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to send test message: " + ex.Message, ex);
                return(new ValidationFailure("ApiKey", "Unable to send test message"));
            }

            return(null);
        }