public void List() { var request = new BatchPushRequest { Notifications = new List<PushNotification> { new PushNotification { Payload = new PushPayload { Alert = "My Alert", Sound = "My Sound", Badge = Badge.Increment() }, Aliases = new List<string> {"alias1"} }, new PushNotification { Payload = new PushPayload { Alert = "My Alert", Sound = "My Sound", Badge = Badge.Increment() }, Aliases = new List<string> {"alias1"} } } }; var text = request.Serialize().FormatAsJson(); var expected = @" [ { 'aps': { 'alert': 'My Alert', 'badge': '+1', 'sound': 'My Sound' }, 'aliases': [ 'alias1' ] }, { 'aps': { 'alert': 'My Alert', 'badge': '+1', 'sound': 'My Sound' }, 'aliases': [ 'alias1' ] } ]".Replace("\r\n", "\n"); Assert.AreEqual(expected, text); }
public void Execute(BatchPushRequest request, Action<BatchPushResponse> responseCallback, Action<Exception> exceptionCallback) { var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/push/batch/"); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; var asyncRequest = new AsyncRequest { WriteToRequest = stream =>stream.WriteToStream(request.Serialize), Request = webRequest, ReadFromResponse = o => responseCallback(new BatchPushResponse()), ExceptionCallback = exceptionCallback, }; asyncRequest.Execute();; }
public void Execute(BatchPushRequest request, Action <BatchPushResponse> responseCallback, Action <Exception> exceptionCallback) { var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/push/batch/"); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; var asyncRequest = new AsyncRequest { WriteToRequest = stream => stream.WriteToStream(request.Serialize), Request = webRequest, ReadFromResponse = o => responseCallback(new BatchPushResponse()), ExceptionCallback = exceptionCallback, }; asyncRequest.Execute();; }
public static string Serialize(this BatchPushRequest request) { return(new JsonArray(request.Notifications.Select(JsonObj)).ToString()); }