myshows-rpc

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

License

License

GroupId

GroupId

com.github.srgsf
ArtifactId

ArtifactId

myshows-rpc
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

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

Project URL

https://github.com/srgsf/myshows-rpc
Source Code Management

Source Code Management

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

Download myshows-rpc

How to add to project

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

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.

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.

Versions

Version
0.1.0