A Java wrapper around https://tvtime.com Rest API using Retrofit 2 and Moshi for json serialization.
Pull requests are welcome.
Add the following dependency to your Gradle project:
implementation 'com.github.srgsf:tvtime-client:1.0'
Or for Maven:
<dependency>
<groupId>com.github.srgsf</groupId>
<artifactId>tvtime-client</artifactId>
<version>1.0</version>
</dependency>
The TV Time API can only be accessed via OAuth 2.0.
Current version supports Web Application flow and Limited Device flow. See TvTimeAuthClient
for details.
Example of Limited Device flow token polling.
TvTimeAuthClient authClient = new TvTimeAuthClient.Builder()
.clientCredentials("APIClientId", "APIClientSecret")
.build();
DeviceCode code = null;
Response<DeviceCode> codeResponse = authClient.deviceCode();
if (codeResponse.isSuccessful()) {
code = codeResponse.body();
showToTheUser(code.userCode, code.verificationUrl);
String token = token(code);
}
...
String token(DeviceCode code) throws IOException, InterruptedException {
Instant expire = Instant.now().plusSeconds(code.expiresIn);
//polling
while (true) {
Thread.sleep(code.interval * 1000);
Response<String> tokenResponse = authClient.accessToken(code.deviceCode);
if (tokenResponse.isSuccessful()) {
return tokenResponse.body();
}
if (Instant.now().isAfter(expire)) {
return null;
}
}
}
Use like any other retrofit2 based service.
Optionally you can share OkHttp client and Retrofit instances to keep single request pooling, disk cache, routing logic, etc.
TvTime client = new TvTime.Builder()
.tokenProvider(() -> "<TOKEN>")
.build();
TvTimeInfo api = client.info();
Response<User> response = api.user().execute();
if (response.isSuccessful()) {
User u = response.body();
//use user
}
See test cases in src/test/
for more examples.
- Retrieve Progress method always responses with
null
progress. - Checkin, Save Progress and Retrieve Progress methods don't work if
show_id
,season_number
andnumber
are sent as Episode Item parameter.