Example #1
0
        private static void Main(string[] args)
        {
            var notification = new ProwlNotification();
            var options      = new CommandOptions();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                notification.ApiKey      = options.ApiKey;
                notification.Application = options.Application;
                notification.Event       = options.Event;
                notification.Description = options.Description;
                notification.Priority    = options.Priority;
            }

            var client = new ProwlClient();

            try
            {
                client.SendNotification(notification);
                Console.WriteLine("Notification successfully sent.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }
        public void SendNotification(ProwlNotification notification)
        {
            notification.Validate();

            var notificationRequestUriString = this.CreateNotificationAddRequestUriString(notification);

            var notificationRequest = HttpWebRequest.Create(notificationRequestUriString);

            notificationRequest.ContentLength = 0;
            notificationRequest.ContentType   = "application/x-www-form-urlencoded";
            notificationRequest.Method        = "POST";

            try
            {
                using (WebResponse response = notificationRequest.GetResponse())
                {
                    var httpResponse = (HttpWebResponse)response;
                    if (httpResponse.StatusCode != HttpStatusCode.OK)
                    {
                        throw new WebException(httpResponse.StatusDescription);
                    }
                }
            }
            catch (WebException e)
            {
                using (WebResponse response = e.Response)
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;
                    throw new InvalidDataException(string.Format("An error occurred whilst sending the notification to Prowl: {0}", httpResponse.StatusDescription));
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** PROWL API TEST ***");

            var notification = new ProwlNotification()
            {
                ApiKey      = "75fcd3a230ac062616e14c15ed5f79bdb5d0d199",
                Application = "Send To Prowl",
                Event       = "Test Notification",
                Description = "Just testing notifications",
                Priority    = 1
            };

            var client = new ProwlClient();

            client.SendNotification(notification);
        }
        private string CreateNotificationAddRequestUriString(ProwlNotification notification)
        {
            var notificationAddRequestFormat = "add?apikey={0}&application={1}&description={2}&event={3}&priority={4}";

            var addCommand = new StringBuilder();

            addCommand.Append(prowlApiUrl);

            addCommand.AppendFormat(
                notificationAddRequestFormat,
                HttpUtility.UrlEncode(notification.ApiKey),
                HttpUtility.UrlEncode(notification.Application),
                HttpUtility.UrlEncode(notification.Description),
                HttpUtility.UrlEncode(notification.Event),
                notification.Priority);

            return(addCommand.ToString());
        }