Ejemplo n.º 1
0
        public void SendNotification(string title, string message, GotifySettings settings)
        {
            var client  = RestClientFactory.BuildClient(settings.Server);
            var request = new RestRequest("message", Method.POST);

            request.AddQueryParameter("token", settings.AppToken);
            request.AddParameter("title", title);
            request.AddParameter("message", message);
            request.AddParameter("priority", settings.Priority);

            client.ExecuteAndValidate(request);
        }
Ejemplo n.º 2
0
        public void SendNotification(string title, string message, GotifySettings settings)
        {
            try
            {
                var request = new HttpRequestBuilder(settings.Server).Resource("message").Post()
                              .AddQueryParam("token", settings.AppToken)
                              .AddFormParameter("title", title)
                              .AddFormParameter("message", message)
                              .AddFormParameter("priority", settings.Priority)
                              .Build();

                _httpClient.Execute(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    throw new GotifyException("Unauthorized - AuthToken is invalid");
                }

                throw new GotifyException("Unable to connect to Gotify. Status Code: {0}", ex.Response.StatusCode);
            }
        }