예제 #1
0
        public void Test_BuildWithNullPushMessageType()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithPushMessageType(null);
        }
예제 #2
0
        public void Test_0004_BuildWithNullAPNSMessage()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithAPNSMessage(null);
        }
예제 #3
0
        public void Test_0002_KiiPushMessage_all_false()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage msg = KiiPushMessage.BuildWith(data)
                                 .EnableAPNS(false)
                                 .EnableGCM(false)
                                 .EnableMqtt(false)
                                 .SendAppID(false)
                                 .SendObjectScope(false)
                                 .SendOrigin(false)
                                 .SendSender(false)
                                 .SendToDevelopment(false)
                                 .SendTopicId(false)
                                 .SendToProduction(false)
                                 .SendWhen(false)
                                 .Build();
            JsonObject json = msg.ToJson();

            Assert.AreEqual(false, json.Get("sendAppID"));
            Assert.AreEqual(false, json.Get("sendObjectScope"));
            Assert.AreEqual(false, json.Get("sendOrigin"));
            Assert.AreEqual(false, json.Get("sendSender"));
            Assert.AreEqual(false, json.Get("sendToDevelopment"));
            Assert.AreEqual(false, json.Get("sendTopicID"));
            Assert.AreEqual(false, json.Get("sendToProduction"));
            Assert.AreEqual(false, json.Get("sendWhen"));
            Assert.AreEqual(false, json.GetJsonObject("gcm").Get("enabled"));
            Assert.AreEqual(false, json.GetJsonObject("apns").Get("enabled"));
            Assert.AreEqual(false, json.GetJsonObject("mqtt").Get("enabled"));
            Assert.AreEqual("abc", json.GetJsonObject("data").Get("payload"));
        }
 private KiiPushMessage(KiiPushMessageData messageData, JsonObject parent, JsonObject gcm, JsonObject apns, JsonObject mqtt)
 {
     this.mMessageData = messageData;
     this.mParent      = parent;
     this.mGcm         = gcm;
     this.mApns        = apns;
     this.mMqtt        = mqtt;
 }
 /// <summary>
 /// Instantiate message builder with the data.
 /// </summary>
 /// <remarks></remarks>
 /// <returns>Builder of the message.</returns>
 /// <param name="messageData">Message data.</param>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 public static KiiPushMessage.Builder BuildWith(KiiPushMessageData messageData)
 {
     if (messageData == null)
     {
         throw new ArgumentNullException("messageData can not be null");
     }
     return(new KiiPushMessage.Builder(messageData));
 }
 internal Builder(KiiPushMessageData messageData)
 {
     this.mParent      = new JsonObject();
     this.mMessageData = messageData;
     this.mGcm         = GCMMessage.CreateBuilder().Build().ToJson();
     this.mApns        = APNSMessage.CreateBuilder().Build().ToJson();
     this.mMqtt        = MqttMessage.CreateBuilder().Build().ToJson();
 }
예제 #7
0
 /// <summary>
 /// Create a builder with the data that will be sent only to android-GCM devices.
 /// Corresponding to GCM's "data"
 /// The data specified here will be merged with the data specified on <see cref="KiiPushMessage.BuildWith(KiiPushMessage.Data)"/>
 /// </summary>
 /// <remarks></remarks>
 /// <param name="data">Data.</param>
 /// <returns>Builder of the message.</returns>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 public Builder WithGCMData(GCMData data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data must not be null");
     }
     this.mMessageData = data;
     return(this);
 }
예제 #8
0
 /// <summary>
 /// Create builder with Data that will be sent only to iOS-APNS devices.
 /// Corresponding to APNS's custom payload.
 /// The data specified here will be merged with the data specified on <see cref="KiiPushMessage.BuildWith(KiiPushMessage.Data)"/>
 /// </summary>
 /// <remarks></remarks>
 /// <param name="data">APNS specific data.</param>
 /// <returns>Builder of the message.</returns>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 public Builder WithAPNSData(APNSData data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data must not be null");
     }
     this.mData = data;
     return(this);
 }
예제 #9
0
        internal static bool IsValidData(KiiPushMessageData data)
        {
            JsonObject           json = data.ToJsonObject();
            IEnumerator <string> keys = json.Keys();

            while (keys.MoveNext())
            {
                string key = keys.Current;
                if (!ValidateKey(key))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #10
0
        public void Test_0005_SendMessage()
        {
            this.LogIn();
            ClearClientRequest();
            client.AddResponse(200, null);

            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage message = KiiPushMessage.BuildWith(data).Build();

            KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic");

            topic.SendMessage(message);
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]);
        }
        public void Test_0001_KiiPushMessageData()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("string", "abc")
            .Put("int", 10)
            .Put("long", 1000L)
            .Put("double", 10.05)
            .Put("bool", false);

            JsonObject json = data.ToJsonObject();

            Assert.AreEqual(json.Get("string"), "abc");
            Assert.AreEqual(json.Get("int"), 10);
            Assert.AreEqual(json.Get("long"), 1000L);
            Assert.AreEqual(json.Get("double"), 10.05);
            Assert.AreEqual(json.Get("bool"), false);
        }
예제 #12
0
 internal static new bool ValidateKey(string key)
 {
     if (!KiiPushMessageData.ValidateKey(key))
     {
         return(false);
     }
     if (key.StartsWith("google"))
     {
         return(false);
     }
     foreach (String reserveKey in GCM_RESERVE_KEYS)
     {
         if (reserveKey == key.ToLower())
         {
             return(false);
         }
     }
     return(true);
 }
예제 #13
0
        public void Test_SendMessage_Anonymous()
        {
            this.LogIn();
            ClearClientRequest();
            client.AddResponse(new CloudException(401, null));

            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage message = KiiPushMessage.BuildWith(data).Build();

            KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic");

            Kii.LogOut();
            try {
                topic.SendMessage(message);
                Assert.Fail("CloudException has not thrown");
            } catch (CloudException e) {
                // pass
            }
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]);
        }
예제 #14
0
 internal static new bool ValidateKey(string key)
 {
     return(KiiPushMessageData.ValidateKey(key));
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KiiCorp.Cloud.Storage.APNSMessage"/> class.
 /// </summary>
 /// <param name="parent">Parent.</param>
 /// <param name="data">Data.</param>
 /// <param name="alert">Alert.</param>
 internal APNSMessage(JsonObject parent, KiiPushMessageData data, JsonObject alert)
 {
     this.mParent = parent;
     this.mData   = data;
     this.mAlert  = alert;
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KiiCorp.Cloud.Storage.GCMMessage"/> class.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="parent">Parent.</param>
 internal GCMMessage(KiiPushMessageData data, JsonObject parent)
 {
     this.mData   = data;
     this.mParent = parent;
 }
        public void Test_0002_KiiPushMessageData_InvalidKey()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("", "abc");
        }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KiiCorp.Cloud.Storage.MqttMessage"/> class.
 /// </summary>
 /// <param name="parent">Parent.</param>
 /// <param name="data">Data.</param>
 internal MqttMessage(JsonObject parent, KiiPushMessageData data)
 {
     this.parent = parent;
     this.data   = data;
 }