コード例 #1
0
        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);
        }
コード例 #2
0
        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();;
        }
コード例 #3
0
        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();;
        }
コード例 #4
0
 public static string Serialize(this BatchPushRequest request)
 {
     return(new JsonArray(request.Notifications.Select(JsonObj)).ToString());
 }