public void Single2()
 {
     var registration = new AddRegistrationRequest
     {
         Alias = "alias",
         Badge = 2,
         QuietTime = new QuietTime
         {
             Start = "22:00",
             End = "8:00"
         },
         Tags = new List<string> { "tag1", "tag2" },
         TimeZone = "America/Los_Angeles"
     };
     var text = registration.Serialize().FormatAsJson();
     var expected = @"
     {
       'quiettime': {
     'start': '22:00',
     'end': '8:00'
       },
       'alias': 'alias',
       'badge': 2,
       'tz': 'America/Los_Angeles',
       'tags': [
     'tag1',
     'tag2'
       ]
     }".Replace("\r\n", "\n");
     Assert.AreEqual(expected, text);
 }
 public void Simple()
 {
     var service = new AddRegistrationService
                       {
                           RequestBuilder = ServerRequestBuilder.Instance
                       };
     var registration = new AddRegistrationRequest
                            {
                                DeviceToken = "AppleDeviceId",
                                Tags = new List<string> {"MyTag"},
                                Alias = "MyAlias",
                                Badge = 10
                            };
     service.Execute(registration, response => Debug.WriteLine("Success"), ExceptionHandler.Handle);
 }
        public void Execute(AddRegistrationRequest request, Action<AddRegistrationResponse> responseCallback, Action<Exception> exceptionCallback)
        {
            var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/device_tokens/" + request.DeviceToken);
            webRequest.Method = "PUT";

            var asyncRequest = new AsyncRequest
            {
                WriteToRequest = stream => stream.WriteToStream(request.Serialize),
                Request = webRequest,
                ReadFromResponse = o => responseCallback(new AddRegistrationResponse()),
                ExceptionCallback = exceptionCallback,
                    RequestContentType = "application/json"
            };

            asyncRequest.Execute();
        }
Пример #4
0
        public void Execute(AddRegistrationRequest request, Action <AddRegistrationResponse> responseCallback, Action <Exception> exceptionCallback)
        {
            var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/device_tokens/" + request.DeviceToken);

            webRequest.Method      = "PUT";
            webRequest.ContentType = "application/json";

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

            asyncRequest.Execute();
        }
        public void Tags()
        {
            var service = new AddRegistrationService
                              {
                                  RequestBuilder = RequestBuilderHelper.Build()
                              };
            var registration = new AddRegistrationRequest
                                   {
                                       DeviceToken = RemoteSettings.AppleDeviceId,
                                       Tags = new List<string>
                                           {
                                               "bangladesh",
                                           }
                                   };


            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(registration, x => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
            asyncTestHelper.Wait();
        }
        static JsonObject JsonObj(AddRegistrationRequest registration)
        {
            var jsonObj = new JsonObject();

            if (registration.QuietTime != null)
            {
                var quiettime = new JsonObject();
                quiettime["start"]   = registration.QuietTime.Start;
                quiettime["end"]     = registration.QuietTime.End;
                jsonObj["quiettime"] = quiettime;
            }

            if (registration.Alias != null)
            {
                jsonObj["alias"] = registration.Alias;
            }
            if (registration.Badge != null)
            {
                jsonObj["badge"] = registration.Badge.Value;
            }
            if (registration.TimeZone != null)
            {
                jsonObj["tz"] = registration.TimeZone;
            }
            // jsonObj.tags = Dynamic.ListValue(registration.Tags);
            if (registration.Tags != null)
            {
                var tagArray = new JsonArray();
                foreach (var tag in registration.Tags)
                {
                    tagArray.Add(tag);
                }
                jsonObj["tags"] = tagArray;
            }

            return(jsonObj);
        }
        static JsonObject JsonObj(AddRegistrationRequest registration)
        {
            var jsonObj = new JsonObject();

            if (registration.QuietTime != null)
            {
                var quiettime = new JsonObject();
                quiettime["start"] = registration.QuietTime.Start;
                quiettime["end"] = registration.QuietTime.End;
                jsonObj["quiettime"] = quiettime;
            }

            if (registration.Alias != null)
            {
                jsonObj["alias"] = registration.Alias;
            }
            if (registration.Badge != null)
            {
                jsonObj["badge"] = registration.Badge.Value;
            }
            if (registration.TimeZone != null)
            {
                jsonObj["tz"] = registration.TimeZone;
            }
               // jsonObj.tags = Dynamic.ListValue(registration.Tags);
            if (registration.Tags != null)
            {
                var tagArray = new JsonArray();
                foreach (var tag in registration.Tags)
                {
                    tagArray.Add(tag);
                }
                jsonObj["tags"] = tagArray;
            }

            return jsonObj;
        }
        public static string Serialize(this AddRegistrationRequest registration)
        {
            var jsonObj = JsonObj(registration);

            return(jsonObj.ToString());
        }