com.pubnub.api.endpoints.channel_groups.AllChannelsChannelGroup 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.builder.PubNubErrorBuilder;
import com.pubnub.api.endpoints.Endpoint;
import com.pubnub.api.enums.PNOperationType;
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsAllChannelsResult;
import com.pubnub.api.models.server.Envelope;
import lombok.Setter;
import lombok.experimental.Accessors;
import retrofit2.Call;
import retrofit2.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Accessors(chain = true, fluent = true)
public class AllChannelsChannelGroup extends Endpoint, PNChannelGroupsAllChannelsResult> {
@Setter
private String channelGroup;
public AllChannelsChannelGroup(PubNub pubnub) {
super(pubnub);
}
@Override
protected void validateParams() throws PubNubException {
if (channelGroup == null || channelGroup.isEmpty()) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_GROUP_MISSING).build();
}
}
@Override
protected Call> doWork(Map params) {
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
return service.allChannelsChannelGroup(this.getPubnub().getConfiguration().getSubscribeKey(), channelGroup, params);
}
@Override
protected PNChannelGroupsAllChannelsResult createResponse(Response> input) throws PubNubException {
Map stateMappings;
if (input.body() == null || input.body().getPayload() == null) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PARSING_ERROR).build();
}
stateMappings = (Map) input.body().getPayload();
List channels = (ArrayList) stateMappings.get("channels");
return PNChannelGroupsAllChannelsResult.builder()
.channels(channels)
.build();
}
protected int getConnectTimeout() {
return this.getPubnub().getConfiguration().getConnectTimeout();
}
protected int getRequestTimeout() {
return this.getPubnub().getConfiguration().getNonSubscribeRequestTimeout();
}
@Override
protected PNOperationType getOperationType() {
return PNOperationType.PNChannelsForGroupOperation;
}
@Override
protected boolean isAuthRequired() {
return true;
}
}