public void Single() { var notification = new BroadcastNotificationRequest { Payload = new PushPayload { Alert = "My Alert", Sound = "My Sound", Badge = Badge.Increment() }, ExcludeTokens = new List<string> {"exclude1"}, }; var actual = notification.Serialize().FormatAsJson(); var expected = @" { 'aps': { 'alert': 'My Alert', 'badge': '+1', 'sound': 'My Sound' }, 'exclude_tokens': [ 'exclude1' ] }".Replace("\r\n", "\n"); Assert.AreEqual(expected, actual); }
static JsonObject JsonObj(BroadcastNotificationRequest notification) { var jsonObj = new JsonObject(); jsonObj["aps"] = BatchPushRequestSerializer.JsonObject(notification.Payload); if (notification.ExcludeTokens != null) { jsonObj["exclude_tokens"] = notification.ExcludeTokens.ToJsonArray(); } return(jsonObj); }
static JsonObject JsonObj(BroadcastNotificationRequest notification) { var jsonObj = new JsonObject(); jsonObj["aps"] = BatchPushRequestSerializer.JsonObject(notification.Payload); if (notification.ExcludeTokens != null) { jsonObj["exclude_tokens"] = notification.ExcludeTokens.ToJsonArray(); } return jsonObj; }
public void Execute(BroadcastNotificationRequest request, Action<BroadcastNotificationResponse> responseCallback, Action<Exception> exceptionCallback) { var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/push/broadcast/"); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; var asyncRequest = new AsyncRequest { WriteToRequest = stream => stream.WriteToStream(request.Serialize), Request = webRequest, ReadFromResponse = o => responseCallback(new BroadcastNotificationResponse()), ExceptionCallback = exceptionCallback, }; asyncRequest.Execute(); }
public void Execute(BroadcastNotificationRequest request, Action<BroadcastNotificationResponse> responseCallback, Action<Exception> exceptionCallback) { var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/push/broadcast/"); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; var asyncRequest = new AsyncRequest { WriteToRequest = stream => stream.WriteToStream(request.Serialize), Request = webRequest, ReadFromResponse = o => responseCallback(new BroadcastNotificationResponse()), ExceptionCallback = exceptionCallback, }; asyncRequest.Execute(); }
public void Simple() { var service = new BroadcastService { RequestBuilder = ServerRequestBuilder.Instance }; var notification = new BroadcastNotificationRequest { ExcludeTokens = new List<string> {"TokenToExclude"}, Payload = new PushPayload { Alert = "Alert 2", Badge = Badge.Increment() } }; service.Execute(notification, response => Debug.WriteLine("Success"),ExceptionHandler.Handle); }
public void Simple() { var service = new BroadcastService { RequestBuilder = RequestBuilderHelper.Build() }; var broadcastNotification = new BroadcastNotificationRequest { Payload = new PushPayload { Alert = "Alert 2", Badge = Badge.Increment() } }; var asyncTestHelper = new AsyncTestHelper(); service.Execute(broadcastNotification, response => asyncTestHelper.Callback(null), asyncTestHelper.HandleException); asyncTestHelper.Wait(); }
public static string Serialize(this BroadcastNotificationRequest notification) { var jsonObj = JsonObj(notification); return(jsonObj.ToString()); }