Remove deprecated setters from ApiClient

This commit is contained in:
Niels van Velzen 2024-09-22 10:19:53 +02:00 committed by Niels van Velzen
parent 422ad5ec9d
commit b4004adaa6
5 changed files with 26 additions and 28 deletions

View File

@ -1,4 +1,4 @@
public class org/jellyfin/sdk/api/ktor/KtorClient : org/jellyfin/sdk/api/client/ApiClient {
public final class org/jellyfin/sdk/api/ktor/KtorClient : org/jellyfin/sdk/api/client/ApiClient {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lorg/jellyfin/sdk/model/ClientInfo;Lorg/jellyfin/sdk/model/DeviceInfo;Lorg/jellyfin/sdk/api/client/HttpClientOptions;Lorg/jellyfin/sdk/api/sockets/SocketConnectionFactory;)V
public fun getAccessToken ()Ljava/lang/String;
public fun getBaseUrl ()Ljava/lang/String;
@ -7,10 +7,6 @@ public class org/jellyfin/sdk/api/ktor/KtorClient : org/jellyfin/sdk/api/client/
public fun getHttpClientOptions ()Lorg/jellyfin/sdk/api/client/HttpClientOptions;
public fun getWebSocket ()Lorg/jellyfin/sdk/api/sockets/SocketApi;
public fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun setAccessToken (Ljava/lang/String;)V
public fun setBaseUrl (Ljava/lang/String;)V
public fun setClientInfo (Lorg/jellyfin/sdk/model/ClientInfo;)V
public fun setDeviceInfo (Lorg/jellyfin/sdk/model/DeviceInfo;)V
public fun update (Ljava/lang/String;Ljava/lang/String;Lorg/jellyfin/sdk/model/ClientInfo;Lorg/jellyfin/sdk/model/DeviceInfo;)V
}

View File

@ -42,14 +42,23 @@ import javax.net.ssl.SSLException
import io.ktor.http.HttpMethod as KtorHttpMethod
@Suppress("LongParameterList")
public open class KtorClient(
override var baseUrl: String?,
override var accessToken: String?,
override var clientInfo: ClientInfo,
override var deviceInfo: DeviceInfo,
public class KtorClient(
initialBaseUrl: String?,
initialAccessToken: String?,
initialClientInfo: ClientInfo,
initialDeviceInfo: DeviceInfo,
override val httpClientOptions: HttpClientOptions,
private val socketConnectionFactory: SocketConnectionFactory,
) : ApiClient() {
public override var baseUrl: String? = initialBaseUrl
private set
public override var accessToken: String? = initialAccessToken
private set
public override var clientInfo: ClientInfo = initialClientInfo
private set
public override var deviceInfo: DeviceInfo = initialDeviceInfo
private set
private val client: HttpClient = HttpClient {
followRedirects = httpClientOptions.followRedirects
expectSuccess = false
@ -118,7 +127,12 @@ public open class KtorClient(
// String content
is String -> setBody(TextContent(requestBody, ContentType.Text.Plain))
// File content
is FileInfo -> setBody(ByteArrayContent(requestBody.content, ContentType.parse(requestBody.mediaType)))
is FileInfo -> setBody(
ByteArrayContent(
requestBody.content,
ContentType.parse(requestBody.mediaType)
)
)
// Binary content
is ByteArray -> setBody(ByteArrayContent(requestBody, ContentType.Application.OctetStream))
// Json content

View File

@ -14,10 +14,6 @@ public abstract class org/jellyfin/sdk/api/client/ApiClient {
public abstract fun getWebSocket ()Lorg/jellyfin/sdk/api/sockets/SocketApi;
public abstract fun request (Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun request$default (Lorg/jellyfin/sdk/api/client/ApiClient;Lorg/jellyfin/sdk/api/client/HttpMethod;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/lang/Object;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public abstract fun setAccessToken (Ljava/lang/String;)V
public abstract fun setBaseUrl (Ljava/lang/String;)V
public abstract fun setClientInfo (Lorg/jellyfin/sdk/model/ClientInfo;)V
public abstract fun setDeviceInfo (Lorg/jellyfin/sdk/model/DeviceInfo;)V
public abstract fun update (Ljava/lang/String;Ljava/lang/String;Lorg/jellyfin/sdk/model/ClientInfo;Lorg/jellyfin/sdk/model/DeviceInfo;)V
public static synthetic fun update$default (Lorg/jellyfin/sdk/api/client/ApiClient;Ljava/lang/String;Ljava/lang/String;Lorg/jellyfin/sdk/model/ClientInfo;Lorg/jellyfin/sdk/model/DeviceInfo;ILjava/lang/Object;)V
}

View File

@ -8,10 +8,6 @@ import org.jellyfin.sdk.model.ClientInfo
import org.jellyfin.sdk.model.DeviceInfo
import kotlin.reflect.KClass
private const val UPDATE_DEPRECATION_MESSAGE =
"This property should not be set directly as changes are not propagated to the WebSocket connection." +
" Migrate to using the update() function instead."
public abstract class ApiClient {
public companion object {
/**
@ -29,27 +25,23 @@ public abstract class ApiClient {
/**
* URL to use as base for API endpoints. Should include the protocol and may contain a path.
*/
public abstract var baseUrl: String?
@Deprecated(UPDATE_DEPRECATION_MESSAGE) set
public abstract val baseUrl: String?
/**
* Access token to use for requests. Appended to all requests if set.
*/
public abstract var accessToken: String?
@Deprecated(UPDATE_DEPRECATION_MESSAGE) set
public abstract val accessToken: String?
/**
* Information about the client / application send in all API requests.
*/
public abstract var clientInfo: ClientInfo
@Deprecated(UPDATE_DEPRECATION_MESSAGE) set
public abstract val clientInfo: ClientInfo
/**
* Information about the device send in all API requests. Only a single session is allowed per
* device id.
*/
public abstract var deviceInfo: DeviceInfo
@Deprecated(UPDATE_DEPRECATION_MESSAGE) set
public abstract val deviceInfo: DeviceInfo
/**
* HTTP Options for this ApiClient.

View File

@ -31,7 +31,7 @@ public class Main {
UserApiExtensionsKt.authenticateUserByName(userApi, "demo", "", new JavaResponseContinuation<AuthenticationResult>() {
@Override
public void onResponse(@NotNull AuthenticationResult response) {
client.setAccessToken(response.getAccessToken());
client.update(client.getBaseUrl(), response.getAccessToken(), client.getClientInfo(), client.getDeviceInfo());
logger.info("Got access token: {}", response.getAccessToken());
latch.countDown();