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