forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
68 lines (52 loc) · 1.86 KB
/
Copy pathTime.java
File metadata and controls
68 lines (52 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.pubnub.api.endpoints;
import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubException;
import com.pubnub.api.builder.PubNubErrorBuilder;
import com.pubnub.api.enums.PNOperationType;
import com.pubnub.api.models.consumer.PNTimeResult;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
import java.util.List;
import java.util.Map;
public class Time extends Endpoint<List<Long>, PNTimeResult> {
public Time(PubNub pubnub) {
super(pubnub);
}
private interface TimeService {
@GET("/time/0")
Call<List<Long>> fetchTime(@QueryMap Map<String, String> options);
}
@Override
protected final void validateParams() throws PubNubException {
}
@Override
protected final Call<List<Long>> doWork(Map<String, String> params) {
TimeService service = this.createRetrofit().create(TimeService.class);
return service.fetchTime(params);
}
@Override
protected final PNTimeResult createResponse(final Response<List<Long>> input) throws PubNubException {
PNTimeResult.PNTimeResultBuilder timeData = PNTimeResult.builder();
if (input.body() == null || input.body().size() == 0) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PARSING_ERROR).build();
}
timeData.timetoken(input.body().get(0));
return timeData.build();
}
protected int getConnectTimeout() {
return this.getPubnub().getConfiguration().getConnectTimeout();
}
protected int getRequestTimeout() {
return this.getPubnub().getConfiguration().getNonSubscribeRequestTimeout();
}
@Override
protected PNOperationType getOperationType() {
return PNOperationType.PNTimeOperation;
}
@Override
protected boolean isAuthRequired() {
return false;
}
}