コード例 #1
0
        //public enum Priority { ProwlNotificationPriority.
        public static void Send(string msgDescription, string msgEvent, Priority msgPriority)
        {
            // Before posting a notification,
            // check out the [app.config] file to configure the Prowl client.
            try
            {
                // Create a notification.
                var notification = new ProwlNotification();

                notification.Description = msgDescription;
                notification.Event       = msgEvent;
                notification.Priority    = (ProwlNotificationPriority)msgPriority;
                // Create the Prowl client.
                // By default, the Prowl client will attempt to load configuration
                // from the configuration file (app.config).  You can use an overloaded constructor
                // to configure the client directly and bypass the configuration file.
                var clientCfg = new ProwlClientConfiguration();
                clientCfg.ApiKeychain     = API_KEY;
                clientCfg.ApplicationName = "Copper Hedge";

                var prowlClient = new ProwlClient(clientCfg);

                // Post the notification.
                prowlClient.PostNotification(notification);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        public virtual bool Verify(string apiKey)
        {
            try
            {
                var verificationRequest = new Verification();
                verificationRequest.ApiKey = apiKey;

                var client = new ProwlClient();

                Logger.Trace("Verifying API Key: {0}", apiKey);

                var verificationResult = client.SendVerification(verificationRequest);
                if (String.IsNullOrWhiteSpace(verificationResult.ErrorMessage) && verificationResult.ResultCode == "200")
                {
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Logger.TraceException(ex.Message, ex);
                Logger.Warn("Invalid API Key: {0}", apiKey);
            }

            return(false);
        }
コード例 #3
0
ファイル: ProwlService.cs プロジェクト: zobe123/Lidarr
        public void SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Prowlin.Notification
                {
                    Application = BuildInfo.AppName,
                    Description = message,
                    Event       = title,
                    Priority    = priority,
                    Url         = url
                };

                notification.AddApiKey(apiKey.Trim());

                var client = new ProwlClient();

                _logger.Debug("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (!string.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                {
                    throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
                }
            }

            catch (Exception ex)
            {
                _logger.Debug(ex, ex.Message);
                _logger.Warn("Invalid API Key: {0}", apiKey);
            }
        }
コード例 #4
0
ファイル: ProwlService.cs プロジェクト: zobe123/Lidarr
        public void Verify(string apiKey)
        {
            try
            {
                var verificationRequest = new Verification();
                verificationRequest.ApiKey = apiKey;

                var client = new ProwlClient();

                _logger.Debug("Verifying API Key: {0}", apiKey);

                var verificationResult = client.SendVerification(verificationRequest);
                if (!string.IsNullOrWhiteSpace(verificationResult.ErrorMessage) &&
                    verificationResult.ResultCode != "200")
                {
                    throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
                }
            }

            catch (Exception ex)
            {
                _logger.Debug(ex, ex.Message);
                _logger.Warn("Invalid API Key: {0}", apiKey);
                throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: sven-s/ProwlNotifier
        private static void Main(string[] args)
        {
            var show_help = false;
            var apikey = "";
            var applicationName = "Default";
            var eventName = "Default";
            var show_timestamp = false;

            var p = new OptionSet
                    {
                        {
                            "a|apikey=", "the {APIKEY} for Prowl.", v =>
                            {
                                if (v == null)
                                {
                                    throw new OptionException("Missing api key for option -a", "-a");
                                }
                                apikey = v;
                            }
                        },
                        { "n|name=", "the {NAME} of the application that sends the notification.", v => applicationName = v },
                        { "e|event=", "the {EVENT} of the notification.", v => eventName = (v ?? "Default") },
                        { "d|datetime=", "shows a timestamp with the message.", v => show_timestamp = v != null },
                        { "h|help", "show this message and exit", v => show_help = v != null },
                    };

            List<string> extra;
            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("prowlNotifier: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'prowlNotifier --help' for more information.");
                return;
            }

            if (show_help || string.IsNullOrEmpty(apikey))
            {
                ShowHelp(p);
                return;
            }

            // Create and send the notification.
            var message = string.Join(" ", extra.ToArray());
            if (string.IsNullOrEmpty(message))
            {
                message = "Test";
            }

            if (show_timestamp) message = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " " + message;

            var notification = new ProwlNotification { Description = message, Event = eventName, Priority = ProwlNotificationPriority.Normal };

            var client = new ProwlClient(new ProwlClientConfiguration { ApiKeychain = apikey, ApplicationName = applicationName });
            client.PostNotification(notification);
        }
コード例 #6
0
        public void ReturnsNegativeOneWhenThereAreNoKeys()
        {
            ProwlClient client = new ProwlClient();

            int expected = -1;
            int actual   = client.Send("app", 0, "app://", "app-subject", "app-message");

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        private void startProwl(string applicationName)
        {
            var config = new ProwlClientConfiguration();

            config.ApplicationName = applicationName;
            config.ApiKeychain     = "75fcd3a230ac062616e14c15ed5f79bdb5d0d199";
            config.BaseUrl         = "https://api.prowlapp.com/publicapi";
            config.ProviderKey     = "";
            _prowl = new ProwlClient(config);
        }
コード例 #8
0
        public ProwlPub(string apiKey, string appName = "(general)")
        {
            var configuration = new ProwlClientConfiguration();

            // Provider keys are used by developers to allow applications to connect with Prowl with an
            // increased request limit and allow for retrieving new API keys from user's accounts.
            //configuration.ProviderKey = apiKey;
            configuration.ApiKeychain     = apiKey;
            configuration.ApplicationName = appName;
            m_prowl = new ProwlClient(configuration);
        }
コード例 #9
0
        public void RetrieveApiKey_should_call_RetrieveApikey_on_HttpInterface()
        {
            FakeHttpInterface fakeHttpInterface = new FakeHttpInterface();
            ProwlClient       client            = new ProwlClient(fakeHttpInterface);

            RetrieveApikey retrieveApikey = new RetrieveApikey()
            {
                ProviderKey = "1234567890123456789012345678901234567890",
                Token       = "1234567890123456789012345678901234567890"
            };

            client.RetrieveApikey(retrieveApikey);
        }
コード例 #10
0
        public void Verification_apikey_wrong_length_throws_validation_ArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var verification = new Verification
            {
                ApiKey = "12345678678901234567890"
            };

            Assert.Throws(typeof(ArgumentException),
                          delegate { prowlClient.SendVerification(verification); });
        }
コード例 #11
0
        public void RetrieveToken_should_call_RetriveToken_on_HttpInterface()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var retriveTokenMessage = new RetrieveToken()
            {
                ProviderKey = "1234567890123456789012345678901234567890"
            };

            prowlClient.RetreiveToken(retriveTokenMessage);

            Assert.True(fakeHttpInterface.RetrieveTokenCalled);
        }
コード例 #12
0
        public void SendVerification_should_call_SendVerification_on_HttpInterface()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var verification = new Verification
            {
                ApiKey      = "1234567890123456789012345678901234567890",
                ProviderKey = "ewrwe"
            };

            prowlClient.SendVerification(verification);
            Assert.True(fakeHttpInterface.SendVerificationCalled);
        }
コード例 #13
0
        public void RetrieveApiKey_should_return_correct_fake_data()
        {
            FakeHttpInterface fakeHttpInterface = new FakeHttpInterface();
            ProwlClient       client            = new ProwlClient(fakeHttpInterface);

            RetrieveApikey retrieveApikey = new RetrieveApikey()
            {
                ProviderKey = "1234567890123456789012345678901234567890",
                Token       = "1234567890123456789012345678901234567890"
            };
            RetrieveApikeyResult retrieveApikeyResult = client.RetrieveApikey(retrieveApikey);

            Assert.Equal("0987654321098765432109876543210987654321", retrieveApikeyResult.ApiKey);
        }
コード例 #14
0
        public void Execute(params object[] list)
        {
            INotification notification = new Prowlin.Notification()
            {
                Application = "FeuerwehrCloud",
                Description = (string)list[1],
                Event       = (string)list[0],
                Priority    = NotificationPriority.Emergency,
                Url         = "https://" + System.Environment.MachineName + ".feuerwehrcloud.de:10443/alert.php?alerid=" + (string)list[2]
            };

            notification.AddApiKey("6b9ea4e98c84381c2606dd3ec48ea1033a4d127a");
            ProwlClient        prowlClient        = new ProwlClient();
            NotificationResult notificationResult = prowlClient.SendNotification(notification);
        }
コード例 #15
0
        public void no_application_should_not_pass_validation_and_throw_ArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var n = new Notification
            {
                Description = "foo",
                Event       = "event",
                Priority    = NotificationPriority.Normal,
                Url         = "http://www.nnihle.com/blog"
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            Assert.Throws(typeof(ArgumentException), delegate { prowlClient.SendNotification(n); });
        }
コード例 #16
0
        public void RetrieveToken_WithLongProviderKey_ShouldTrhowArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var retriveTokenMessage = new RetrieveToken()
            {
                ProviderKey = "12345678901234567890123456789012345678901290"
            };

            Assert.Throws(typeof(ArgumentException), delegate
            {
                prowlClient.RetreiveToken(retriveTokenMessage);
            });

            Assert.False(fakeHttpInterface.RetrieveTokenCalled);
        }
コード例 #17
0
ファイル: ProwlJob.cs プロジェクト: The-Stig/AlarmWorkflow
        bool IJob.Initialize()
        {
            try
            {
                pcconfig = new ProwlClientConfiguration();

                pcconfig.ApplicationName = SettingsManager.Instance.GetSetting("ProwlJob", "ApplicationName").GetString();
                pcconfig.ProviderKey     = SettingsManager.Instance.GetSetting("ProwlJob", "ProviderKey").GetString();
                pcconfig.ApiKeychain     = SettingsManager.Instance.GetSetting("ProwlJob", "API").GetString();

                pclient = new ProwlClient(pcconfig);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #18
0
        public void SendVerification_on_httpInterface_should_be_called_when_sending_notification()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var n = new Notification
            {
                Application = "app",
                Description = "foo",
                Event       = "event",
                Priority    = NotificationPriority.Normal
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            prowlClient.SendNotification(n);

            Assert.True(fakeHttpInterface.SendNotificationsCalled);
        }
コード例 #19
0
        public void Application_with_more_than_256_characters_should_throw_ArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var appStr = new string('n', 257);
            var n      = new Notification
            {
                Application = appStr,
                Description = "foo",
                Event       = "event",
                Priority    = NotificationPriority.Normal,
                Url         = "http://www.nnihle.com/blog"
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            Assert.Throws(typeof(ArgumentException), delegate { prowlClient.SendNotification(n); });
        }
コード例 #20
0
        public void Url_with_more_than_512_characters_should_not_pass_validation_and_throw_ArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var url = new string('n', 513);

            var n = new Notification
            {
                Application = "Application",
                Description = "foo",
                Event       = "evnet",
                Priority    = NotificationPriority.Normal,
                Url         = url
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            Assert.Throws(typeof(ArgumentException), delegate { prowlClient.SendNotification(n); });
        }
コード例 #21
0
        public void validation_should_pass_with_correct_notifictaion_object()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var n = new Notification
            {
                Application = "app",
                Description = "foo",
                Event       = "event",
                Priority    = NotificationPriority.Normal,
                Url         = "http://www.nnihle.com/blog"
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            prowlClient.SendNotification(n);

            Assert.True(fakeHttpInterface.SendNotificationsCalled);
        }
コード例 #22
0
        public void Event_with_more_than_1024_characters_should_not_pass_validation_and_throw_ArgumentException()
        {
            var fakeHttpInterface = new FakeHttpInterface();
            var prowlClient       = new ProwlClient(fakeHttpInterface);

            var evt = new string('n', 2000);

            var n = new Notification
            {
                Application = "Application",
                Description = "foo",
                Event       = evt,
                //Toooo long
                Priority = NotificationPriority.Normal,
                Url      = "http://www.nnihle.com/blog"
            };

            n.AddApiKey("aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd");

            Assert.Throws(typeof(ArgumentException), delegate { prowlClient.SendNotification(n); });
        }
コード例 #23
0
        public virtual bool SendNotification(string title, string message, string apiKeys, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Notification
                {
                    Application = "NzbDrone",
                    Description = message,
                    Event       = title,
                    Priority    = priority,
                    Url         = url
                };

                foreach (var apiKey in apiKeys.Split(','))
                {
                    notification.AddApiKey(apiKey.Trim());
                }

                var client = new ProwlClient();

                Logger.Trace("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (String.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                {
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Logger.TraceException(ex.Message, ex);
                Logger.Warn("Invalid API Key(s): {0}", apiKeys);
            }

            return(false);
        }
コード例 #24
0
ファイル: ProwlJob.cs プロジェクト: Knatter33/AlarmWorkflow
        bool IJob.Initialize()
        {
            try
            {
                _configuration = new ProwlClientConfiguration();

                _configuration.ApplicationName = SettingsManager.Instance.GetSetting("ProwlJob", "ApplicationName").GetString();
                _configuration.ProviderKey = SettingsManager.Instance.GetSetting("ProwlJob", "ProviderKey").GetString();

                string apiKeychain = string.Join(",", SettingsManager.Instance.GetSetting("ProwlJob", "API").GetStringArray());
                _configuration.ApiKeychain = apiKeychain;

                _client = new ProwlClient(_configuration);
                return true;
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, "Error while initializing Prowl.", ex);
                return false;
            }
        }
コード例 #25
0
 public void InitializeClient()
 {
     _client = new ProwlClient();
 }
コード例 #26
0
        private void Run(string[] args)
        {
            ArgumentsObject arguments = Configuration.Configure <ArgumentsObject>().CreateAndBind(args);

            if (arguments.Help || args.Length == 0)
            {
                ShowHelp();
                return;
            }

            var prowlClient = new ProwlClient();

            if (arguments.RetrieveToken)
            {
                RetrieveToken retrieveToken = new RetrieveToken();
                retrieveToken.ProviderKey = arguments.ProviderKey;

                RetrieveTokenResult result = prowlClient.RetreiveToken(retrieveToken);
                System.Console.WriteLine("Token retreived\nToken: {0}\nUrl: {1}",
                                         result.Token,
                                         result.Url);

                return;
            }

            if (arguments.NewKey)
            {
                if (string.IsNullOrEmpty(arguments.Token) || string.IsNullOrEmpty(arguments.ProviderKey))
                {
                    System.Console.WriteLine("ProviderKey and Token required for this operation.");
                    return;
                }
                RetrieveApikey retrieveApikey = new RetrieveApikey();
                retrieveApikey.Token       = arguments.Token;
                retrieveApikey.ProviderKey = arguments.ProviderKey;

                RetrieveApikeyResult retrieveApikeyResult = prowlClient.RetrieveApikey(retrieveApikey);
                System.Console.WriteLine("New APIKEY: {0}");
                return;
            }

            if (string.IsNullOrEmpty(arguments.Key))
            {
                System.Console.WriteLine("ApiKey requried");
                return;
            }

            if (arguments.Verify)
            {
                IVerification v = new Verification();
                v.ApiKey      = arguments.Key;
                v.ProviderKey = arguments.ProviderKey;
                System.Console.WriteLine("Sending verification...");
                VerificationResult verificationResult = prowlClient.SendVerification(v);
                System.Console.WriteLine("Verification {3}\n\tVerification returned: {0} \n\tNumber of messages left to send: {1}\n\tReset UNIX timestamp: {2}",
                                         verificationResult.ResultCode,
                                         verificationResult.RemainingMessageCount.ToString(),
                                         verificationResult.TimeStamp,
                                         verificationResult.ResultCode == "200" ? "OK" : "NOT OK");
            }
            else
            {
                if (string.IsNullOrEmpty(arguments.Event))
                {
                    System.Console.WriteLine("Event is required");
                    return;
                }

                if (string.IsNullOrEmpty(arguments.Application))
                {
                    System.Console.WriteLine("Application is required");
                    return;
                }

                var notification = new Notification
                {
                    Application = arguments.Application,
                    Description = arguments.Description,
                    Event       = arguments.Event,
                    Url         = arguments.Url
                };


                switch (arguments.Priority.ToLower())
                {
                case "verylow":
                    notification.Priority = NotificationPriority.VeryLow;
                    break;

                case "moderate":
                    notification.Priority = NotificationPriority.Moderate;
                    break;

                case "high":
                    notification.Priority = NotificationPriority.High;
                    break;

                case "emergency":
                    notification.Priority = NotificationPriority.Emergency;
                    break;

                default:
                    notification.Priority = NotificationPriority.Normal;
                    break;
                }

                foreach (string s in arguments.Key.Split(new[] { ',', ';' }))
                {
                    notification.AddApiKey(s);
                }

                NotificationResult notificationResult = prowlClient.SendNotification(notification);

                System.Console.WriteLine("Remaing number of messages: {0}", notificationResult.RemainingMessageCount.ToString());
            }
        }
コード例 #27
0
 public void ProwlClient_should_take_IHttpNotfication_in_constructor()
 {
     IHttpInterface httpInterface = new FakeHttpInterface();
     var            prowlClient   = new ProwlClient(httpInterface);
 }
コード例 #28
0
ファイル: Program.cs プロジェクト: nippe/Prowlin
        private void Run(string[] args)
        {
            ArgumentsObject arguments = Configuration.Configure<ArgumentsObject>().CreateAndBind(args);

            if(arguments.Help || args.Length == 0) {
                ShowHelp();
                return;
            }

            var prowlClient = new ProwlClient();

            if (arguments.RetrieveToken)
            {
                RetrieveToken retrieveToken = new RetrieveToken();
                retrieveToken.ProviderKey = arguments.ProviderKey;

                RetrieveTokenResult result = prowlClient.RetreiveToken(retrieveToken);
                System.Console.WriteLine("Token retreived\nToken: {0}\nUrl: {1}",
                    result.Token,
                    result.Url);

                return;
            }

            if (arguments.NewKey) {
                if(string.IsNullOrEmpty(arguments.Token) || string.IsNullOrEmpty(arguments.ProviderKey)) {
                    System.Console.WriteLine("ProviderKey and Token required for this operation.");
                    return;
                }
                RetrieveApikey retrieveApikey = new RetrieveApikey();
                retrieveApikey.Token = arguments.Token;
                retrieveApikey.ProviderKey = arguments.ProviderKey;

                RetrieveApikeyResult retrieveApikeyResult = prowlClient.RetrieveApikey(retrieveApikey);
                System.Console.WriteLine("New APIKEY: {0}");
                return;
            }

            if (string.IsNullOrEmpty(arguments.Key)) {
                System.Console.WriteLine("ApiKey requried");
                return;
            }

            if(arguments.Verify) {
                IVerification v = new Verification();
                v.ApiKey = arguments.Key;
                v.ProviderKey = arguments.ProviderKey;
                System.Console.WriteLine("Sending verification...");
                VerificationResult verificationResult = prowlClient.SendVerification(v);
                System.Console.WriteLine("Verification {3}\n\tVerification returned: {0} \n\tNumber of messages left to send: {1}\n\tReset UNIX timestamp: {2}",
                    verificationResult.ResultCode,
                    verificationResult.RemainingMessageCount.ToString(),
                    verificationResult.TimeStamp,
                    verificationResult.ResultCode == "200" ? "OK" : "NOT OK");
            }
            else {
                if (string.IsNullOrEmpty(arguments.Event))
                {
                    System.Console.WriteLine("Event is required");
                    return;
                }

                if (string.IsNullOrEmpty(arguments.Application))
                {
                    System.Console.WriteLine("Application is required");
                    return;
                }

                var notification = new Notification
                {
                    Application = arguments.Application,
                    Description = arguments.Description,
                    Event = arguments.Event,
                    Url = arguments.Url
                };

                switch (arguments.Priority.ToLower())
                {
                    case "verylow":
                        notification.Priority = NotificationPriority.VeryLow;
                        break;
                    case "moderate":
                        notification.Priority = NotificationPriority.Moderate;
                        break;
                    case "high":
                        notification.Priority = NotificationPriority.High;
                        break;
                    case "emergency":
                        notification.Priority = NotificationPriority.Emergency;
                        break;
                    default:
                        notification.Priority = NotificationPriority.Normal;
                        break;
                }

                foreach (string s in arguments.Key.Split(new[] { ',', ';' }))
                {
                    notification.AddApiKey(s);
                }

                NotificationResult notificationResult= prowlClient.SendNotification(notification);

                System.Console.WriteLine("Remaing number of messages: {0}", notificationResult.RemainingMessageCount.ToString());
            }
        }
コード例 #29
0
ファイル: ProwlJob.cs プロジェクト: The-Stig/AlarmWorkflow
        bool IJob.Initialize()
        {
            try
            {
                pcconfig = new ProwlClientConfiguration();

                pcconfig.ApplicationName = SettingsManager.Instance.GetSetting("ProwlJob", "ApplicationName").GetString();
                pcconfig.ProviderKey = SettingsManager.Instance.GetSetting("ProwlJob", "ProviderKey").GetString();
                pcconfig.ApiKeychain = SettingsManager.Instance.GetSetting("ProwlJob", "API").GetString();

                pclient = new ProwlClient(pcconfig);
                return true;
            }
            catch
            {
                return false;
            }
        }