Skip to content

Commit 71436c3

Browse files
committed
New Endpoin API
1 parent 2f5ea67 commit 71436c3

17 files changed

Lines changed: 394 additions & 368 deletions

‎src/main/java/com/pubnub/api/core/Pubnub.java‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.*;
2424
import java.nio.file.Files;
2525
import java.nio.file.Paths;
26+
import java.util.Properties;
2627

2728

2829
@Getter
@@ -194,24 +195,35 @@ public final void stop() {
194195
* @return Stringified representation of the SDK version.
195196
*/
196197
private String fetchSDKVersion() {
197-
byte[] encoded;
198+
Properties prop = new Properties();
199+
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("version.properties");
198200
try {
199-
encoded = Files.readAllBytes(Paths.get(Pubnub.class.getClassLoader().getResource("version.properties").getPath()));
201+
prop.load(in);
200202
} catch (IOException e) {
201203
return "N/A";
202204
}
203-
try {
204-
return new String(encoded, "UTF-8").trim();
205-
} catch (UnsupportedEncodingException e) {
206-
return "N/A";
207-
}
208-
}
209205

210-
public final ChannelGroupListAll.ChannelGroupListAllBuilder channelGroupListAll() {return ChannelGroupListAll.builder().pubnub(this); }
211-
public final AllChannelsChannelGroup.AllChannelsChannelGroupBuilder allChannelsChannelGroup() {return AllChannelsChannelGroup.builder().pubnub(this);}
212-
public final AddChannelChannelGroup.AddChannelChannelGroupBuilder addChannelChannelGroup() {return AddChannelChannelGroup.builder().pubnub(this);}
213-
public final RemoveChannel.RemoveChannelBuilder removeChannel() {return RemoveChannel.builder().pubnub(this);}
214-
public final DeleteChannelGroup.DeleteChannelGroupBuilder deleteChannelGroup() {return DeleteChannelGroup.builder().pubnub(this); }
206+
return prop.getProperty("version");
215207

216208

209+
// byte[] encoded;
210+
// try {
211+
// encoded = Files.readAllBytes(Paths.get(Pubnub.class.getClassLoader().getResource("version.properties").getPath()));
212+
// } catch (IOException e) {
213+
// return "N/A";
214+
// }
215+
// try {
216+
// return new String(encoded, "UTF-8").trim();
217+
// } catch (UnsupportedEncodingException e) {
218+
// return "N/A";
219+
// }
220+
}
221+
222+
public final ListAllChannelGroup listAllChannelGroup() {
223+
return new ListAllChannelGroup(this);
224+
}
225+
public final AllChannelsChannelGroup allChannelsChannelGroup(){return new AllChannelsChannelGroup(this);}
226+
public final AddChannelChannelGroup addChannelChannelGroup() {return new AddChannelChannelGroup(this);}
227+
public final RemoveChannel removeChannel() {return new RemoveChannel(this);}
228+
public final DeleteChannelGroup deleteChannelGroup() {return new DeleteChannelGroup(this);}
217229
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.pubnub.api.core.models.consumer_facing;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class PNChannelGroupsAllChannelsResult extends PNResult {
11+
private List<String> channels;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.pubnub.api.core.models.consumer_facing;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.util.List;
7+
8+
@Getter
9+
@Setter
10+
public class PNChannelGroupsListAllResult extends PNResult {
11+
private List<String> groups;
12+
}
Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
package com.pubnub.api.endpoints.channel_groups;
22

3-
import com.pubnub.api.core.*;
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.PubnubUtil;
7+
import com.pubnub.api.core.enums.PNOperationType;
48
import com.pubnub.api.core.models.Envelope;
9+
import com.pubnub.api.core.models.consumer_facing.PNChannelGroupsAllChannelsResult;
510
import com.pubnub.api.endpoints.Endpoint;
6-
import lombok.Builder;
7-
import lombok.Singular;
8-
import retrofit2.Call;
9-
import retrofit2.Response;
1011

11-
import java.util.HashMap;
12+
import java.util.ArrayList;
1213
import java.util.List;
1314
import java.util.Map;
15+
import lombok.Setter;
16+
import lombok.experimental.Accessors;
17+
import retrofit2.Call;
18+
import retrofit2.Response;
1419

15-
@Builder
16-
public class AddChannelChannelGroup extends Endpoint<Envelope,Void> {
17-
private Pubnub pubnub;
18-
private String group;
19-
@Singular
20-
private List<String> channels;
21-
private String uuid;
20+
@Accessors(chain = true, fluent = true)
21+
public class AddChannelChannelGroup extends Endpoint<Envelope,Boolean> {
22+
@Setter private String uuid;
23+
@Setter private String group;
24+
@Setter private List<String> channels;
25+
26+
27+
public AddChannelChannelGroup(Pubnub pubnub) {
28+
super(pubnub);
29+
}
2230

2331
@Override
24-
protected boolean validateParams() { return true;}
32+
protected boolean validateParams() {
33+
return true;
34+
}
2535

2636
@Override
27-
protected final Call<Envelope> doWork() throws PubnubException {
37+
protected Call<Envelope> doWork(Map<String, String> params) {
2838
String channelCSV;
29-
Map<String, String> params = new HashMap<String, String>();
30-
31-
if (group==null) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"group cannot be null");
32-
if (channels.size() == 0) throw new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS,"channel cannot be null");
39+
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
3340

34-
ChannelGroupService service = this.createRetrofit(this.pubnub).create(ChannelGroupService.class);
41+
if (channels.size() > 0) {
42+
params.put("add", PubnubUtil.joinString(channels, ","));
43+
}
3544

36-
channelCSV = PubnubUtil.joinString(channels, ",");
37-
38-
params.put("add", channelCSV);
3945
params.put("uuid", this.uuid != null ? this.uuid : pubnub.getConfiguration().getUuid());
4046

41-
return service.AddChannelChannelGroup(pubnub.getConfiguration().getSubscribeKey(), group , params);
47+
return service.AddChannelChannelGroup(pubnub.getConfiguration().getSubscribeKey(), group, params);
4248
}
4349

4450
@Override
45-
protected PnResponse createResponse(Response<Envelope> input) {
46-
PnResponse pnResponse = new PnResponse();
47-
pnResponse.fillFromRetrofit(input);
48-
pnResponse.setPayload("");
49-
50-
return pnResponse;
51+
protected Boolean createResponse(Response<Envelope> input) throws PubnubException {
52+
return true;
5153
}
5254

5355
protected int getConnectTimeout() {
@@ -58,6 +60,9 @@ protected int getRequestTimeout() {
5860
return pubnub.getConfiguration().getNonSubscribeRequestTimeout();
5961
}
6062

61-
63+
@Override
64+
protected PNOperationType getOperationType() {
65+
return PNOperationType.PNAddChannelsToGroupOperation;
66+
}
6267

6368
}
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
11
package com.pubnub.api.endpoints.channel_groups;
22

3-
import com.pubnub.api.core.PnResponse;
43
import com.pubnub.api.core.Pubnub;
54
import com.pubnub.api.core.PubnubError;
65
import com.pubnub.api.core.PubnubException;
6+
import com.pubnub.api.core.enums.PNOperationType;
77
import com.pubnub.api.core.models.Envelope;
8+
import com.pubnub.api.core.models.consumer_facing.PNChannelGroupsAllChannelsResult;
89
import 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;
1512
import java.util.List;
1613
import 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
}

‎src/main/java/com/pubnub/api/endpoints/channel_groups/ChannelGroupListAll.java‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎src/main/java/com/pubnub/api/endpoints/channel_groups/ChannelGroupService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public interface ChannelGroupService {
1212
@GET("v2/channel-registration/sub-key/{subKey}/channel-group")
13-
Call<Envelope<Object>> ChannelGroupListAll(@Path("subKey") String subKey,
13+
Call<Envelope<Object>> ListAllChannelGroup(@Path("subKey") String subKey,
1414
@QueryMap Map<String, String> options);
1515

1616
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")

0 commit comments

Comments
 (0)