Skip to content

Commit 2f5ea67

Browse files
committed
Add support for channel group operations
LISTING ALL REGISTERED CHANNEL GROUPS @get("v2/channel-registration/sub-key/{subKey}/channel-group") LISTING ALL CHANNELS FOR A CHANNEL GROUP @get("v2/channel-registration/sub-key/{subKey}/channel-group/{group}") ADDING CHANNELS // NEW CHANNEL GROUP @get("v2/channel-registration/sub-key/{subKey}/channel-group/{group}") REMOVING CHANNELS @get("v2/channel-registration/sub-key/{subKey}/channel-group/{group}") DELETING A CHANNEL GROUP @get("v2/channel-registration/sub-key/{subKey}/channel-group/{group_name}/remove")
1 parent 944f7c0 commit 2f5ea67

12 files changed

Lines changed: 621 additions & 0 deletions

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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.*;
1011
import com.pubnub.api.endpoints.presence.*;
1112
import com.pubnub.api.endpoints.pubsub.Publish;
1213
import com.pubnub.api.endpoints.push.CreatePushNotification;
@@ -206,4 +207,11 @@ private String fetchSDKVersion() {
206207
}
207208
}
208209

210+
public final ChannelGroupListAll.ChannelGroupListAllBuilder channelGroupListAll() {return ChannelGroupListAll.builder().pubnub(this); }
211+
public final AllChannelsChannelGroup.AllChannelsChannelGroupBuilder allChannelsChannelGroup() {return AllChannelsChannelGroup.builder().pubnub(this);}
212+
public final AddChannelChannelGroup.AddChannelChannelGroupBuilder addChannelChannelGroup() {return AddChannelChannelGroup.builder().pubnub(this);}
213+
public final RemoveChannel.RemoveChannelBuilder removeChannel() {return RemoveChannel.builder().pubnub(this);}
214+
public final DeleteChannelGroup.DeleteChannelGroupBuilder deleteChannelGroup() {return DeleteChannelGroup.builder().pubnub(this); }
215+
216+
209217
}
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.*;
4+
import com.pubnub.api.core.models.Envelope;
5+
import com.pubnub.api.endpoints.Endpoint;
6+
import lombok.Builder;
7+
import lombok.Singular;
8+
import retrofit2.Call;
9+
import retrofit2.Response;
10+
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
@Builder
16+
public class AddChannelChannelGroup extends Endpoint<Envelope,Void> {
17+
private Pubnub pubnub;
18+
private String group;
19+
@Singular
20+
private List<String> channels;
21+
private String uuid;
22+
23+
@Override
24+
protected boolean validateParams() { return true;}
25+
26+
@Override
27+
protected final Call<Envelope> doWork() throws PubnubException {
28+
String channelCSV;
29+
Map<String, String> params = new HashMap<String, String>();
30+
31+
if (group==null) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"group cannot be null");
32+
if (channels.size() == 0) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"channel cannot be null");
33+
34+
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
35+
36+
channelCSV = PubnubUtil.joinString(channels, ",");
37+
38+
params.put("add", channelCSV);
39+
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
40+
41+
return service.AddChannelChannelGroup(pubnub.getConfiguration().getSubscribeKey(), group , params);
42+
}
43+
44+
@Override
45+
protected PnResponse createResponse(Response<Envelope> input) {
46+
PnResponse pnResponse = new PnResponse();
47+
pnResponse.fillFromRetrofit(input);
48+
pnResponse.setPayload("");
49+
50+
return pnResponse;
51+
}
52+
53+
protected int getConnectTimeout() {
54+
return pubnub.getConfiguration().getConnectTimeout();
55+
}
56+
57+
protected int getRequestTimeout() {
58+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
59+
}
60+
61+
62+
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.PnResponse;
4+
import com.pubnub.api.core.Pubnub;
5+
import com.pubnub.api.core.PubnubError;
6+
import com.pubnub.api.core.PubnubException;
7+
import com.pubnub.api.core.models.Envelope;
8+
import com.pubnub.api.endpoints.Endpoint;
9+
import lombok.Builder;
10+
import lombok.Singular;
11+
import retrofit2.Call;
12+
import retrofit2.Response;
13+
14+
import java.util.HashMap;
15+
import java.util.List;
16+
import java.util.Map;
17+
18+
@Builder
19+
public class AllChannelsChannelGroup extends Endpoint<Envelope<Object>,Map<String, Object>>
20+
{
21+
private Pubnub pubnub;
22+
private String group;
23+
private String uuid;
24+
25+
26+
@Override
27+
protected boolean validateParams() {return true;}
28+
29+
@Override
30+
protected final Call<Envelope<Object>> doWork() throws PubnubException {
31+
Map<String, String> params = new HashMap<String, String>();
32+
33+
if (group==null) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"group cannot be null");
34+
35+
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
36+
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
37+
38+
return service.AllChannelsChannelGroup(pubnub.getConfiguration().getSubscribeKey(), group , params);
39+
}
40+
41+
@Override
42+
protected PnResponse<Map<String, Object>> createResponse(Response<Envelope<Object>> input) {
43+
PnResponse<Map<String, Object>> pnResponse = new PnResponse<Map<String, Object>>();
44+
pnResponse.fillFromRetrofit(input);
45+
46+
if (input.body() != null && input.body().getPayload()!=null) {
47+
Map<String, Object> stateMappings;
48+
stateMappings = (Map<String, Object>) input.body().getPayload();
49+
pnResponse.setPayload(stateMappings);
50+
}
51+
52+
return pnResponse;
53+
}
54+
55+
protected int getConnectTimeout() {
56+
return pubnub.getConfiguration().getConnectTimeout();
57+
}
58+
59+
protected int getRequestTimeout() {
60+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
61+
}
62+
63+
64+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.PnResponse;
4+
import com.pubnub.api.core.Pubnub;
5+
import com.pubnub.api.core.PubnubException;
6+
import com.pubnub.api.core.models.Envelope;
7+
import com.pubnub.api.endpoints.Endpoint;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
import lombok.Builder;
13+
import retrofit2.Call;
14+
import retrofit2.Response;
15+
16+
17+
@Builder
18+
public class ChannelGroupListAll extends Endpoint<Envelope<Object>,Map<String, Object>>
19+
{
20+
private Pubnub pubnub;
21+
private String uuid;
22+
23+
@Override
24+
protected boolean validateParams() {
25+
return true;
26+
}
27+
28+
@Override
29+
protected final Call<Envelope<Object>> doWork() throws PubnubException {
30+
Map<String, String> params = new HashMap<String, String>();
31+
32+
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
33+
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
34+
35+
return service.ChannelGroupListAll(pubnub.getConfiguration().getSubscribeKey(), params);
36+
}
37+
38+
@Override
39+
protected PnResponse<Map<String, Object>> createResponse(Response<Envelope<Object>> input) {
40+
PnResponse<Map<String, Object>> pnResponse = new PnResponse<Map<String, Object>>();
41+
pnResponse.fillFromRetrofit(input);
42+
43+
if (input.body() != null && input.body().getPayload()!=null) {
44+
Map<String, Object> stateMappings;
45+
stateMappings = (Map<String, Object>) input.body().getPayload();
46+
pnResponse.setPayload(stateMappings);
47+
}
48+
49+
return pnResponse;
50+
}
51+
52+
protected int getConnectTimeout() {
53+
return pubnub.getConfiguration().getConnectTimeout();
54+
}
55+
56+
protected int getRequestTimeout() {
57+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
58+
}
59+
60+
}
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>> ChannelGroupListAll(@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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.PnResponse;
4+
import com.pubnub.api.core.Pubnub;
5+
import com.pubnub.api.core.PubnubError;
6+
import com.pubnub.api.core.PubnubException;
7+
import com.pubnub.api.core.models.Envelope;
8+
import com.pubnub.api.endpoints.Endpoint;
9+
import lombok.Builder;
10+
import retrofit2.Call;
11+
import retrofit2.Response;
12+
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
@Builder
17+
public class DeleteChannelGroup extends Endpoint<Envelope,Void>
18+
{
19+
private Pubnub pubnub;
20+
private String group_name;
21+
private String uuid;
22+
23+
@Override
24+
protected boolean validateParams() {return true;}
25+
26+
@Override
27+
protected final Call<Envelope> doWork() throws PubnubException {
28+
Map<String, String> params = new HashMap<String, String>();
29+
30+
if (group_name==null) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"group cannot be null");
31+
32+
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
33+
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
34+
35+
return service.DeleteChannelGroup(pubnub.getConfiguration().getSubscribeKey(), group_name , params);
36+
}
37+
38+
@Override
39+
protected PnResponse createResponse(Response<Envelope> input) {
40+
PnResponse pnResponse = new PnResponse();
41+
pnResponse.fillFromRetrofit(input);
42+
pnResponse.setPayload("");
43+
44+
return pnResponse;
45+
}
46+
47+
protected int getConnectTimeout() {
48+
return pubnub.getConfiguration().getConnectTimeout();
49+
}
50+
51+
protected int getRequestTimeout() {
52+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
53+
}
54+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.pubnub.api.endpoints.channel_groups;
2+
3+
import com.pubnub.api.core.*;
4+
import com.pubnub.api.core.models.Envelope;
5+
import com.pubnub.api.endpoints.Endpoint;
6+
import lombok.Builder;
7+
import lombok.Singular;
8+
import retrofit2.Call;
9+
import retrofit2.Response;
10+
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
@Builder
16+
public class RemoveChannel extends Endpoint<Envelope,Void>
17+
{
18+
private Pubnub pubnub;
19+
private String group;
20+
@Singular
21+
private List<String> channels;
22+
private String uuid;
23+
24+
@Override
25+
protected boolean validateParams() {return true;}
26+
27+
@Override
28+
protected final Call<Envelope> doWork() throws PubnubException {
29+
Map<String, String> params = new HashMap<String, String>();
30+
String channelCSV;
31+
32+
if (group==null) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"group cannot be null");
33+
if (channels.size() == 0) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"channel cannot be null");
34+
35+
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
36+
37+
channelCSV = PubnubUtil.joinString(channels, ",");
38+
39+
params.put("remove", channelCSV);
40+
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
41+
42+
return service.RemoveChannel(pubnub.getConfiguration().getSubscribeKey(), group , params);
43+
}
44+
45+
@Override
46+
protected PnResponse createResponse(Response<Envelope> input) {
47+
PnResponse pnResponse = new PnResponse();
48+
pnResponse.fillFromRetrofit(input);
49+
pnResponse.setPayload("");
50+
51+
return pnResponse;
52+
}
53+
54+
protected int getConnectTimeout() {
55+
return pubnub.getConfiguration().getConnectTimeout();
56+
}
57+
58+
protected int getRequestTimeout() {
59+
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
60+
}
61+
}

0 commit comments

Comments
 (0)