Skip to content

Commit 37732a3

Browse files
author
Max Presman
committed
moving over channel groups
2 parents 17b846c + 71436c3 commit 37732a3

15 files changed

Lines changed: 573 additions & 2 deletions

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
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;
1015
import com.pubnub.api.endpoints.presence.GetState;
1116
import com.pubnub.api.endpoints.presence.HereNow;
1217
import com.pubnub.api.endpoints.presence.SetState;
@@ -119,6 +124,26 @@ public final Publish publish() {
119124
return new Publish(this, publishSequenceManager);
120125
}
121126

127+
public final ListAllChannelGroup listChannelsForChannelGroup() {
128+
return new ListAllChannelGroup(this);
129+
}
130+
131+
public final AllChannelsChannelGroup allChannelsInChannelGroup() {
132+
return new AllChannelsChannelGroup(this);
133+
}
134+
135+
public final AddChannelChannelGroup addChannelsToChannelGroup() {
136+
return new AddChannelChannelGroup(this);
137+
}
138+
139+
public final RemoveChannelChannelGroup removeChannelsFromChannelGroup() {
140+
return new RemoveChannelChannelGroup(this);
141+
}
142+
143+
public final DeleteChannelGroup deleteChannelGroup() {
144+
return new DeleteChannelGroup(this);
145+
}
146+
122147
// public methods
123148

