Пример #1
0
        public void SendNotification(string title, string message, PushalotSettings settings)
        {
            var client = RestClientFactory.BuildClient(URL);
            var request = BuildRequest();

            request.AddParameter("Source", "Sonarr");

            if (settings.Image)
            {
                request.AddParameter("Image", "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/128.png");
            }

            request.AddParameter("Title", title);
            request.AddParameter("Body", message);
            request.AddParameter("AuthorizationToken", settings.AuthToken);

            if ((PushalotPriority)settings.Priority == PushalotPriority.Important)
            {
                request.AddParameter("IsImportant", true);
            }

            if ((PushalotPriority)settings.Priority == PushalotPriority.Silent)
            {
                request.AddParameter("IsSilent", true);
            }

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

                SendNotification(title, body, settings);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "Authentication Token is invalid: " + ex.Message);
                    return new ValidationFailure("AuthToken", "Authentication Token is invalid");
                }

                if (ex.Response.StatusCode == HttpStatusCode.NotAcceptable)
                {
                    _logger.Error(ex, "Message limit reached: " + ex.Message);
                    return new ValidationFailure("AuthToken", "Message limit reached");
                }

                if (ex.Response.StatusCode == HttpStatusCode.Gone)
                {
                    _logger.Error(ex, "Authorization Token is no longer valid: " + ex.Message);
                    return new ValidationFailure("AuthToken", "Authorization Token is no longer valid, please use a new one.");
                }

                var response = Json.Deserialize<PushalotResponse>(ex.Response.Content);

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

            return null;
        }