Property
Abstraction for modeling type-safe properties of the ApiKey implementation.
Implementations should also model an "Unknown" value in the event new properties are added, such that older versions of the implementation remain functional.
e.g.
public abstract class MyProperty private constructor(
encoding: String,
): ApiKey.Property(encoding) {
public data object AUTHENTICATION: MyProperty("AUTHENTICATION")
public class Something(public val count: Int): MyProperty("SOMETHING:$count")
public class Unknown internal constructor(value: String): MyProperty(value)
public companion object: Decoder() {
@Throws(IllegalArgumentException::class)
public override fun decode(value: String): MyProperty = when {
value == AUTHENTICATION.encoding -> AUTHENTICATION
value.startsWith("SOMETHING") -> Something(value.substringAfter(':').toInt())
else -> Unknown(value)
}
}
} Content copied to clipboard