11package com .pubnub .api .endpoints .channel_groups ;
22
3- import com .pubnub .api .core .PnResponse ;
43import com .pubnub .api .core .Pubnub ;
54import com .pubnub .api .core .PubnubError ;
65import com .pubnub .api .core .PubnubException ;
6+ import com .pubnub .api .core .enums .PNOperationType ;
77import com .pubnub .api .core .models .Envelope ;
8+ import com .pubnub .api .core .models .consumer_facing .PNChannelGroupsAllChannelsResult ;
89import com .pubnub .api .endpoints .Endpoint ;
9- import lombok .Builder ;
10- import lombok .Singular ;
11- import retrofit2 .Call ;
12- import retrofit2 .Response ;
1310
14- import java .util .HashMap ;
11+ import java .util .ArrayList ;
1512import java .util .List ;
1613import java .util .Map ;
14+ import lombok .Setter ;
15+ import lombok .experimental .Accessors ;
16+ import retrofit2 .Call ;
17+ import retrofit2 .Response ;
1718
18- @ Builder
19- public class AllChannelsChannelGroup extends Endpoint <Envelope <Object >,Map < String , Object > >
19+ @ Accessors ( chain = true , fluent = true )
20+ public class AllChannelsChannelGroup extends Endpoint <Envelope <Object >,PNChannelGroupsAllChannelsResult >
2021{
21- private Pubnub pubnub ;
22- private String group ;
23- private String uuid ;
22+ @ Setter private String uuid ;
23+ @ Setter private String group ;
2424
25+ public AllChannelsChannelGroup (Pubnub pubnub ) {
26+ super (pubnub );
27+ }
2528
2629 @ Override
27- protected boolean validateParams () {return true ;}
30+ protected boolean validateParams () {
31+ return true ;
32+ }
2833
2934 @ 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 );
35+ protected Call <Envelope <Object >> doWork (Map <String , String > params ) {
36+ ChannelGroupService service = this .createRetrofit ().create (ChannelGroupService .class );
3637 params .put ("uuid" , this .uuid != null ? this .uuid : pubnub .getConfiguration ().getUuid ());
3738
38- return service .AllChannelsChannelGroup (pubnub .getConfiguration ().getSubscribeKey (), group , params );
39+ return service .AllChannelsChannelGroup (pubnub .getConfiguration ().getSubscribeKey (), group , params );
3940 }
4041
4142 @ 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 );
43+ protected PNChannelGroupsAllChannelsResult createResponse (Response <Envelope <Object >> input ) throws PubnubException {
44+ Map <String , Object > stateMappings ;
45+
46+ if (input .body () == null || input .body ().getPayload () == null ) {
47+ throw PubnubException .builder ().pubnubError (PubnubError .PNERROBJ_PARSING_ERROR ).build ();
5048 }
5149
52- return pnResponse ;
50+ PNChannelGroupsAllChannelsResult pnChannelGroupsAllChannelsResult = new PNChannelGroupsAllChannelsResult ();
51+
52+ stateMappings = (Map <String , Object >) input .body ().getPayload ();
53+ List <String > channels = (ArrayList <String >) stateMappings .get ("channels" );
54+ pnChannelGroupsAllChannelsResult .setChannels (channels );
55+
56+ return pnChannelGroupsAllChannelsResult ;
5357 }
5458
5559 protected int getConnectTimeout () {
@@ -60,5 +64,9 @@ protected int getRequestTimeout() {
6064 return pubnub .getConfiguration ().getNonSubscribeRequestTimeout ();
6165 }
6266
67+ @ Override
68+ protected PNOperationType getOperationType () {
69+ return PNOperationType .PNChannelsForGroupOperation ;
70+ }
6371
6472}
0 commit comments