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); } }
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); }
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); }); }
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); }); }
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); }
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); }
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); }); }
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); }); }
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); }
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()); } }
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()); } }