tvtime-client

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

Лицензия

Лицензия

Категории

Категории

CLI Взаимодействие с пользователем
Группа

Группа

com.github.srgsf
Идентификатор

Идентификатор

tvtime-client
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

tvtime-client
Api client implementation for https://www.tvtime.com show progress tracker.
Ссылка на сайт

Ссылка на сайт

https://github.com/srgsf/tvtime-client
Система контроля версий

Система контроля версий

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

Скачать tvtime-client

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.squareup.retrofit2 : retrofit jar 2.9.0
com.squareup.retrofit2 : converter-moshi jar 2.9.0

test (3)

Идентификатор библиотеки Тип Версия
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

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.0