public void Execute(ModifyTagRequest request, Action<ModifyTagResponse> responseCallback, Action<Exception> exceptionCallback)
        {
            var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/tags/" + request.Tag);
            webRequest.Method = "POST";

            var asyncRequest = new AsyncRequest
            {
                WriteToRequest = stream => stream.WriteToStream(request.Serialize),
                Request = webRequest,
                ReadFromResponse = o => responseCallback(new ModifyTagResponse()),
                ExceptionCallback = exceptionCallback,
                RequestContentType = "application/json"
            };
            asyncRequest.Execute();
        }
 public void Simple()
 {
     var registration = new ModifyTagRequest
     {
         AddDevicePins = new List<string> { "AddDevicePin1", "AddDevicePin2" },
         RemoveDevicePins = new List<string> { "RemoveDevicePin1", "RemoveDevicePin2" },
         AddDeviceTokens = new List<string> { "AddDeviceToken1", "AddDeviceToken2" },
         RemoveDeviceTokens = new List<string> { "RemoveDeviceToken1", "RemoveDeviceToken2" },
         AddPushIds = new List<string> { "AddPushId1", "AddPushId2" },
         RemovePushIds = new List<string> { "RemovePushId1", "RemovePushId2" }
     };
     var text = registration.Serialize().FormatAsJson();
     var expected = @"
     {
       'device_tokens': {
     'add': [
       'AddDeviceToken1',
       'AddDeviceToken2'
     ],
     'remove': [
       'RemoveDeviceToken1',
       'RemoveDeviceToken2'
     ]
       },
       'device_pins': {
     'add': [
       'AddDevicePin1',
       'AddDevicePin2'
     ],
     'remove': [
       'RemoveDevicePin1',
       'RemoveDevicePin2'
     ]
       },
       'apids': {
     'add': [
       'AddPushId1',
       'AddPushId2'
     ],
     'remove': [
       'RemovePushId1',
       'RemovePushId2'
     ]
       }
     }".Replace("\r\n", "\n");
     Assert.AreEqual(expected, text);
 }
        public void Execute(ModifyTagRequest request, Action <ModifyTagResponse> responseCallback, Action <Exception> exceptionCallback)
        {
            var webRequest = RequestBuilder.Build("https://go.urbanairship.com/api/tags/" + request.Tag);

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

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

            asyncRequest.Execute();
        }
        public void Simple()
        {

            var service = new ModifyTagService
            {
                RequestBuilder = RequestBuilderHelper.Build()
            };
            var tokens = new ModifyTagRequest
            {
                Tag = "myTag",
                AddDeviceTokens = new List<string> { RemoteSettings.AppleDeviceId },
            };
            
            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(tokens, response => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);

            asyncTestHelper.Wait();
        }
 public void Multiple()
 {
     var service = new ModifyTagService
                       {
                           RequestBuilder = ServerRequestBuilder.Instance
                       };
     var tokens = new ModifyTagRequest
                      {
                          Tag = "tag1",
                          AddDevicePins = new List<string> {"AddDevicePin1", "AddDevicePin2"},
                          RemoveDevicePins = new List<string> {"RemoveDevicePin1", "RemoveDevicePin2"},
                          AddDeviceTokens = new List<string> {"AddDeviceToken1", "AddDeviceToken2"},
                          RemoveDeviceTokens = new List<string> {"RemoveDeviceToken1", "RemoveDeviceToken2"},
                          AddPushIds = new List<string> {"AddPushId1", "AddPushId2"},
                          RemovePushIds = new List<string> {"RemovePushId1", "RemovePushId2"}
                      };
     service.Execute(tokens, response => Debug.WriteLine("Success"),ExceptionHandler.Handle);
 }
        static JsonObject JsonObj(ModifyTagRequest modifyTagRequest)
        {
            var jsonObj = new JsonObject();

            var appleDeviceTokens = new JsonObject();
            appleDeviceTokens["add"] = modifyTagRequest.AddDeviceTokens.ToJsonArray();
            appleDeviceTokens["remove"] = modifyTagRequest.RemoveDeviceTokens.ToJsonArray();
            jsonObj["device_tokens"] = appleDeviceTokens;

            var blackBerryDevicePins = new JsonObject();
            blackBerryDevicePins["add"] = modifyTagRequest.AddDevicePins.ToJsonArray();
            blackBerryDevicePins["remove"] = modifyTagRequest.RemoveDevicePins.ToJsonArray();
            jsonObj["device_pins"] = blackBerryDevicePins;

            var androidPushIds = new JsonObject();
            androidPushIds["add"] = modifyTagRequest.AddPushIds.ToJsonArray();
            androidPushIds["remove"] = modifyTagRequest.RemovePushIds.ToJsonArray();
            jsonObj["apids"] = androidPushIds;

            return jsonObj;
        }
Exemple #7
0
        static JsonObject JsonObj(ModifyTagRequest modifyTagRequest)
        {
            var jsonObj = new JsonObject();

            var appleDeviceTokens = new JsonObject();

            appleDeviceTokens["add"]    = modifyTagRequest.AddDeviceTokens.ToJsonArray();
            appleDeviceTokens["remove"] = modifyTagRequest.RemoveDeviceTokens.ToJsonArray();
            jsonObj["device_tokens"]    = appleDeviceTokens;

            var blackBerryDevicePins = new JsonObject();

            blackBerryDevicePins["add"]    = modifyTagRequest.AddDevicePins.ToJsonArray();
            blackBerryDevicePins["remove"] = modifyTagRequest.RemoveDevicePins.ToJsonArray();
            jsonObj["device_pins"]         = blackBerryDevicePins;

            var androidPushIds = new JsonObject();

            androidPushIds["add"]    = modifyTagRequest.AddPushIds.ToJsonArray();
            androidPushIds["remove"] = modifyTagRequest.RemovePushIds.ToJsonArray();
            jsonObj["apids"]         = androidPushIds;

            return(jsonObj);
        }
Exemple #8
0
        public static string Serialize(this ModifyTagRequest modifyTagRequest)
        {
            var jsonObj = JsonObj(modifyTagRequest);

            return(jsonObj.ToString());
        }