private NameValueCollection GetMessageAsNameValueCollection(PushoverMessage message) { var postData = new NameValueCollection() { {"token", _config.ApiToken}, {"user", message.User}, {"message", message.Message}, {"priority", message.Priority.ToString("D")}, {"sound", message.Sound.ToString("G").ToLower()} }; if (!string.IsNullOrWhiteSpace(message.Device)) postData.Add("device", message.Device); if (!string.IsNullOrWhiteSpace(message.Title)) postData.Add("title", message.Title); if (!string.IsNullOrWhiteSpace(message.Url)) postData.Add("url", message.Url); if (!string.IsNullOrWhiteSpace(message.UrlTitle)) postData.Add("url_title", message.UrlTitle); if (!string.IsNullOrWhiteSpace(message.TimeStamp)) postData.Add("timestamp", message.TimeStamp); return postData; }
private FormUrlEncodedContent GetMessageAsFormUrlEncodedContent(PushoverMessage message) { var bob = new List<KeyValuePair<string, string>>(); bob.Add(new KeyValuePair<string, string>("token", _config.ApiToken)); bob.Add(new KeyValuePair<string, string>("user", message.User)); bob.Add(new KeyValuePair<string, string>("message", message.Message)); bob.Add(new KeyValuePair<string, string>("priority", message.Priority.ToString("D"))); bob.Add(new KeyValuePair<string, string>("sound", message.Sound.ToString("G").ToLower())); if (!string.IsNullOrWhiteSpace(message.Device)) bob.Add(new KeyValuePair<string, string>("device", message.Device)); if (!string.IsNullOrWhiteSpace(message.Title)) bob.Add(new KeyValuePair<string, string>("title", message.Title)); if (!string.IsNullOrWhiteSpace(message.Url)) bob.Add(new KeyValuePair<string, string>("url", message.Url)); if (!string.IsNullOrWhiteSpace(message.UrlTitle)) bob.Add(new KeyValuePair<string, string>("url_title", message.UrlTitle)); if (!string.IsNullOrWhiteSpace(message.TimeStamp)) bob.Add(new KeyValuePair<string, string>("timestamp", message.TimeStamp)); var postData = new FormUrlEncodedContent(bob.ToArray()); return postData; }
public async Task<PushoverSendResult> SendNotificationAsync(PushoverMessage message) { PushoverSendResult messageResult = null; var formContent = GetMessageAsFormUrlEncodedContent(message); var response2 = await _config.HttpClient.PostAsync(_config.ApiUrl, formContent); var responseRaw = await response2.Content.ReadAsStringAsync(); messageResult = JsonConvert.DeserializeObject<PushoverSendResult>(responseRaw); return messageResult; }
public void SendInitialTest() { var config = TestConfig.GetPushoverGetConfig(); var client = new PushoverClient(config); var message = new PushoverMessage(TestConfig.UserKey) { Message = "This is a test message Rachel", Priority = PushoverPriority.Normal, Sound = PushoverSound.Bike, Title = "Hello World", Url = "http://google.co.za", UrlTitle = "Google" }; client.SendNotification(message); }
public void SendDodgeyRequest() { var config = TestConfig.GetPushoverGetConfig(); var client = new PushoverClient(config); var message = new PushoverMessage() { Message = "This is a test message Rachel", Priority = PushoverPriority.Normal, Sound = PushoverSound.Bike, Title = "Hello World", Url = "http://google.co.za", UrlTitle = "Google" }; var result = client.SendNotification(message); Assert.IsFalse(result.WasSuccessful); }
public void Booo() { var httpClient = Substitute.For<IHttpClient>(); var config = TestConfig.GetPushoverGetConfig(); config.HttpClient = httpClient; var client = new PushoverClient(config); var message = new PushoverMessage(TestConfig.UserKey) { Message = "This is a test message Rachel", Priority = PushoverPriority.Normal, Sound = PushoverSound.Bike, Title = "Hello World", Url = "http://google.co.za", UrlTitle = "Google" }; httpClient.Received().PostAsync(Arg.Any<string>(), Arg.Is<FormUrlEncodedContent>(form => form.ToString().Contains("bb"))); client.SendNotification(message); }
public PushoverSendResult SendNotification(PushoverMessage message) { return SendNotificationAsync(message).Result; }