Skip to content

Commit

Permalink
Replace data class usage with Poko
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewCarlson committed Oct 23, 2024
1 parent 78012ae commit 225b622
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 402 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.multiplatform) apply false
alias(libs.plugins.serialization) apply false
alias(libs.plugins.binaryCompat) apply false
alias(libs.plugins.poko) apply false
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
alias(libs.plugins.mavenPublish)
Expand Down
2 changes: 1 addition & 1 deletion client/src/commonMain/kotlin/QBittorrentClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class QBittorrentClient(
private val allList = listOf("all")
}

internal data class Config(
internal class Config(
val baseUrl: String,
val username: String,
val password: String,
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ binaryCompat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", ve
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.30.0" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
poko = { id = "dev.drewhamilton.poko", version = "0.17.2" }

[libraries]
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down
382 changes: 0 additions & 382 deletions models/api/qbittorrent-models.api

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.ksp)
alias(libs.plugins.poko)
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion models/src/commonMain/kotlin/AddTorrentBody.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package qbittorrent.models

import kotlin.time.*

data class AddTorrentBody(
class AddTorrentBody(
/**
* Torrent file HTTP or Magnet urls.
*/
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/BuildInfo.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class BuildInfo(
class BuildInfo(
val qt: String,
val libtorrent: String,
val boost: String,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/Category.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class Category(
class Category(
val name: String,
val savePath: String,
)
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/GlobalTransferInfo.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class GlobalTransferInfo(
class GlobalTransferInfo(
/** Global download rate (bytes/s) */
@SerialName("dl_info_speed")
val dlInfoSpeed: Long,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/LogEntry.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class LogEntry(
class LogEntry(
/** ID of the message */
val id: Int,
/** Text of the message */
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/MainData.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import qbittorrent.models.serialization.KeyMergingTransformer

@Poko
@Serializable
data class MainData(
class MainData(
/** Response ID */
val rid: Long,
/** Whether the response contains all the data or partial data */
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/PeerLog.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class PeerLog(
class PeerLog(
val id: Int,
val ip: String,
val timestamp: Long,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/QBittorrentPrefs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import qbittorrent.models.preferences.*
Expand All @@ -9,10 +10,11 @@ import qbittorrent.models.serialization.GenerateSerialNameMapper
import qbittorrent.models.serialization.NewLineListSerializer
import qbittorrent.models.serialization.SemiColonListSerializer

@Poko
@GeneratePropertySerializerMapper
@GenerateSerialNameMapper
@Serializable
data class QBittorrentPrefs(
class QBittorrentPrefs(
/** Currently selected language (e.g. en_GB for English) */
val locale: String,
/** True if a subfolder should be created when adding a torrent */
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/ServerState.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class ServerState(
class ServerState(
/** all time download (bytes) */
@SerialName("alltime_dl")
val allTimeDownload: Long,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/Torrent.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import qbittorrent.models.serialization.CommaListSerializer
import qbittorrent.models.serialization.GenerateSerialNameMapper
import kotlin.reflect.KProperty1

@Poko
@GenerateSerialNameMapper
@Serializable
data class Torrent(
class Torrent(
/** Time (Unix Epoch) when the torrent was added to the client */
@SerialName("added_on")
val addedOn: Long,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/TorrentFile.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class TorrentFile(
class TorrentFile(
/** The index of this file in the torrent contents list */
val index: Int,
/** File name (including relative path) */
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/TorrentPeer.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class TorrentPeer(
class TorrentPeer(
val client: String = "",
val connection: String = "",
val country: String = "",
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/TorrentPeers.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class TorrentPeers(
class TorrentPeers(
@SerialName("full_update")
val fullUpdate: Boolean = false,
val rid: Int = 0,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/TorrentProperties.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class TorrentProperties(
class TorrentProperties(
/** Torrent save path */
@SerialName("save_path")
val savePath: String,
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/TorrentTracker.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class TorrentTracker(
class TorrentTracker(
/** The tracker URL. */
val url: String,
/**
Expand Down
4 changes: 3 additions & 1 deletion models/src/commonMain/kotlin/Webseed.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package qbittorrent.models

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Poko
@Serializable
data class Webseed(
class Webseed(
/** URL of the web seed. */
val url: String,
)
10 changes: 7 additions & 3 deletions models/src/commonMain/kotlin/preferences/ScanDirs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package qbittorrent.models.preferences

import dev.drewhamilton.poko.Poko
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -8,20 +9,23 @@ sealed class ScanDir {
/**
* Download to the monitored folder
*/
@Poko
@Serializable // 0
data class MonitoredFolder(val scanDir: String) : ScanDir()
class MonitoredFolder(val scanDir: String) : ScanDir()

/**
* Download to the default save path
*/
@Poko
@Serializable // 1
data class DefaultSavePath(val scanDir: String) : ScanDir()
class DefaultSavePath(val scanDir: String) : ScanDir()

/**
* Download to this [path]
*/
@Poko
@Serializable
data class CustomSavePath(
class CustomSavePath(
val scanDir: String,
val path: String
) : ScanDir()
Expand Down

0 comments on commit 225b622

Please sign in to comment.