public void testNotification()
        {
            int number = ServiceHelper.generateSendno();
           
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all(); 
            payload.options = new Options() { sendno = number };
            payload.notification = new Notification().setAlert("alert");
            payload.Check();

            JObject json = new JObject();
            json.Add("platform", JToken.FromObject("all"));
            json.Add("audience", JToken.FromObject("all"));
           

            JObject noti = new JObject();
            noti.Add("alert", JToken.FromObject("alert"));
            json.Add("notification", noti);

            JObject options = new JObject();
            options.Add("sendno", JToken.FromObject(number));
            options.Add("apns_production", JToken.FromObject(false));
            json.Add("options", options);

            var jSetting = new JsonSerializerSettings();
            jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
            var jsonString = JsonConvert.SerializeObject(payload, jSetting);
            var jsonObject = json.ToString(Formatting.None);

            Assert.AreEqual(jsonObject, jsonString);
        }
        public void testIllegal_OnlyAudience()
        {
            PushPayload pushPayliad = new PushPayload();
            pushPayliad.audience = Audience.all();
            pushPayliad.Check();

        }
        public static void Main(string[] args)
        {
            //init a pushpayload
            PushPayload pushPayload = new PushPayload();
            pushPayload.platform = Platform.all();
            pushPayload.audience = Audience.all();
            pushPayload.notification = new Notification().setAlert(ALERT);

            ScheduleClient scheduleclient = new ScheduleClient(app_key, master_secret);

            //get schedule
            try
            {
                var result = scheduleclient.getSchedule(PAGEID);
                Console.WriteLine(result.schedules[0].name);

                Console.WriteLine(result.schedules);
                Console.WriteLine(result);
            }
            catch (APIRequestException e)
            {
                Console.WriteLine("Error response from JPush server. Should review and fix it. ");
                Console.WriteLine("HTTP Status: " + e.Status);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Message: " + e.ErrorCode);
            }
            catch (APIConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
 public MessageResult sendPush(PushPayload payload) 
 {
     Preconditions.checkArgument(payload != null, "pushPayload should not be empty");
     payload.Check();
     String payloadJson = payload.ToJson();
     return sendPush(payloadJson);
 }
        public static void Main(string[] args)
        {
            PushPayload pushPayload = new PushPayload();
            pushPayload.platform = Platform.all();
            pushPayload.audience = Audience.all();
            pushPayload.notification = new Notification().setAlert(ALERT);
            ScheduleClient scheduleclient = new ScheduleClient(app_key, master_secret);

            //init a TriggerPayload
            TriggerPayload triggerConstructor = new TriggerPayload(START, END, TIME_PERIODICAL, TIME_UNIT, FREQUENCY, POINT);
            //init a SchedulePayload
            SchedulePayload schedulepayloadperiodical = new SchedulePayload(NAME, ENABLED, triggerConstructor, pushPayload);

            try
            {
                var result = scheduleclient.sendSchedule(schedulepayloadperiodical);
                Console.WriteLine(result);
            }
            catch (APIRequestException e)
            {
                Console.WriteLine("Error response from JPush server. Should review and fix it. ");
                Console.WriteLine("HTTP Status: " + e.Status);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Message: " + e.ErrorCode);
            }
            catch (APIConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
 public void testIllegal_OnlyPlatform()
 {
     Platform platform = Platform.all();
     PushPayload pushPayliad = new PushPayload();
     pushPayliad.platform = platform;
     pushPayliad.Check();
 }
Ejemplo n.º 7
0
 public static PushPayload PushObject_all_alias_alert()
 {
     PushPayload pushPayload = new PushPayload();
     pushPayload.platform = Platform.android();
     pushPayload.audience = Audience.s_alias("alias1");
     pushPayload.notification = new Notification().setAlert(ALERT);
     return pushPayload;
 }
Ejemplo n.º 8
0
 public static PushPayload PushObject_All_All_Alert()
 {
     PushPayload pushPayload = new PushPayload();
     pushPayload.platform = Platform.all();
     pushPayload.audience = Audience.all();
     pushPayload.notification = new Notification().setAlert(ALERT);
     return pushPayload;
 }
Ejemplo n.º 9
0
 public static PushPayload PushObject_ios_audienceMore_messageWithExtras()
 {
     var pushPayload = new PushPayload();
     pushPayload.platform = Platform.android_ios();
     pushPayload.audience = Audience.s_tag("tag1","tag2");
     pushPayload.message = Message.content(MSG_CONTENT).AddExtras("from", "JPush");
     return pushPayload;
 }
Ejemplo n.º 10
0
 public void sendByAliasMore()
 {
     PushPayload payload = new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.s_alias(ALIAS1, ALIAS2);
     payload.notification = new Notification().setAlert(ALERT);
     var result = _client.SendPush(payload);
     Assert.IsTrue(result.isResultOK());
 }
Ejemplo n.º 11
0
 public void sendByRegistrationID()
 {
     PushPayload payload = new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.s_registrationId(REGISTRATION_ID1);
     payload.notification = new Notification().setAlert(ALERT);
     var result = _client.SendPush(payload);
     Assert.IsTrue(result.isResultOK());
 }
        public void testIllegal_NoPlatform()
        {
            Notification notifcation = new Notification().setAlert("alert");

            PushPayload pushPayliad = new PushPayload();
            pushPayliad.audience = Audience.all(); ;
            pushPayliad.notification = notifcation;

            pushPayliad.Check();
        }
Ejemplo n.º 13
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            pushPayload.audience = Audience.s_tag("tag1");
            pushPayload.notification =  Notification.android(ALERT,TITLE);

            return pushPayload;
        }
         public void sendByTagAnd() 
        {
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.s_tag_and(TAG1);
            payload.notification = new Notification().setAlert(ALERT);

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
Ejemplo n.º 15
0
        public void sendMessageContentAndExtras() 
       {
            
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all();
            payload.message = Message.content(MSG_CONTENT).AddExtras("key1", "value1").AddExtras("key2", 222).AddExtras("key3", false);

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
Ejemplo n.º 16
0
        public void sendMessageContentOnly()   
         {
           
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all();
            payload.message = Message.content(MSG_CONTENT);

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
 public void testAndroidExceed2()
 {
     PushPayload payload = new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.all();
     payload.notification = new Notification();
     payload.notification.AndroidNotification = new AndroidNotification().setAlert(LONG_TEXT_3);
     payload.Check();
     Debug.WriteLine("Size: " + UTF8Encoding.UTF8.GetBytes(LONG_TEXT_3).Length);
     Assert.IsTrue(payload.IsAndroidExceedLength(), "Should exceed - " + UTF8Encoding.UTF8.GetBytes(LONG_TEXT_3).Length);
 }
        public void testGlobalExceed()
        {
            PushPayload payload = new PushPayload();
             payload.platform = Platform.all();
             payload.audience = Audience.all();
             payload.message = Message.content(LONG_TEXT_2);
             payload.Check();

             Debug.WriteLine("Size: " + UTF8Encoding.UTF8.GetBytes(LONG_TEXT_2).Length);
             Assert.IsTrue(payload.IsGlobalExceedLength(), "Should exceed - " + UTF8Encoding.UTF8.GetBytes(LONG_TEXT_2).Length);
        }
        public void testIllegal_PlatformAudience()
        {
            Platform platform = Platform.all();
            Audience audience = Audience.all();
           
            PushPayload pushPayliad = new PushPayload();
            pushPayliad.platform = platform;
            pushPayliad.audience = audience;

            pushPayliad.Check();
        }
        public void testIllegal_NoAudience()
        {
            Platform platform = Platform.all();
            Notification notifcation = new Notification().setAlert("alert");

            PushPayload pushPayliad = new PushPayload();

            pushPayliad.platform = platform;
            pushPayliad.notification = notifcation;

            pushPayliad.Check();
        }
 public void sendNotification_android_buildId()
 {
     PushPayload payload = new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.all();
     payload.notification = new Notification()
                            .setAlert(ALERT)
                            .setAndroid(new AndroidNotification()
                                         .setBuilderID(100));
     var result = _client.SendPush(payload);
     Assert.IsTrue(result.isResultOK());
 }
        public void sendAlert_wp() 
        {
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all();

            payload.notification = new Notification()
                               .setAlert("alert")
                               .setWinphone(new WinphoneNotification().setAlert("winphone alert"));
            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
Ejemplo n.º 23
0
       public void sendSimpleMessageAndNotification_Pall() 
      {
          
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all(); 
            payload.audience = Audience.all();
            payload.notification = new Notification().setAlert("\U0001F604");
            payload.message =  Message.content("Pall Nall Mall alert");

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
        public void sendNotification_android_extras()
        {
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all();
            payload.notification = new Notification()
                                   .setAlert(ALERT)
                                   .setAndroid(new AndroidNotification()
                                    .AddExtra("key1", "value1")
                                    .AddExtra("key2", 222));

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
 public SchedulePayload(Name name, Enabled enabled, TriggerPayload trigger, PushPayload push)
 {
     schedule_id = null;
     Debug.Assert(name != null);
     Debug.Assert(enabled.getEnable());
     Debug.Assert(trigger != null);
     Debug.Assert(push != null);
     this.name = name.getName();
     this.enabled = true;
     this.trigger = trigger;
     this.push = push;
     jSetting = new JsonSerializerSettings();
     jSetting.NullValueHandling = NullValueHandling.Ignore;
     jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
 }
 public SchedulePayload(String name, Boolean enabled, TriggerPayload trigger, PushPayload push)
 {
     schedule_id = null;
     Debug.Assert(name != null);
     Debug.Assert(enabled);
     Debug.Assert(trigger != null);
     Debug.Assert(push != null);
     this.name = name;
     this.enabled = enabled;
     this.trigger = trigger;
     this.push = push;
     jSetting = new JsonSerializerSettings();
     jSetting.NullValueHandling = NullValueHandling.Ignore;
     jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
 }
Ejemplo n.º 27
0
        public static PushPayload PushObject_android_and_ios()
        {
            PushPayload pushPayload = new PushPayload();
            pushPayload.platform = Platform.android_ios();
            var audience = Audience.s_tag("tag1");
            pushPayload.audience = audience;
            var notification = new Notification().setAlert("alert content");
            notification.AndroidNotification = new AndroidNotification().setTitle("Android Title");
            notification.IosNotification = new IosNotification();
            notification.IosNotification.incrBadge(1);
            notification.IosNotification.AddExtra("extra_key", "extra_value");

            pushPayload.notification = notification.Check();

            return pushPayload;
        }
 public int sendNotification(String alert)
 {
     PushPayload payload = new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.s_alias("special_c");
     payload.notification = new Notification().setAlert(alert);
     try
     {
         _client.SendPush(payload);
     }
     catch (APIRequestException e)
     {
         return e.ErrorCode;
     }
     return 0;
 }
        public void sendByTag()
        {
            //PushPayload payload = PushPayload.newBuilder()
            //        .setPlatform(Platform.all())
            //        .setAudience(Audience.tag(TAG1))
            //        .setNotification(Notification.alert(ALERT))
            //        .build();

            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.s_tag(TAG1);
            payload.notification = new Notification().setAlert("alert");

            var result = _client.SendPush(payload);
            Assert.IsTrue(result.isResultOK());
        }
 public int sendMessage(String content)
 {
     Message message = Message.content(content).setTitle("title");
     PushPayload payload =new PushPayload();
     payload.platform = Platform.all();
     payload.audience = Audience.s_alias("special_c");
     payload.message  = message;
     try
     {
         _client.SendPush(payload);
     }
     catch (APIRequestException e)
     {
         return e.ErrorCode;
     }
     return 0;
 }