Skip to content

Instantly share code, notes, and snippets.

@nielsvanvelzen
Created June 5, 2021 13:25
Show Gist options
  • Save nielsvanvelzen/cf6b01ff94eb48bf0db2c71c239be5ea to your computer and use it in GitHub Desktop.
Save nielsvanvelzen/cf6b01ff94eb48bf0db2c71c239be5ea to your computer and use it in GitHub Desktop.
Kotlin SDK - Java sample
package org.jellyfin.sdk.sample.java;
import org.jellyfin.sdk.api.client.HttpClientOptions;
import org.jellyfin.sdk.api.client.KtorClient;
import org.jellyfin.sdk.api.client.Response;
import org.jellyfin.sdk.api.client.compatibility.JavaCallback;
import org.jellyfin.sdk.api.operations.UserApi;
import org.jellyfin.sdk.model.ClientInfo;
import org.jellyfin.sdk.model.DeviceInfo;
import org.jellyfin.sdk.model.api.AuthenticateUserByName;
import org.jellyfin.sdk.model.api.AuthenticationResult;
import org.jetbrains.annotations.Nullable;
public class JavaExample {
private KtorClient createClient() {
return new KtorClient(
"https://demo.jellyfin.org/stable/",
null,
new ClientInfo("Test", "0"),
new DeviceInfo("test", "test"),
new HttpClientOptions()
);
}
public void authenticate() {
var client = createClient();
var test = new UserApi(client);
test.authenticateUserByName(new AuthenticateUserByName("demo", null, ""), new JavaCallback<AuthenticationResult>() {
@Override
public void onResponse(@Nullable Response<AuthenticationResult> response) {
var content = response.getContent();
client.setAccessToken(content.getAccessToken());
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment