Skip to content

Commit 973dc25

Browse files
author
Max Presman
committed
append pojo to all responses
1 parent 3c0a73b commit 973dc25

17 files changed

Lines changed: 142 additions & 36 deletions

‎src/main/java/com/pubnub/api/builder/SubscribeBuilder.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
import com.pubnub.api.builder.dto.SubscribeOperation;
44
import com.pubnub.api.managers.SubscriptionManager;
5-
import lombok.Getter;
5+
import lombok.AccessLevel;
66
import lombok.Setter;
7+
import lombok.experimental.Accessors;
78

89
import java.util.List;
910

10-
@Getter
1111
@Setter
12+
@Accessors(chain = true, fluent = true)
1213
public class SubscribeBuilder extends PubSubBuilder {
1314

1415
/**
1516
* Allow users to specify if they would also like to include the presence channels for those subscriptions.
1617
*/
18+
@Setter(AccessLevel.NONE)
1719
private boolean presenceEnabled;
1820

1921
/**
2022
* Allow users to subscribe with a custom timetoken.
2123
*/
24+
@Setter(AccessLevel.NONE)
2225
private Long timetoken;
2326

2427
public SubscribeBuilder(final SubscriptionManager subscriptionManager) {

‎src/main/java/com/pubnub/api/endpoints/History.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class History extends Endpoint<JsonNode, PNHistoryResult> {
2929
@Setter private String channel;
3030
@Setter private Long start;
3131
@Setter private Long end;
32-
@Setter private boolean reverse = false;
32+
@Setter private Boolean reverse;
3333
@Setter private Integer count;
34-
@Setter private boolean includeTimetoken = false;
34+
@Setter private Boolean includeTimetoken;
3535

3636
public History(PubNub pubnub) {
3737
super(pubnub);
@@ -54,8 +54,13 @@ protected Call<JsonNode> doWork(Map<String, String> params) {
5454

5555
HistoryService service = this.createRetrofit().create(HistoryService.class);
5656

57-
params.put("reverse", String.valueOf(reverse));
58-
params.put("include_token", String.valueOf(includeTimetoken));
57+
if (reverse != null) {
58+
params.put("reverse", String.valueOf(reverse));
59+
}
60+
61+
if (includeTimetoken != null) {
62+
params.put("include_token", String.valueOf(includeTimetoken));
63+
}
5964

6065
if (count != null && count > 0 && count <= 10) {
6166
params.put("count", String.valueOf(count));
@@ -88,7 +93,7 @@ protected PNHistoryResult createResponse(Response<JsonNode> input) throws PubNub
8893
PNHistoryItemResult.PNHistoryItemResultBuilder historyItem = PNHistoryItemResult.builder();
8994
Object message;
9095

91-
if (includeTimetoken) {
96+
if (includeTimetoken != null && includeTimetoken) {
9297
historyItem.timetoken(historyEntry.get("timetoken").asLong());
9398
message = processMessage(historyEntry.get("message"));
9499
} else {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.pubnub.api.endpoints.channel_groups;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
56
import com.pubnub.api.PubnubUtil;
67
import com.pubnub.api.enums.PNOperationType;
8+
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsAddChannelResult;
79
import com.pubnub.api.models.server.Envelope;
810
import com.pubnub.api.endpoints.Endpoint;
911
import lombok.Setter;
@@ -16,7 +18,7 @@
1618
import java.util.Map;
1719

1820
@Accessors(chain = true, fluent = true)
19-
public class AddChannelChannelGroup extends Endpoint<Envelope, Boolean> {
21+
public class AddChannelChannelGroup extends Endpoint<Envelope, PNChannelGroupsAddChannelResult> {
2022
@Setter private String channelGroup;
2123
@Setter private List<String> channels;
2224

@@ -43,8 +45,12 @@ protected Call<Envelope> doWork(final Map<String, String> params) {
4345
}
4446

4547
@Override
46-
protected Boolean createResponse(Response<Envelope> input) throws PubNubException {
47-
return !input.body().isError();
48+
protected PNChannelGroupsAddChannelResult createResponse(Response<Envelope> input) throws PubNubException {
49+
if (input.body() == null) {
50+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
51+
}
52+
53+
return PNChannelGroupsAddChannelResult.builder().build();
4854
}
4955

5056
protected int getConnectTimeout() {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.pubnub.api.endpoints.channel_groups;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
56
import com.pubnub.api.enums.PNOperationType;
7+
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsDeleteGroupResult;
68
import com.pubnub.api.models.server.Envelope;
79
import com.pubnub.api.endpoints.Endpoint;
810
import lombok.Setter;
@@ -13,7 +15,7 @@
1315
import java.util.Map;
1416

1517
@Accessors(chain = true, fluent = true)
16-
public class DeleteChannelGroup extends Endpoint<Envelope,Boolean> {
18+
public class DeleteChannelGroup extends Endpoint<Envelope, PNChannelGroupsDeleteGroupResult> {
1719
@Setter private String channelGroup;
1820

1921
public DeleteChannelGroup(PubNub pubnub) {
@@ -33,8 +35,12 @@ protected Call<Envelope> doWork(Map<String, String> params) {
3335
}
3436

3537
@Override
36-
protected Boolean createResponse(Response<Envelope> input) throws PubNubException {
37-
return true;
38+
protected PNChannelGroupsDeleteGroupResult createResponse(Response<Envelope> input) throws PubNubException {
39+
if (input.body() == null) {
40+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
41+
}
42+
43+
return PNChannelGroupsDeleteGroupResult.builder().build();
3844
}
3945

4046
protected int getConnectTimeout() {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.pubnub.api.endpoints.channel_groups;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
56
import com.pubnub.api.PubnubUtil;
67
import com.pubnub.api.enums.PNOperationType;
8+
import com.pubnub.api.models.consumer.channel_group.PNChannelGroupsRemoveChannelResult;
79
import com.pubnub.api.models.server.Envelope;
810
import com.pubnub.api.endpoints.Endpoint;
911
import lombok.Setter;
@@ -16,7 +18,7 @@
1618
import java.util.Map;
1719

1820
@Accessors(chain = true, fluent = true)
19-
public class RemoveChannelChannelGroup extends Endpoint<Envelope,Boolean> {
21+
public class RemoveChannelChannelGroup extends Endpoint<Envelope, PNChannelGroupsRemoveChannelResult> {
2022
@Setter private String channelGroup;
2123
@Setter private List<String> channels;
2224

@@ -43,8 +45,12 @@ protected Call<Envelope> doWork(Map<String, String> params) {
4345
}
4446

4547
@Override
46-
protected Boolean createResponse(Response<Envelope> input) throws PubNubException {
47-
return true;
48+
protected PNChannelGroupsRemoveChannelResult createResponse(Response<Envelope> input) throws PubNubException {
49+
if (input.body() == null) {
50+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
51+
}
52+
53+
return PNChannelGroupsRemoveChannelResult.builder().build();
4854
}
4955

5056
protected int getConnectTimeout() {

‎src/main/java/com/pubnub/api/endpoints/push/ListPushProvisions.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.pubnub.api.endpoints.push;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
56
import com.pubnub.api.enums.PNOperationType;
67
import com.pubnub.api.enums.PushType;
78
import com.pubnub.api.endpoints.Endpoint;
9+
import com.pubnub.api.models.consumer.push.PNPushListProvisionsResult;
810
import lombok.Setter;
911
import lombok.experimental.Accessors;
1012
import retrofit2.Call;
@@ -14,7 +16,7 @@
1416
import java.util.Map;
1517

1618
@Accessors(chain = true, fluent = true)
17-
public class ListPushProvisions extends Endpoint<List<String>, List<String>> {
19+
public class ListPushProvisions extends Endpoint<List<String>, PNPushListProvisionsResult> {
1820

1921
@Setter private PushType pushType;
2022
@Setter private String deviceId;
@@ -36,8 +38,12 @@ protected Call<List<String>> doWork(Map<String, String> params) throws PubNubExc
3638
}
3739

3840
@Override
39-
protected List<String> createResponse(Response<List<String>> input) throws PubNubException {
40-
return input.body();
41+
protected PNPushListProvisionsResult createResponse(Response<List<String>> input) throws PubNubException {
42+
if (input.body() == null) {
43+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
44+
}
45+
46+
return PNPushListProvisionsResult.builder().channels(input.body()).build();
4147
}
4248

4349
protected int getConnectTimeout() {

‎src/main/java/com/pubnub/api/endpoints/push/RemoveAllPushChannelsForDevice.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.pubnub.api.endpoints.push;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
6+
import com.pubnub.api.endpoints.Endpoint;
57
import com.pubnub.api.enums.PNOperationType;
68
import com.pubnub.api.enums.PushType;
7-
import com.pubnub.api.endpoints.Endpoint;
9+
import com.pubnub.api.models.consumer.push.PNPushRemoveAllChannelsResult;
810
import lombok.Setter;
911
import lombok.experimental.Accessors;
1012
import retrofit2.Call;
@@ -14,7 +16,7 @@
1416
import java.util.Map;
1517

1618
@Accessors(chain = true, fluent = true)
17-
public class RemoveAllPushChannelsForDevice extends Endpoint<List<Object>, Boolean> {
19+
public class RemoveAllPushChannelsForDevice extends Endpoint<List<Object>, PNPushRemoveAllChannelsResult> {
1820

1921
@Setter private PushType pushType;
2022
@Setter private String deviceId;
@@ -44,8 +46,12 @@ protected Call<List<Object>> doWork(Map<String, String> params) throws PubNubExc
4446
}
4547

4648
@Override
47-
protected Boolean createResponse(Response<List<Object>> input) throws PubNubException {
48-
return true;
49+
protected PNPushRemoveAllChannelsResult createResponse(Response<List<Object>> input) throws PubNubException {
50+
if (input.body() == null) {
51+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
52+
}
53+
54+
return PNPushRemoveAllChannelsResult.builder().build();
4955
}
5056

5157
protected int getConnectTimeout() {

‎src/main/java/com/pubnub/api/endpoints/push/RemoveChannelsFromPush.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.pubnub.api.endpoints.push;
22

33
import com.pubnub.api.PubNub;
4+
import com.pubnub.api.PubNubError;
45
import com.pubnub.api.PubNubException;
56
import com.pubnub.api.PubnubUtil;
7+
import com.pubnub.api.endpoints.Endpoint;
68
import com.pubnub.api.enums.PNOperationType;
79
import com.pubnub.api.enums.PushType;
8-
import com.pubnub.api.endpoints.Endpoint;
10+
import com.pubnub.api.models.consumer.push.PNPushRemoveChannelResult;
911
import lombok.Setter;
1012
import lombok.experimental.Accessors;
1113
import retrofit2.Call;
@@ -16,7 +18,7 @@
1618
import java.util.Map;
1719

1820
@Accessors(chain = true, fluent = true)
19-
public class RemoveChannelsFromPush extends Endpoint<List<Object>, Boolean> {
21+
public class RemoveChannelsFromPush extends Endpoint<List<Object>, PNPushRemoveChannelResult> {
2022

2123
@Setter private PushType pushType;
2224
@Setter private List<String> channels;
@@ -59,8 +61,12 @@ protected Call<List<Object>> doWork(Map<String, String> baseParams) throws PubNu
5961
}
6062

6163
@Override
62-
protected Boolean createResponse(Response<List<Object>> input) throws PubNubException {
63-
return null;
64+
protected PNPushRemoveChannelResult createResponse(Response<List<Object>> input) throws PubNubException {
65+
if (input.body() == null) {
66+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PARSING_ERROR).build();
67+
}
68+
69+
return PNPushRemoveChannelResult.builder().build();
6470
}
6571

6672
protected int getConnectTimeout() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.pubnub.api.models.consumer.channel_group;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
6+
@Builder
7+
@Getter
8+
public class PNChannelGroupsAddChannelResult {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.pubnub.api.models.consumer.channel_group;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
6+
@Builder
7+
@Getter
8+
public class PNChannelGroupsDeleteGroupResult {
9+
}

0 commit comments

Comments
 (0)