2525import cn .jpush .api .report .ReceivedsResult ;
2626import cn .jpush .api .report .ReportClient ;
2727import cn .jpush .api .report .UsersResult ;
28+ import cn .jpush .api .schedule .ScheduleClient ;
29+ import cn .jpush .api .schedule .ScheduleListResult ;
30+ import cn .jpush .api .schedule .ScheduleResult ;
31+ import cn .jpush .api .schedule .model .SchedulePayload ;
32+ import cn .jpush .api .schedule .model .TriggerPayload ;
2833
2934/**
3035 * The global entrance of JPush API library.
@@ -33,6 +38,7 @@ public class JPushClient {
3338 private final PushClient _pushClient ;
3439 private final ReportClient _reportClient ;
3540 private final DeviceClient _deviceClient ;
41+ private final ScheduleClient _scheduleClient ;
3642
3743 /**
3844 * Create a JPush Client.
@@ -44,18 +50,21 @@ public JPushClient(String masterSecret, String appKey) {
4450 _pushClient = new PushClient (masterSecret , appKey );
4551 _reportClient = new ReportClient (masterSecret , appKey );
4652 _deviceClient = new DeviceClient (masterSecret , appKey );
53+ _scheduleClient = new ScheduleClient (masterSecret , appKey );
4754 }
4855
4956 public JPushClient (String masterSecret , String appKey , int maxRetryTimes ) {
5057 _pushClient = new PushClient (masterSecret , appKey , maxRetryTimes );
5158 _reportClient = new ReportClient (masterSecret , appKey , maxRetryTimes );
5259 _deviceClient = new DeviceClient (masterSecret , appKey , maxRetryTimes );
60+ _scheduleClient = new ScheduleClient (masterSecret , appKey , maxRetryTimes );
5361 }
5462
5563 public JPushClient (String masterSecret , String appKey , int maxRetryTimes , HttpProxy proxy ) {
5664 _pushClient = new PushClient (masterSecret , appKey , maxRetryTimes , proxy );
5765 _reportClient = new ReportClient (masterSecret , appKey , maxRetryTimes , proxy );
5866 _deviceClient = new DeviceClient (masterSecret , appKey , maxRetryTimes , proxy );
67+ _scheduleClient = new ScheduleClient (masterSecret , appKey , maxRetryTimes , proxy );
5968 }
6069
6170 /**
@@ -73,6 +82,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
7382 _pushClient = new PushClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
7483 _reportClient = new ReportClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
7584 _deviceClient = new DeviceClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
85+ _scheduleClient = new ScheduleClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
7686 }
7787
7888 /**
@@ -94,6 +104,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
94104 _pushClient = new PushClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
95105 _reportClient = new ReportClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
96106 _deviceClient = new DeviceClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
107+ _scheduleClient = new ScheduleClient (masterSecret , appKey , maxRetryTimes , proxy , conf );
97108 _pushClient .setDefaults (apnsProduction , timeToLive );
98109 }
99110
@@ -111,6 +122,7 @@ public JPushClient(String masterSecret, String appKey, boolean apnsProduction, l
111122 _pushClient = new PushClient (masterSecret , appKey , apnsProduction , timeToLive );
112123 _reportClient = new ReportClient (masterSecret , appKey );
113124 _deviceClient = new DeviceClient (masterSecret , appKey );
125+ _scheduleClient = new ScheduleClient (masterSecret , appKey );
114126 }
115127
116128
@@ -392,7 +404,58 @@ public DefaultResult deleteAlias(String alias, String platform)
392404 throws APIConnectionException , APIRequestException {
393405 return _deviceClient .deleteAlias (alias , platform );
394406 }
395-
396-
407+
408+ public ScheduleResult createSingleSchedule (String name , String time , PushPayload push )
409+ throws APIConnectionException , APIRequestException {
410+ TriggerPayload trigger = TriggerPayload .newBuilder ()
411+ .setSingleTime (time )
412+ .buildSingle ();
413+ SchedulePayload payload = SchedulePayload .newBuilder ()
414+ .setName (name )
415+ .setEnabled (true )
416+ .setTrigger (trigger )
417+ .setPush (push )
418+ .build ();
419+
420+ return _scheduleClient .createSchedule (payload );
421+ }
422+
423+ public ScheduleResult createPeriodicalSchedule (String name , String start , String end , String time ,
424+ TriggerPayload .TimeUnit timeUnit , int frequency , String [] point , PushPayload push )
425+ throws APIConnectionException , APIRequestException {
426+ TriggerPayload trigger = TriggerPayload .newBuilder ()
427+ .setPeriodTime (start , end , time )
428+ .setTimeFrequency (timeUnit , frequency , point )
429+ .buildPeriodical ();
430+ SchedulePayload payload = SchedulePayload .newBuilder ()
431+ .setName (name )
432+ .setEnabled (true )
433+ .setTrigger (trigger )
434+ .setPush (push )
435+ .build ();
436+
437+ return _scheduleClient .createSchedule (payload );
438+ }
439+
440+ public ScheduleResult getSchedule (String scheduleId )
441+ throws APIConnectionException , APIRequestException {
442+ return _scheduleClient .getSchedule (scheduleId );
443+ }
444+
445+ public ScheduleListResult getScheduleList (int page )
446+ throws APIConnectionException , APIRequestException {
447+ return _scheduleClient .getScheduleList (page );
448+ }
449+
450+ public ScheduleResult updateSchedule (String scheduleId , SchedulePayload payload )
451+ throws APIConnectionException , APIRequestException {
452+ return _scheduleClient .updateSchedule (scheduleId , payload );
453+ }
454+
455+ public void deleteSchedule (String scheduleId )
456+ throws APIConnectionException , APIRequestException {
457+ _scheduleClient .deleteSchedule (scheduleId );
458+ }
459+
397460}
398461
0 commit comments