simkl-client
A Java wrapper around https://simkl.com API using Retrofit2 and Moshi
Pull requests are welcome.
Usage
Add the following dependency to your Gradle project:
implementation 'com.github.srgsf:simkl-client:0.1'
Or for Maven:
<dependency>
<groupId>com.github.srgsf</groupId>
<artifactId>simkl-client</artifactId>
<version>0.1</version>
</dependency>
Authorization
Some of SIMKL API methods can only be accessed via OAuth 2.0.
Current version supports Web Application flow and Limited Device flow. See SimklAuthClient
for details.
Example of Web Application flow token request.
HttpUrl url = SimklAuthClient.authorizationRequestUrl("<clientId>",
"<redirectUrl>",
"1234");
// let user to sign in using url, then use <code> to get access token
SimklAuthClient authClient = new SimklAuthClient.Builder()
.clientCredentials("<clientId>", "<clientSecret>", "<redirectUrl>")
.build();
AccessToken token = authClient.accessToken(SimklAuthClient.GrantType.authorization_code, "<code>")
.body();
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.
Simkl simkl = new Simkl.Builder()
.clientId("<clientId>")
.tokenProvider(() -> "<token>")
.build();
Users usersApi = simkl.users();
usersApi.info().enqueue(new Callback<UserInfo>() {
@Override
public void onResponse(Call<UserInfo> call, Response<UserInfo> response) {
if(response.isSuccessful()) {
UserInfo info = response.body();
//use info
}
}
@Override
public void onFailure(Call<UserInfo> call, Throwable t) {
//handle
}
});
See test cases in src/test/
for more examples.
Known API Issues
- Add to Collection and Remove from Collection methods always response with
null
.