Skip to content

Commit be69b89

Browse files
author
Max Presman
committed
split up push notifications
1 parent 520e1c4 commit be69b89

8 files changed

Lines changed: 262 additions & 93 deletions

File tree

‎src/main/java/com/pubnub/api/core/Pubnub.java‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77
import com.pubnub.api.endpoints.Time;
88
import com.pubnub.api.endpoints.access.Audit;
99
import com.pubnub.api.endpoints.access.Grant;
10-
import com.pubnub.api.endpoints.channel_groups.AddChannelChannelGroup;
11-
import com.pubnub.api.endpoints.channel_groups.AllChannelsChannelGroup;
12-
import com.pubnub.api.endpoints.channel_groups.DeleteChannelGroup;
13-
import com.pubnub.api.endpoints.channel_groups.ListAllChannelGroup;
14-
import com.pubnub.api.endpoints.channel_groups.RemoveChannelChannelGroup;
10+
import com.pubnub.api.endpoints.channel_groups.*;
1511
import com.pubnub.api.endpoints.presence.GetState;
1612
import com.pubnub.api.endpoints.presence.HereNow;
1713
import com.pubnub.api.endpoints.presence.SetState;
1814
import com.pubnub.api.endpoints.presence.WhereNow;
1915
import com.pubnub.api.endpoints.pubsub.Publish;
20-
import com.pubnub.api.endpoints.push.CreatePushNotification;
21-
import com.pubnub.api.endpoints.push.ListProvisions;
22-
import com.pubnub.api.endpoints.push.ModifyProvisions;
16+
import com.pubnub.api.endpoints.push.*;
2317
import com.pubnub.api.managers.BasePathManager;
2418
import com.pubnub.api.managers.PublishSequenceManager;
2519
import com.pubnub.api.managers.SubscriptionManager;
@@ -78,12 +72,20 @@ public final SubscribeBuilder subscribe() {
7872

7973
// start push
8074

81-
public final ModifyProvisions modifyPushProvisions() {
82-
return new ModifyProvisions(this);
75+
public final AddChannelsToPush addPushNotificationsOnChannels() {
76+
return new AddChannelsToPush(this);
8377
}
8478

85-
public final ListProvisions listPushProvisions() {
86-
return new ListProvisions(this);
79+
public final RemoveChannelsFromPush removePushNotificationsFromChannels() {
80+
return new RemoveChannelsFromPush(this);
81+
}
82+
83+
public final RemoveAllPushChannelsForDevice removeAllPushNotificationsFromDeviceWithPushToken() {
84+
return new RemoveAllPushChannelsForDevice(this);
85+
}
86+
87+
public final ListPushProvisions auditPushChannelProvisions() {
88+
return new ListPushProvisions(this);
8789
}
8890

8991
public final CreatePushNotification createPushNotification() {

‎src/main/java/com/pubnub/api/core/enums/PNOperationType.java‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,27 @@
55
*/
66
public enum PNOperationType {
77
PNSubscribeOperation,
8-
98
PNUnsubscribeOperation,
10-
119
PNPublishOperation,
12-
1310
PNHistoryOperation,
14-
1511
PNWhereNowOperation,
16-
PNHereNowOperation,
1712

1813
PNHeartbeatOperation,
19-
2014
PNSetStateOperation,
21-
PNGetState,
22-
23-
2415
PNAddChannelsToGroupOperation,
2516
PNRemoveChannelsFromGroupOperation,
2617
PNChannelGroupsOperation,
2718
PNRemoveGroupOperation,
2819
PNChannelsForGroupOperation,
29-
30-
PNPushNotificationModifiedChannelsOperations,
31-
PNPushNotificationListChannelsOperation,
32-
3320
PNPushNotificationEnabledChannelsOperation,
3421
PNAddPushNotificationsOnChannelsOperation,
3522
PNRemovePushNotificationsFromChannelsOperation,
3623
PNRemoveAllPushNotificationsOperation,
24+
PNTimeOperation,
3725

26+
// CREATED
27+
PNHereNowOperation,
28+
PNGetState,
3829
PNAccessManagerAudit,
39-
PNAccessManagerGrant,
40-
41-
PNTimeOperation,
30+
PNAccessManagerGrant
4231
}

src/main/java/com/pubnub/api/endpoints/push/ModifyProvisions.java renamed to src/main/java/com/pubnub/api/endpoints/push/AddChannelsToPush.java

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.pubnub.api.core.enums.PushType;
88
import com.pubnub.api.endpoints.Endpoint;
99
import lombok.Setter;
10-
import lombok.Singular;
1110
import lombok.experimental.Accessors;
1211
import retrofit2.Call;
1312
import retrofit2.Response;
@@ -17,18 +16,16 @@
1716
import 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
}

src/main/java/com/pubnub/api/endpoints/push/ListProvisions.java renamed to src/main/java/com/pubnub/api/endpoints/push/ListPushProvisions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import java.util.Map;
1515

1616
@Accessors(chain = true, fluent = true)
17-
public class ListProvisions extends Endpoint<List<String>, List<String>> {
17+
public class ListPushProvisions extends Endpoint<List<String>, List<String>> {
1818

1919
@Setter private PushType pushType;
2020
@Setter private String deviceId;
2121

22-
public ListProvisions(Pubnub pubnub) {
22+
public ListPushProvisions(Pubnub pubnub) {
2323
super(pubnub);
2424
}
2525

@@ -50,7 +50,7 @@ protected int getRequestTimeout() {
5050

5151
@Override
5252
protected PNOperationType getOperationType() {
53-
return PNOperationType.PNPushNotificationListChannelsOperation;
53+
return PNOperationType.PNPushNotificationEnabledChannelsOperation;
5454
}
5555

5656
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.pubnub.api.endpoints.push;
2+
3+
import com.pubnub.api.core.Pubnub;
4+
import com.pubnub.api.core.PubnubException;
5+
import com.pubnub.api.core.enums.PNOperationType;
6+
import com.pubnub.api.core.enums.PushType;
7+
import com.pubnub.api.endpoints.Endpoint;
8+
import lombok.Setter;
9+
import lombok.experimental.Accessors;
10+
import retrofit2.Call;
11+
import retrofit2.Response;
12+
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@Accessors(chain = true, fluent = true)
17+
public class RemoveAllPushChannelsForDevice extends Endpoint<List<Object>, Boolean> {
18+
19+
@Setter private PushType pushType;
20+
@Setter private String deviceId;
21+
22+
public RemoveAllPushChannelsForDevice(Pubnub pubnub) {
23+
super(pubnub);
24+
}
25+
26+
@Override
27+
protected boolean validateParams() {
28+
if (pushType == null) {
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
35+
36+
@Override
37+
protected Call<List<Object>> doWork(Map<String, String> params) throws PubnubException {
38+
params.put("type", pushType.name().toLowerCase());
39+
40+
PushService service = this.createRetrofit().create(PushService.class);
41+
42+
return service.removeAllChannelsForDevice(pubnub.getConfiguration().getSubscribeKey(), deviceId, params);
43+
44+
}
45+
46+
@Override
47+
protected Boolean createResponse(Response<List<Object>> input) throws PubnubException {
48+
return true;
49+
}
50+
51+
protected int getConnectTimeout() {
52+
return pubnub.getConfiguration().getConnectTimeout();
53+
}
54+
55+
protected int getRequestTimeout() {
56+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
57+
}
58+
59+
@Override
60+
protected PNOperationType getOperationType() {
61+
return null; // PNOperationType.PNPushNotificationModifiedChannelsOperations;
62+
}
63+
64+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.pubnub.api.endpoints.push;
2+
3+
import com.pubnub.api.core.Pubnub;
4+
import com.pubnub.api.core.PubnubException;
5+
import com.pubnub.api.core.PubnubUtil;
6+
import com.pubnub.api.core.enums.PNOperationType;
7+
import com.pubnub.api.core.enums.PushType;
8+
import com.pubnub.api.endpoints.Endpoint;
9+
import lombok.Setter;
10+
import lombok.experimental.Accessors;
11+
import retrofit2.Call;
12+
import retrofit2.Response;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
import java.util.Map;
17+
18+
@Accessors(chain = true, fluent = true)
19+
public class RemoveChannelsFromPush extends Endpoint<List<Object>, Boolean> {
20+
21+
@Setter private PushType pushType;
22+
@Setter private List<String> channels;
23+
@Setter String deviceId;
24+
25+
public RemoveChannelsFromPush(Pubnub pubnub) {
26+
super(pubnub);
27+
28+
channels = new ArrayList<>();
29+
}
30+
31+
@Override
32+
protected boolean validateParams() {
33+
if (pushType == null) {
34+
return false;
35+
}
36+
37+
if (deviceId == null || deviceId.length() == 0) {
38+
return false;
39+
}
40+
41+
if (channels.size() == 0) {
42+
return false;
43+
}
44+
45+
return true;
46+
}
47+
48+
@Override
49+
protected Call<List<Object>> doWork(Map<String, String> baseParams) throws PubnubException {
50+
baseParams.put("type", pushType.name().toLowerCase());
51+
52+
if (channels.size() != 0) {
53+
baseParams.put("remove", PubnubUtil.joinString(channels, ","));
54+
}
55+
56+
PushService service = this.createRetrofit().create(PushService.class);
57+
return service.modifyChannelsForDevice(pubnub.getConfiguration().getSubscribeKey(), deviceId, baseParams);
58+
59+
}
60+
61+
@Override
62+
protected Boolean createResponse(Response<List<Object>> input) throws PubnubException {
63+
return null;
64+
}
65+
66+
protected int getConnectTimeout() {
67+
return pubnub.getConfiguration().getConnectTimeout();
68+
}
69+
70+
protected int getRequestTimeout() {
71+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
72+
}
73+
74+
@Override
75+
protected PNOperationType getOperationType() {
76+
return PNOperationType.PNRemovePushNotificationsFromChannelsOperation;
77+
}
78+
}

src/test/java/com.pubnub.api/endpoints/push/ListProvisionsTest.java renamed to src/test/java/com.pubnub.api/endpoints/push/ListPushProvisionsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
import static com.github.tomakehurst.wiremock.client.WireMock.*;
1616
import static org.junit.Assert.assertEquals;
1717

18-
public class ListProvisionsTest extends TestHarness {
18+
public class ListPushProvisionsTest extends TestHarness {
1919

2020
@Rule
2121
public WireMockRule wireMockRule = new WireMockRule();
2222

23-
private ListProvisions instance;
23+
private ListPushProvisions instance;
2424

2525

2626
@Before
2727
public void beforeEach() throws IOException {
28-
instance = this.createPubNubInstance(8080).listPushProvisions();
28+
instance = this.createPubNubInstance(8080).auditPushChannelProvisions();
2929
}
3030

3131
@Test

0 commit comments

Comments
 (0)