Skip to content

Commit 2bf119d

Browse files
author
Max Presman
committed
adding pnsdk, all tests failing
1 parent a0bf9e5 commit 2bf119d

20 files changed

Lines changed: 141 additions & 48 deletions

File tree

‎pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
<sourceDirectory>src/main/java</sourceDirectory>
3333
<testSourceDirectory>src/test/java</testSourceDirectory>
3434

35+
<resources>
36+
<resource>
37+
<directory>src/main/resources</directory>
38+
<filtering>true</filtering>
39+
</resource>
40+
</resources>
41+
3542
<plugins>
3643
<plugin>
3744
<groupId>org.apache.maven.plugins</groupId>

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.pubnub.api.core;
22

3-
43
import com.pubnub.api.callbacks.SubscribeCallback;
54
import com.pubnub.api.core.builder.SubscribeBuilder;
65
import com.pubnub.api.core.builder.UnsubscribeBuilder;
@@ -19,6 +18,10 @@
1918
import lombok.Getter;
2019
import lombok.extern.slf4j.Slf4j;
2120

21+
import java.io.*;
22+
import java.nio.file.Files;
23+
import java.nio.file.Paths;
24+
2225

2326
@Getter
2427
@Slf4j
@@ -31,10 +34,14 @@ public class Pubnub {
3134
@Getter(AccessLevel.NONE)
3235
private BasePathManager basePathManager;
3336

37+
private String sdkVersion;
38+
3439
public Pubnub(final PnConfiguration initialConfig) {
3540
this.configuration = initialConfig;
3641
this.subscriptionManager = new SubscriptionManager(this);
3742
this.basePathManager = new BasePathManager(initialConfig);
43+
44+
sdkVersion = fetchSDKVersion();
3845
}
3946

4047
public String getBaseUrl() {
@@ -163,4 +170,22 @@ public final String encrypt(final String inputString, final String cipherKey) th
163170
return new Crypto(cipherKey).encrypt(inputString);
164171
}
165172

173+
public String getVersion() {
174+
return sdkVersion;
175+
}
176+
177+
private String fetchSDKVersion() {
178+
byte[] encoded;
179+
try {
180+
encoded = Files.readAllBytes(Paths.get(Pubnub.class.getClassLoader().getResource("version.properties").getPath()));
181+
} catch (IOException e) {
182+
return "N/A";
183+
}
184+
try {
185+
return new String(encoded, "UTF-8");
186+
} catch (UnsupportedEncodingException e) {
187+
return "N/A";
188+
}
189+
}
190+
166191
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class Endpoint<Input, Output> {
3030
public final Output sync() throws PubnubException {
3131
this.validateParams();
3232

33-
Call<Input> call = doWork();
33+
Call<Input> call = doWork(createBaseParams());
3434
Response<Input> serverResponse;
3535
Output response;
3636

@@ -62,7 +62,7 @@ public final Call<Input> async(final PNCallback<Output> callback) {
6262

6363
Call<Input> call = null;
6464
try {
65-
call = doWork();
65+
call = doWork(createBaseParams());
6666
} catch (PubnubException e) {
6767
PubnubException pubnubException = new PubnubException(PubnubError.PNERROBJ_INVALID_ARGUMENTS, e.getMessage());
6868
PNErrorStatus pnErrorStatus = new PNErrorStatus();
@@ -172,21 +172,24 @@ protected final Retrofit createRetrofit(Pubnub pubnub) {
172172
}
173173

174174
protected final Map<String, Object> createBaseParams() {
175-
Map<String, Object> params = new HashMap<String, Object>();
175+
Map<String, Object> params = new HashMap<>();
176176

177177
// TODO: put PNSDK here
178+
params.put("pnsdk", "Java/" + getPubnub().getVersion());
179+
178180

179181
return params;
180182
}
181183

182184
protected abstract boolean validateParams();
183185

184-
protected abstract Call<Input> doWork() throws PubnubException;
186+
protected abstract Call<Input> doWork(Map<String, Object> baseParams) throws PubnubException;
185187
protected abstract Output createResponse(Response<Input> input) throws PubnubException;
186188

187189
// add hooks for timeout
188190
protected abstract int getConnectTimeout();
189191
protected abstract int getRequestTimeout();
190192
protected abstract PNOperationType getOperationType();
193+
protected abstract Pubnub getPubnub();
191194

192195
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.pubnub.api.core.PubnubError;
99
import com.pubnub.api.core.PubnubException;
1010
import com.pubnub.api.core.enums.PNOperationType;
11-
import com.pubnub.api.core.models.consumer_facing.PNHistoryResult;
1211
import com.pubnub.api.core.models.consumer_facing.PNHistoryItemResult;
12+
import com.pubnub.api.core.models.consumer_facing.PNHistoryResult;
1313
import lombok.Builder;
1414
import retrofit2.Call;
1515
import retrofit2.Response;
@@ -18,7 +18,6 @@
1818
import retrofit2.http.QueryMap;
1919

2020
import java.io.IOException;
21-
import java.util.HashMap;
2221
import java.util.Map;
2322

2423
@Builder
@@ -36,7 +35,7 @@ private interface HistoryService {
3635
@GET("v2/history/sub-key/{subKey}/channel/{channel}")
3736
Call<JsonNode> fetchHistory(@Path("subKey") String subKey,
3837
@Path("channel") String channel,
39-
@QueryMap Map<String, String> options);
38+
@QueryMap Map<String, Object> options);
4039
}
4140

4241
@Override
@@ -45,8 +44,7 @@ protected boolean validateParams() {
4544
}
4645

4746
@Override
48-
protected Call<JsonNode> doWork() {
49-
Map<String, String> params = new HashMap<String, String>();
47+
protected Call<JsonNode> doWork(Map<String, Object> params) {
5048

5149
HistoryService service = this.createRetrofit(pubnub).create(HistoryService.class);
5250

@@ -111,6 +109,11 @@ protected PNOperationType getOperationType() {
111109
return PNOperationType.PNHistoryOperation;
112110
}
113111

112+
@Override
113+
protected Pubnub getPubnub() {
114+
return pubnub;
115+
}
116+
114117
private Object processMessage(JsonNode message) throws PubnubException {
115118
if (this.pubnub.getConfiguration().getCipherKey() == null) {
116119
return message;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import retrofit2.Call;
1010
import retrofit2.Response;
1111
import retrofit2.http.GET;
12+
import retrofit2.http.QueryMap;
1213

1314
import java.util.List;
15+
import java.util.Map;
1416

1517
@Builder
1618
public class Time extends Endpoint<List<Long>, PNTimeResult> {
@@ -19,7 +21,7 @@ public class Time extends Endpoint<List<Long>, PNTimeResult> {
1921

2022
private interface TimeService {
2123
@GET("/time/0")
22-
Call<List<Long>> fetchTime();
24+
Call<List<Long>> fetchTime(@QueryMap Map<String, Object> options);
2325
}
2426

2527
@Override
@@ -28,9 +30,9 @@ protected final boolean validateParams() {
2830
}
2931

3032
@Override
31-
protected final Call<List<Long>> doWork() {
33+
protected final Call<List<Long>> doWork(Map<String, Object> params) {
3234
TimeService service = this.createRetrofit(pubnub).create(TimeService.class);
33-
return service.fetchTime();
35+
return service.fetchTime(params);
3436
}
3537

3638
@Override
@@ -58,4 +60,9 @@ protected PNOperationType getOperationType() {
5860
return PNOperationType.PNTimeOperation;
5961
}
6062

63+
@Override
64+
protected Pubnub getPubnub() {
65+
return pubnub;
66+
}
67+
6168
}

‎src/main/java/com/pubnub/api/endpoints/access/Audit.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ protected boolean validateParams() {
3737
}
3838

3939
@Override
40-
protected Call<Envelope<PNAccessManagerAuditData>> doWork() throws PubnubException {
40+
protected Call<Envelope<PNAccessManagerAuditData>> doWork(Map<String, Object> queryParams) throws PubnubException {
4141
String signature;
42-
Map<String, Object> queryParams = new HashMap<>();
4342
Map<String, String> signParams = new HashMap<>();
4443
int timestamp = (int) ((new Date().getTime()) / 1000);
4544

@@ -97,4 +96,9 @@ protected PNOperationType getOperationType() {
9796
return PNOperationType.PNAccessManagerAudit;
9897
}
9998

99+
@Override
100+
protected Pubnub getPubnub() {
101+
return pubnub;
102+
}
103+
100104
}

‎src/main/java/com/pubnub/api/endpoints/access/Grant.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ protected boolean validateParams() {
3939
}
4040

4141
@Override
42-
protected Call<Envelope<PNAccessManagerGrantData>> doWork() throws PubnubException {
42+
protected Call<Envelope<PNAccessManagerGrantData>> doWork(Map<String, Object> queryParams) throws PubnubException {
4343
String signature;
44-
Map<String, Object> queryParams = new HashMap<>();
4544
Map<String, String> signParams = new HashMap<>();
4645
int timestamp = (int) ((new Date().getTime()) / 1000);
4746

@@ -118,4 +117,9 @@ protected PNOperationType getOperationType() {
118117
return PNOperationType.PNAccessManagerGrant;
119118
}
120119

120+
@Override
121+
protected Pubnub getPubnub() {
122+
return pubnub;
123+
}
124+
121125
}

‎src/main/java/com/pubnub/api/endpoints/presence/GetState.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ protected boolean validateParams() {
3737
}
3838

3939
@Override
40-
protected Call<Envelope<Object>> doWork() throws PubnubException {
41-
Map<String, Object> params = this.createBaseParams();
40+
protected Call<Envelope<Object>> doWork(Map<String, Object> params) throws PubnubException {
4241
PresenceService service = this.createRetrofit(this.pubnub).create(PresenceService.class);
4342

4443
if (channelGroups.size() > 0) {
@@ -77,4 +76,9 @@ protected PNOperationType getOperationType() {
7776
return PNOperationType.PNGetState;
7877
}
7978

79+
@Override
80+
protected Pubnub getPubnub() {
81+
return pubnub;
82+
}
83+
8084
}

‎src/main/java/com/pubnub/api/endpoints/presence/Heartbeat.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import retrofit2.Call;
1111
import retrofit2.Response;
1212

13-
import java.util.HashMap;
1413
import java.util.List;
1514
import java.util.Map;
1615

@@ -28,13 +27,12 @@ protected boolean validateParams() {
2827
}
2928

3029
@Override
31-
protected Call<Envelope> doWork() {
32-
Map<String, Object> params = new HashMap<>();
30+
protected Call<Envelope> doWork(Map<String, Object> params) {
3331

3432
params.put("uuid", pubnub.getConfiguration().getUuid());
35-
params.put("heartbeat", pubnub.getConfiguration().getPresenceTimeout());
33+
params.put("heartbeat", String.valueOf(pubnub.getConfiguration().getPresenceTimeout()));
3634

37-
if (channelGroups != null && channelGroups.size() > 0){
35+
if (channelGroups != null && channelGroups.size() > 0) {
3836
params.put("channel-group", PubnubUtil.joinString(channelGroups, ","));
3937
}
4038

@@ -72,4 +70,9 @@ protected PNOperationType getOperationType() {
7270
return PNOperationType.PNHeartbeatOperation;
7371
}
7472

73+
@Override
74+
protected Pubnub getPubnub() {
75+
return pubnub;
76+
}
77+
7578
}

‎src/main/java/com/pubnub/api/endpoints/presence/HereNow.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected boolean validateParams() {
3535
}
3636

3737
@Override
38-
protected Call<Envelope<Object>> doWork() {
38+
protected Call<Envelope<Object>> doWork(Map<String, Object> params) {
3939

4040
if (includeState == null) {
4141
includeState = false;
@@ -46,7 +46,6 @@ protected Call<Envelope<Object>> doWork() {
4646
}
4747

4848
String channelCSV;
49-
Map<String, String> params = new HashMap<String, String>();
5049

5150
PresenceService service = this.createRetrofit(pubnub).create(PresenceService.class);
5251

@@ -168,4 +167,9 @@ protected PNOperationType getOperationType() {
168167
return PNOperationType.PNHereNowOperation;
169168
}
170169

170+
@Override
171+
protected Pubnub getPubnub() {
172+
return pubnub;
173+
}
174+
171175
}

0 commit comments

Comments
 (0)