tvtime-client

Api client implementation for https://www.tvtime.com show progress tracker.

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.srgsf
ArtifactId

ArtifactId

tvtime-client
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

tvtime-client
Api client implementation for https://www.tvtime.com show progress tracker.
Project URL

Project URL

https://github.com/srgsf/tvtime-client
Source Code Management

Source Code Management

https://github.com/srgsf/tvtime-client

Download tvtime-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.srgsf/tvtime-client/ -->
<dependency>
    <groupId>com.github.srgsf</groupId>
    <artifactId>tvtime-client</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.srgsf/tvtime-client/
implementation 'com.github.srgsf:tvtime-client:1.0'
// https://jarcasting.com/artifacts/com.github.srgsf/tvtime-client/
implementation ("com.github.srgsf:tvtime-client:1.0")
'com.github.srgsf:tvtime-client:jar:1.0'
<dependency org="com.github.srgsf" name="tvtime-client" rev="1.0">
  <artifact name="tvtime-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.srgsf', module='tvtime-client', version='1.0')
)
libraryDependencies += "com.github.srgsf" % "tvtime-client" % "1.0"
[com.github.srgsf/tvtime-client "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.9.0
com.squareup.retrofit2 : converter-moshi jar 2.9.0

test (3)

Group / Artifact Type Version
com.squareup.okhttp3 : logging-interceptor jar 3.12.0
com.squareup.okhttp3 : mockwebserver jar 3.12.0
org.junit.jupiter : junit-jupiter-engine jar 5.5.2

Project Modules

There are no modules declared in this project.

tvtime-client

Tests License maven
A Java wrapper around https://tvtime.com Rest API using Retrofit 2 and Moshi for json serialization.

Pull requests are welcome.

Usage

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>

Authorization

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;
            }

        }
    }

Example

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.

Known API Issues

Versions

Version
1.0