|
| 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 | +} |
0 commit comments