myshows-rpc

Json-Rpc implementation for https://myshows.me show progress tracker.

Лицензия

Лицензия

Группа

Группа

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

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

myshows-rpc
Последняя версия

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

0.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

myshows-rpc
Json-Rpc implementation for https://myshows.me show progress tracker.
Ссылка на сайт

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

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

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

https://github.com/srgsf/myshows-rpc

Скачать myshows-rpc

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

<!-- https://jarcasting.com/artifacts/com.github.srgsf/myshows-rpc/ -->
<dependency>
    <groupId>com.github.srgsf</groupId>
    <artifactId>myshows-rpc</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.srgsf/myshows-rpc/
implementation 'com.github.srgsf:myshows-rpc:0.1.0'
// https://jarcasting.com/artifacts/com.github.srgsf/myshows-rpc/
implementation ("com.github.srgsf:myshows-rpc:0.1.0")
'com.github.srgsf:myshows-rpc:jar:0.1.0'
<dependency org="com.github.srgsf" name="myshows-rpc" rev="0.1.0">
  <artifact name="myshows-rpc" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.srgsf', module='myshows-rpc', version='0.1.0')
)
libraryDependencies += "com.github.srgsf" % "myshows-rpc" % "0.1.0"
[com.github.srgsf/myshows-rpc "0.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

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

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

myshows-rpc

Tests License Maven

A Java wrapper around https://myshows.me Json-Rpc API v2.0 using Retrofit 2 and Moshi for json serialization.

Current version contains the following APIs:

  • auth
  • iap
  • lists
  • manage
  • news
  • notes
  • profile
  • push
  • recommendation
  • shows
  • site
  • users

Pull requests are welcome.

Usage

Add the following dependency to your Gradle project:

implementation 'com.github.srgsf:myshows-rpc:0.1.0'

Or for Maven:

<dependency>
  <groupId>com.github.srgsf</groupId>
  <artifactId>myshows-rpc</artifactId>
  <version>0.1.0</version>
</dependency>

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.

 RpcClient client = new RpcClient.Builder().build();
        Shows shows = client.shows();
        Call<List<Show>> call = shows.search(new Query("House"));
        call.enqueue(new Callback<List<Show>>() {
            @Override
            public void onResponse(Call<List<Show>> call, Response<List<Show>> response) {
                if(response.isSuccessful()){
                    List<Show> result = response.body();
                    //use list of found shows.
                } else {
                    try {
                        RpcError error = client.error(response.errorBody());
                        //analyse RPC error.
                    }catch (IOException ex){
                       ex.printStackTrace(); 
                    }
                }
            }

            @Override
            public void onFailure(Call<List<Show>> call, Throwable t) {

            }
        });

Authorization

To use Rpc methods that require valid OAuth 2.0 access token you must either provide RpcClient with AccessTokenProvider implementation or add okhttp3.Interceptor that handles authorization.
Please note that okhttp3.Authenticator is not used due to Json-Rpc always responses with 200 http status.
Library includes MyShowsTokenProvider example implementation of AccessTokenProvider however it is strongly recommended using implementation that fits your key management strategy.

        //shared 
        OkHttpClient httpClient = new OkHttpClient.Builder().build();
        //shared
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(MoshiConverterFactory.create()).baseUrl("/").build();

        MyShowsAuthClient authClient = new MyShowsAuthClient.Builder()
                .client(httpClient)
                .retrofit(retrofit)
                .clientCredentials(new Credentials("api_user", "api_secret"))
                .build();
        try {
            //using password grant
            Response<AccessToken> response = authClient.accessToken(new Credentials("myshows_user",
                    "myshows_password"));
            if (!response.isSuccessful()) {
                throw new RuntimeException("authentication failed.");
            }

            RpcClient client = new RpcClient.Builder()
                    .client(httpClient)
                    .retrofit(retrofit)
                    .tokenProvider(new MyShowsTokenProvider(authClient, response.body()))
                    .build();
            Profile profile = client.profile();
            Response<UserProfile> profileResponse = profile.get(new UserLogin("my_shows_login")).execute();
            if (profileResponse.isSuccessful()) {
                UserProfile p = profileResponse.body();
                //use profile
            }
        } catch (IOException ex) {
            //handle
        }

See test cases in src/test/ for more examples.

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

Версия
0.1.0