public void BuildDictionaryForRetreiveToken_should_build_correct_dictionary() { RetrieveToken rt = new RetrieveToken() { ProviderKey = "9012345678901234567890123456789012345678" }; Dictionary <string, string> resultDict = new RequestBuilderHelper().BuildDictionaryForRetreiveToken(rt); Assert.Equal(rt.ProviderKey, resultDict["providerkey"]); }
public RetrieveTokenResult RetrieveToken(RetrieveToken retrieveToken) { Dictionary<string, string> parameters = _requestBuilderHelper.BuildDictionaryForRetreiveToken(retrieveToken); RetrieveTokenResult retrieveTokenResult = new RetrieveTokenResult(); XDocument resultDocument = GetResultDocument(parameters, Method.GetToken, retrieveTokenResult); ResultParser.ParseTokenResult(resultDocument, retrieveTokenResult); return retrieveTokenResult; }
public RetrieveTokenResult RetrieveToken(RetrieveToken retrieveToken) { _retrieveTokenCalled = true; return(new RetrieveTokenResult() { RemainingMessageCount = 999, ResultCode = "200", TimeStamp = "", Token = "ASDFGASDFGASDFGASDFGASDFGASDFGASDFGASDFG", Url = "http://www.prowlapp.com/" }); }
public RetrieveTokenResult RetrieveToken(RetrieveToken retrieveToken) { _retrieveTokenCalled = true; return new RetrieveTokenResult() { RemainingMessageCount = 999, ResultCode = "200", TimeStamp = "", Token = "ASDFGASDFGASDFGASDFGASDFGASDFGASDFGASDFG", Url = "http://www.prowlapp.com/" }; }
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); }
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); }
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()); } }
public void BuildDictionaryForRetreiveToken_should_build_correct_dictionary() { RetrieveToken rt = new RetrieveToken() { ProviderKey = "9012345678901234567890123456789012345678" }; Dictionary<string, string> resultDict = new RequestBuilderHelper().BuildDictionaryForRetreiveToken(rt); Assert.Equal(rt.ProviderKey, resultDict["providerkey"]); }
public Dictionary<string, string> BuildDictionaryForRetreiveToken(RetrieveToken retrieveToken) { Dictionary<string,string > parameters = new Dictionary<string, string>(1); parameters.Add("providerkey", retrieveToken.ProviderKey); return parameters; }
public RetrieveTokenResult RetreiveToken(RetrieveToken retrieveToken) { ValidateObject(retrieveToken); return _httpInterface.RetrieveToken(retrieveToken); }