77import com .pubnub .api .core .enums .PushType ;
88import com .pubnub .api .endpoints .Endpoint ;
99import lombok .Setter ;
10- import lombok .Singular ;
1110import lombok .experimental .Accessors ;
1211import retrofit2 .Call ;
1312import retrofit2 .Response ;
1716import java .util .Map ;
1817
1918@ Accessors (chain = true , fluent = true )
20- public class ModifyProvisions extends Endpoint <List <Object >, Boolean > {
19+ public class AddChannelsToPush extends Endpoint <List <Object >, Boolean > {
2120
2221 @ Setter private PushType pushType ;
23- @ Setter private @ Singular List <String > addChannels ;
24- @ Setter private @ Singular List <String > removeChannels ;
22+ @ Setter private List <String > channels ;
2523 @ Setter String deviceId ;
26- @ Setter private boolean removeAllChannels ;
2724
28- public ModifyProvisions (Pubnub pubnub ) {
25+ public AddChannelsToPush (Pubnub pubnub ) {
2926 super (pubnub );
30- addChannels = new ArrayList <>();
31- removeChannels = new ArrayList <>();
27+
28+ channels = new ArrayList <>();
3229 }
3330
3431 @ Override
@@ -41,40 +38,29 @@ protected boolean validateParams() {
4138 return false ;
4239 }
4340
44- return true ;
45- }
41+ if (channels .size () == 0 ) {
42+ return false ;
43+ }
4644
47- public ModifyProvisions removeAllChannels () {
48- removeAllChannels = true ;
49- return this ;
45+ return true ;
5046 }
5147
5248 @ Override
53- protected Call <List <Object >> doWork (Map <String , String > params ) throws PubnubException {
54- params .put ("type" , pushType .name ().toLowerCase ());
49+ protected Call <List <Object >> doWork (Map <String , String > baseParams ) throws PubnubException {
50+ baseParams .put ("type" , pushType .name ().toLowerCase ());
5551
56- if (addChannels .size () != 0 ) {
57- params .put ("add" , PubnubUtil .joinString (addChannels , "," ));
58- }
59-
60- if (removeChannels .size () != 0 ) {
61- params .put ("remove" , PubnubUtil .joinString (removeChannels , "," ));
52+ if (channels .size () != 0 ) {
53+ baseParams .put ("add" , PubnubUtil .joinString (channels , "," ));
6254 }
6355
6456 PushService service = this .createRetrofit ().create (PushService .class );
65-
66- if (this .removeAllChannels ) {
67- return service .removeAllChannelsForDevice (pubnub .getConfiguration ().getSubscribeKey (), deviceId , params );
68- } else {
69- return service .modifyChannelsForDevice (pubnub .getConfiguration ().getSubscribeKey (), deviceId , params );
70- }
71-
57+ return service .modifyChannelsForDevice (pubnub .getConfiguration ().getSubscribeKey (), deviceId , baseParams );
7258
7359 }
7460
7561 @ Override
7662 protected Boolean createResponse (Response <List <Object >> input ) throws PubnubException {
77- return true ;
63+ return null ;
7864 }
7965
8066 protected int getConnectTimeout () {
@@ -87,7 +73,6 @@ protected int getRequestTimeout() {
8773
8874 @ Override
8975 protected PNOperationType getOperationType () {
90- return PNOperationType .PNPushNotificationModifiedChannelsOperations ;
76+ return PNOperationType .PNPushNotificationEnabledChannelsOperation ;
9177 }
92-
9378}
0 commit comments