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;
        }
 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);
 }
        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();
        }
 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);
 }
Exemple #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();
        }
 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();
 }
 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();
 }
        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);
        }
        public static string Serialize(this PushNotificationRequest notification)
        {
            var jsonObj = JsonObj(notification);

            return(jsonObj.ToString());
        }