コード例 #1
0
        static JsonObject JsonObj(PushNotificationRequest notification)
        {
            var jsonObj = new JsonObject();

            var android = new JsonObject();

            if (notification.Payload.Alert != null)
            {
                android["alert"] = notification.Payload.Alert;
            }
            if (notification.Payload.Extra != null)
            {
                var extra = new JsonObject();
                foreach (var pair in notification.Payload.Extra)
                {
                    extra[pair.Key] = pair.Value;
                }
                android["extra"] = extra;
            }
            jsonObj["android"] = android;
            if (notification.PushIds != null)
            {
                jsonObj["apids"] = notification.PushIds.ToJsonArray();
            }
            if (notification.Aliases != null)
            {
                jsonObj["aliases"] = notification.Aliases.ToJsonArray();
            }
            if (notification.Tags != null)
            {
                jsonObj["tags"] = notification.Tags.ToJsonArray();
            }

            return jsonObj;
        }
コード例 #2
0
 public void Single()
 {
     var notification = new PushNotificationRequest
                            {
                                Payload = new PushPayload
                                              {
                                                  Alert = "My Alert",
                                                  Extra = new Dictionary<string, string>
                                                              {
                                                                  {"a","b"}
                                                              },
                                              },
                                Aliases = new List<string> {"alias1"},
                                Tags = new List<string> {"tag1"},
                            };
     var text = notification.Serialize().FormatAsJson();
     var expected = @"
     {
       'android': {
     'alert': 'My Alert',
     'extra': {
       'a': 'b'
     }
       },
       'aliases': [
     'alias1'
       ],
       'tags': [
     'tag1'
       ]
     }".Replace("\r\n", "\n");
     Assert.AreEqual(expected, text);
 }
コード例 #3
0
        public void Execute(PushNotificationRequest notification, Action<PushNotificationResponse> responseCallback, Action<Exception> exceptionCallback)
        {
            var request = RequestBuilder.Build("https://go.urbanairship.com/api/push/");
            request.Method = "POST";
            request.ContentType = "application/json";

            var asyncRequest = new AsyncRequest
                {
                    Request = request,
                    ReadFromResponse = o => responseCallback(new PushNotificationResponse()),
                    ExceptionCallback = exceptionCallback,
                    WriteToRequest = stream => stream.WriteToStream(notification.Serialize),
                };
            asyncRequest.Execute();
        }
コード例 #4
0
 public void Simple()
 {
     var service = new PushService
                       {
                           RequestBuilder = ServerRequestBuilder.Instance
                       };
     var notification = new PushNotificationRequest
                            {
                                Tags = new List<string> {"MyTag"},
                                PushIds = new List<string> {"AndroidPushId"},
                                Payload = new PushPayload
                                              {
                                                  Alert = "Alert 2"
                                              }
                            };
     service.Execute(notification,response => Debug.WriteLine("Success"),ExceptionHandler.Handle);
 }
コード例 #5
0
        public void Execute(PushNotificationRequest notification, Action <PushNotificationResponse> responseCallback, Action <Exception> exceptionCallback)
        {
            var request = RequestBuilder.Build("https://go.urbanairship.com/api/push/");

            request.Method      = "POST";
            request.ContentType = "application/json";

            var asyncRequest = new AsyncRequest
            {
                Request           = request,
                ReadFromResponse  = o => responseCallback(new PushNotificationResponse()),
                ExceptionCallback = exceptionCallback,
                WriteToRequest    = stream => stream.WriteToStream(notification.Serialize),
            };

            asyncRequest.Execute();
        }
コード例 #6
0
 public void ToTag()
 {
     var service = new PushService
         {
             RequestBuilder = RequestBuilderHelper.Build()
         };
     var pushNotification = new PushNotificationRequest
         {
             Tags = new List<string> {"africa"},
             Payload = new PushPayload
                 {
                     Alert = "Alert 2"
                 }
         };
     var asyncTestHelper = new AsyncTestHelper();
     service.Execute(pushNotification, x => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
     asyncTestHelper.Wait();
 }
コード例 #7
0
 public void Simple()
 {
     var service = new PushService
         {
             RequestBuilder = RequestBuilderHelper.Build()
         };
     var pushNotification = new PushNotificationRequest
         {
             PushIds = new List<string> {RemoteSettings.AndroidPushId},
             Payload = new PushPayload
                 {
                     Alert = "Alert 2"
                 }
         };
     var asyncTestHelper = new AsyncTestHelper();
     service.Execute(pushNotification, x => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
     asyncTestHelper.Wait();
 }
コード例 #8
0
        static JsonObject JsonObj(PushNotificationRequest notification)
        {
            var jsonObj = new JsonObject();

            var android = new JsonObject();

            if (notification.Payload.Alert != null)
            {
                android["alert"] = notification.Payload.Alert;
            }
            if (notification.Payload.Extra != null)
            {
                var extra = new JsonObject();
                foreach (var pair in notification.Payload.Extra)
                {
                    extra[pair.Key] = pair.Value;
                }
                android["extra"] = extra;
            }
            jsonObj["android"] = android;
            if (notification.PushIds != null)
            {
                jsonObj["apids"] = notification.PushIds.ToJsonArray();
            }
            if (notification.Aliases != null)
            {
                jsonObj["aliases"] = notification.Aliases.ToJsonArray();
            }
            if (notification.Tags != null)
            {
                jsonObj["tags"] = notification.Tags.ToJsonArray();
            }


            return(jsonObj);
        }
コード例 #9
0
        public static string Serialize(this PushNotificationRequest notification)
        {
            var jsonObj = JsonObj(notification);

            return(jsonObj.ToString());
        }