com.pubnub.api.endpoints.channel_groups.AddChannelChannelGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub Show documentation
Show all versions of pubnub Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of
broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter
second!
package com.pubnub.api.endpoints.channel_groups;
import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubException;
import com.pubnub.api.PubNubUtil;
import com.pubnub.api.builder.PubNubErrorBuilder;
import com.pubnub.api.endpoints.Endpoint;
import com.pubnub.api.enums.PNOperationType;
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsAddChannelResult;
import com.pubnub.api.models.server.Envelope;
import lombok.Setter;
import lombok.experimental.Accessors;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Accessors(chain = true, fluent = true)
public class AddChannelChannelGroup extends Endpoint {
@Setter
private String channelGroup;
@Setter
private List channels;
public AddChannelChannelGroup(PubNub pubnub, Retrofit retrofit) {
super(pubnub, retrofit);
channels = new ArrayList<>();
}
@Override
protected void validateParams() throws PubNubException {
if (channelGroup == null || channelGroup.isEmpty()) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_GROUP_MISSING).build();
}
if (channels.size() == 0) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_CHANNEL_MISSING).build();
}
}
@Override
protected Call doWork(final Map params) {
ChannelGroupService service = this.getRetrofit().create(ChannelGroupService.class);
if (channels.size() > 0) {
params.put("add", PubNubUtil.joinString(channels, ","));
}
return service.addChannelChannelGroup(this.getPubnub().getConfiguration().getSubscribeKey(), channelGroup, params);
}
@Override
protected PNChannelGroupsAddChannelResult createResponse(Response input) throws PubNubException {
if (input.body() == null) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PARSING_ERROR).build();
}
return PNChannelGroupsAddChannelResult.builder().build();
}
@Override
protected PNOperationType getOperationType() {
return PNOperationType.PNAddChannelsToGroupOperation;
}
@Override
protected boolean isAuthRequired() {
return true;
}
}