124149
/**
@@ -207,5 +232,4 @@ private String fetchSDKVersion() {
207232
return prop.getProperty("version");
208233

209234
}
210-
211235
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.pubnub.api.core.models.consumer_facing;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class PNChannelGroupsAllChannelsResult extends PNResult {
11+
private List<String> channels;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.pubnub.api.core.models.consumer_facing;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class PNChannelGroupsListAllResult extends PNResult {
11+
private List<String> groups;
12+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.pubnub.api.endpoints.channel_groups;
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.models.Envelope;
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 AddChannelChannelGroup extends Endpoint<Envelope, Boolean> {
20+
@Setter private String channelGroup;
21+
@Setter private List<String> channels;
22+
23+
24+
public AddChannelChannelGroup(Pubnub pubnub) {
25+
super(pubnub);
26+
channels = new ArrayList<>();
27+
}
28+
29+
@Override
30+
protected boolean validateParams() {
31+
return true;
32+
}
33+
34+
@Override
35+
protected Call<Envelope> doWork(Map<String, String> params) {
36+
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
37+
38+
if (channels.size() > 0) {
39+
params.put("add", PubnubUtil.joinString(channels, ","));
40+
}
41+
42+
return service.AddChannelChannelGroup(pubnub.getConfiguration().getSubscribeKey(), channelGroup, params);
43+
}
44+
45+
@Override
46+
protected Boolean createResponse(Response<Envelope> input) throws PubnubException {
47+
return true;
48+
}
49+
50+
protected int getConnectTimeout() {
51+
return pubnub.getConfiguration().getConnectTimeout();
52+
}
53+
54+
protected int getRequestTimeout() {
55+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
56+
}
57+
58+
@Override
59+
protected PNOperationType getOperationType() {
60+
return PNOperationType.PNAddChannelsToGroupOperation;
61+
}
62+
63+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.Pubnub;
4+
import com.pubnub.api.core.PubnubError;
5+
import com.pubnub.api.core.PubnubException;
6+
import com.pubnub.api.core.enums.PNOperationType;
7+
import com.pubnub.api.core.models.Envelope;
8+
import com.pubnub.api.core.models.consumer_facing.PNChannelGroupsAllChannelsResult;
9+
import com.pubnub.api.endpoints.Endpoint;
10+
import lombok.Setter;
11+
import lombok.experimental.Accessors;
12+
import retrofit2.Call;
13+
import retrofit2.Response;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
@Accessors(chain = true, fluent = true)
20+
public class AllChannelsChannelGroup extends Endpoint<Envelope<Object>, PNChannelGroupsAllChannelsResult> {
21+
@Setter private String channelGroup;
22+
23+
public AllChannelsChannelGroup(Pubnub pubnub) {
24+
super(pubnub);
25+
}
26+
27+
@Override
28+
protected boolean validateParams() {
29+
return true;
30+
}
31+
32+
@Override
33+
protected Call<Envelope<Object>> doWork(Map<String, String> params) {
34+
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
35+
36+
return service.AllChannelsChannelGroup(pubnub.getConfiguration().getSubscribeKey(), channelGroup, params);
37+
}
38+
39+
@Override
40+
protected PNChannelGroupsAllChannelsResult createResponse(Response<Envelope<Object>> input) throws PubnubException {
41+
Map<String, Object> stateMappings;
42+
43+
if (input.body() == null || input.body().getPayload() == null) {
44+
throw PubnubException.builder().pubnubError(PubnubError.PNERROBJ_PARSING_ERROR).build();
45+
}
46+
47+
PNChannelGroupsAllChannelsResult pnChannelGroupsAllChannelsResult = new PNChannelGroupsAllChannelsResult();
48+
49+
stateMappings = (Map<String, Object>) input.body().getPayload();
50+
List<String> channels = (ArrayList<String>) stateMappings.get("channels");
51+
pnChannelGroupsAllChannelsResult.setChannels(channels);
52+
53+
return pnChannelGroupsAllChannelsResult;
54+
}
55+
56+
protected int getConnectTimeout() {
57+
return pubnub.getConfiguration().getConnectTimeout();
58+
}
59+
60+
protected int getRequestTimeout() {
61+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
62+
}
63+
64+
@Override
65+
protected PNOperationType getOperationType() {
66+
return PNOperationType.PNChannelsForGroupOperation;
67+
}
68+
69+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.models.Envelope;
4+
import retrofit2.Call;
5+
import retrofit2.http.GET;
6+
import retrofit2.http.Path;
7+
import retrofit2.http.QueryMap;
8+
import java.util.Map;
9+
10+
11+
public interface ChannelGroupService {
12+
@GET("v2/channel-registration/sub-key/{subKey}/channel-group")
13+
Call<Envelope<Object>> ListAllChannelGroup(@Path("subKey") String subKey,
14+
@QueryMap Map<String, String> options);
15+
16+
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
17+
Call<Envelope<Object>> AllChannelsChannelGroup(@Path("subKey") String subKey,
18+
@Path("group") String group,
19+
@QueryMap Map<String, String> options);
20+
21+
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
22+
Call<Envelope> AddChannelChannelGroup(@Path("subKey") String subKey,
23+
@Path("group") String group,
24+
@QueryMap Map<String, String> options);
25+
26+
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
27+
Call<Envelope> RemoveChannel(@Path("subKey") String subKey,
28+
@Path("group") String group,
29+
@QueryMap Map<String, String> options);
30+
31+
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group_name}/remove")
32+
Call<Envelope> DeleteChannelGroup(@Path("subKey") String subKey,
33+
@Path("group_name") String group,
34+
@QueryMap Map<String, String> options);
35+
}
36+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.pubnub.api.endpoints.channel_groups;
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.models.Envelope;
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.Map;
14+
15+
@Accessors(chain = true, fluent = true)
16+
public class DeleteChannelGroup extends Endpoint<Envelope,Boolean> {
17+
@Setter private String channelGroup;
18+
19+
public DeleteChannelGroup(Pubnub pubnub) {
20+
super(pubnub);
21+
}
22+
23+
@Override
24+
protected boolean validateParams() {
25+
return true;
26+
}
27+
28+
@Override
29+
protected Call<Envelope> doWork(Map<String, String> params) {
30+
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
31+
32+
return service.DeleteChannelGroup(pubnub.getConfiguration().getSubscribeKey(), channelGroup, params);
33+
}
34+
35+
@Override
36+
protected Boolean createResponse(Response<Envelope> input) throws PubnubException {
37+
return true;
38+
}
39+
40+
protected int getConnectTimeout() {
41+
return pubnub.getConfiguration().getConnectTimeout();
42+
}
43+
44+
protected int getRequestTimeout() {
45+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
46+
}
47+
48+
@Override
49+
protected PNOperationType getOperationType() {
50+
return PNOperationType.PNRemoveGroupOperation;
51+
}
52+
53+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.Pubnub;
4+
import com.pubnub.api.core.PubnubError;
5+
import com.pubnub.api.core.PubnubException;
6+
import com.pubnub.api.core.enums.PNOperationType;
7+
import com.pubnub.api.core.models.Envelope;
8+
import com.pubnub.api.core.models.consumer_facing.PNChannelGroupsListAllResult;
9+
import com.pubnub.api.endpoints.Endpoint;
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 ListAllChannelGroup extends Endpoint<Envelope<Object>, PNChannelGroupsListAllResult> {
20+
21+
public ListAllChannelGroup(Pubnub pubnub) {
22+
super(pubnub);
23+
}
24+
25+
@Override
26+
protected boolean validateParams() {
27+
return true;
28+
}
29+
30+
@Override
31+
protected Call<Envelope<Object>> doWork(Map<String, String> params) {
32+
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
33+
34+
return service.ListAllChannelGroup(pubnub.getConfiguration().getSubscribeKey(), params);
35+
}
36+
37+
@Override
38+
protected PNChannelGroupsListAllResult createResponse(Response<Envelope<Object>> input) throws PubnubException {
39+
Map<String, Object> stateMappings;
40+
41+
if (input.body() == null || input.body().getPayload() == null) {
42+
throw PubnubException.builder().pubnubError(PubnubError.PNERROBJ_PARSING_ERROR).build();
43+
}
44+
45+
PNChannelGroupsListAllResult pnChannelGroupsListAllResult = new PNChannelGroupsListAllResult();
46+
47+
stateMappings = (Map<String, Object>) input.body().getPayload();
48+
List<String> groups = (ArrayList<String>) stateMappings.get("groups");
49+
pnChannelGroupsListAllResult.setGroups(groups);
50+
51+
return pnChannelGroupsListAllResult;
52+
}
53+
54+
protected int getConnectTimeout() {
55+
return pubnub.getConfiguration().getConnectTimeout();
56+
}
57+
58+
protected int getRequestTimeout() {
59+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
60+
}
61+
62+
@Override
63+
protected PNOperationType getOperationType() {
64+
return PNOperationType.PNChannelGroupsOperation;
65+
}
66+
67+
}

0 commit comments

Comments
 (0)