From 1bb6a625971ef57bffcb5bf328ca1e02586c9fb9 Mon Sep 17 00:00:00 2001 From: sya-ri Date: Fri, 12 Aug 2022 18:54:14 +0900 Subject: [PATCH] tweak: Move classes, Remove method --- .../kotlin/dev/s7a/gofile/GofileClient.kt | 19 +---- .../s7a/gofile/GofileCreateFolderResponse.kt | 23 ++++++ .../gofile/GofileGetAccountDetailsResponse.kt | 33 ++++++++ .../dev/s7a/gofile/GofileGetServerResponse.kt | 9 +++ .../kotlin/dev/s7a/gofile/GofileRequest.kt | 2 +- .../kotlin/dev/s7a/gofile/GofileResponse.kt | 78 +------------------ .../s7a/gofile/GofileResponseSerializer.kt | 2 +- .../s7a/gofile/GofileUploadFileResponse.kt | 23 ++++++ src/commonTest/kotlin/Tests.kt | 4 +- 9 files changed, 97 insertions(+), 96 deletions(-) create mode 100644 src/commonMain/kotlin/dev/s7a/gofile/GofileCreateFolderResponse.kt create mode 100644 src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt create mode 100644 src/commonMain/kotlin/dev/s7a/gofile/GofileGetServerResponse.kt create mode 100644 src/commonMain/kotlin/dev/s7a/gofile/GofileUploadFileResponse.kt diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt index 5b04f99..c0fb51c 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt @@ -67,22 +67,11 @@ class GofileClient(private val client: HttpClient) { * Get the best server available to receive files. * * `https://api.gofile.io/getServer` - * - * @see getServerName */ - suspend fun getServer(): Result { + suspend fun getServer(): Result { return request(GofileRequest.GetServer) } - /** - * Get the best server name available to receive files. - * - * @see getServer - */ - suspend fun getServerName(): String? { - return getServer().getOrNull()?.server - } - /** * Upload one file on a specific server. * If you specify a folderId, the file will be added to this folder. @@ -102,7 +91,7 @@ class GofileClient(private val client: HttpClient) { * When using the folderId, you must pass the account token. * @param server Server to upload to. If you specify null, it will use the best available. */ - suspend fun uploadFile(fileName: String, fileContent: ByteArray, contentType: String, token: String? = null, folderId: String? = null, server: String? = null): Result { + suspend fun uploadFile(fileName: String, fileContent: ByteArray, contentType: String, token: String? = null, folderId: String? = null, server: String? = null): Result { val serverName = server ?: getServer().fold(onSuccess = { it.server }, onFailure = { return Result.failure(it) }) return request(GofileRequest.UploadFile(fileName, fileContent, contentType, token, folderId, serverName)) } @@ -128,7 +117,7 @@ class GofileClient(private val client: HttpClient) { * @param folderName The name of the created folder. * @param token The access token of an account. Can be retrieved from the profile page. */ - suspend fun createFolder(parentFolderId: String, folderName: String, token: String): Result { + suspend fun createFolder(parentFolderId: String, folderName: String, token: String): Result { return request(GofileRequest.CreateFolder(parentFolderId, folderName, token)) } @@ -202,7 +191,7 @@ class GofileClient(private val client: HttpClient) { * * @param token The access token of an account. Can be retrieved from the profile page. */ - suspend fun getAccountDetails(token: String): Result { + suspend fun getAccountDetails(token: String): Result { return request(GofileRequest.GetAccountDetails(token)) } } diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileCreateFolderResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileCreateFolderResponse.kt new file mode 100644 index 0000000..3c553f0 --- /dev/null +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileCreateFolderResponse.kt @@ -0,0 +1,23 @@ +package dev.s7a.gofile + +import kotlinx.serialization.Serializable + +/** + * @property id An id of the created folder. + * @property type Content type. + * @property name A name of the created folder. + * @property parentFolder The parent folder id of the created folder. + * @property createTime Creation time. + * @property childs Files and folders the folder. + * @property code A code to open the folder. + */ +@Serializable +data class GofileCreateFolderResponse( + val id: String, + val type: GofileContentType, + val name: String, + val parentFolder: String, + val createTime: Long, + val childs: List, + val code: String +) diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt new file mode 100644 index 0000000..0b7b46b --- /dev/null +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt @@ -0,0 +1,33 @@ +package dev.s7a.gofile + +import kotlinx.serialization.Serializable + +/** + * **The statistics are updated every 24 hours.** + * + * @property token The access token of an account. + * @property email The email of an account. + * @property tier The tier of an account. + * @property tierAmount Dollars paid monthly. + * @property rootFolder The root folder id. + * @property filesCount A number of files. + * @property filesCountLimit Limit of [filesCount]. + * @property totalSize A size of all files. + * @property totalSizeLimit Limit of [totalSize]. + * @property total30DDLTraffic DDL traffic increases when someone downloads your content through a direct link. It is counted for the last 30 days. Downloads from the website are unlimited. + * @property total30DDLTrafficLimit Limit of [total30DDLTraffic]. + */ +@Serializable +data class GofileGetAccountDetailsResponse( + val token: String, + val email: String, + val tier: GofileTier, + val tierAmount: Int? = null, + val rootFolder: String, + val filesCount: Int, + val filesCountLimit: Int?, + val totalSize: Double, + val totalSizeLimit: Double?, + val total30DDLTraffic: Double, + val total30DDLTrafficLimit: Double? +) diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileGetServerResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetServerResponse.kt new file mode 100644 index 0000000..3fa0bf4 --- /dev/null +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetServerResponse.kt @@ -0,0 +1,9 @@ +package dev.s7a.gofile + +import kotlinx.serialization.Serializable + +/** + * @property server The best server available to receive files. + */ +@Serializable +data class GofileGetServerResponse(val server: String) diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt index 10f82ac..738e23c 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt @@ -14,7 +14,7 @@ import io.ktor.http.Parameters /** * Request types of Gofile.io. */ -sealed interface GofileRequest { +internal sealed interface GofileRequest { /** * Http method. */ diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileResponse.kt index dd41529..86c77cd 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileResponse.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileResponse.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonObject * Response types of Gofile.io. */ @Serializable(with = GofileResponseSerializer::class) -sealed class GofileResponse { +internal sealed class GofileResponse { /** * Gofile.io returns "ok" status. */ @@ -17,80 +17,4 @@ sealed class GofileResponse { * Gofile.io returns some error. */ data class Error(val status: String, val data: JsonObject? = null) : GofileResponse() - - /** - * @property server The best server available to receive files. - */ - @Serializable - data class GetServer(val server: String) - - /** - * @property downloadPage A url to download the uploaded file. - * @property code A code to download the uploaded file. - * @property parentFolder The parent folder id of the uploaded file. - * @property fileId A id of the uploaded file. - * @property fileName A name of the upload file. - * @property md5 A checksum of the uploaded file. - * @property guestToken If you don't specify a token in the request, Gofile.io will create a guest token. - */ - @Serializable - data class UploadFile( - val downloadPage: String, - val code: String, - val parentFolder: String, - val fileId: String, - val fileName: String, - val md5: String, - val guestToken: String? = null - ) - - /** - * @property id An id of the created folder. - * @property type Content type. - * @property name A name of the created folder. - * @property parentFolder The parent folder id of the created folder. - * @property createTime Creation time. - * @property childs Files and folders the folder. - * @property code A code to open the folder. - */ - @Serializable - data class CreateFolder( - val id: String, - val type: GofileContentType, - val name: String, - val parentFolder: String, - val createTime: Long, - val childs: List, - val code: String - ) - - /** - * **The statistics are updated every 24 hours.** - * - * @property token The access token of an account. - * @property email The email of an account. - * @property tier The tier of an account. - * @property tierAmount Dollars paid monthly. - * @property rootFolder The root folder id. - * @property filesCount A number of files. - * @property filesCountLimit Limit of [filesCount]. - * @property totalSize A size of all files. - * @property totalSizeLimit Limit of [totalSize]. - * @property total30DDLTraffic DDL traffic increases when someone downloads your content through a direct link. It is counted for the last 30 days. Downloads from the website are unlimited. - * @property total30DDLTrafficLimit Limit of [total30DDLTraffic]. - */ - @Serializable - data class GetAccountDetails( - val token: String, - val email: String, - val tier: GofileTier, - val tierAmount: Int? = null, - val rootFolder: String, - val filesCount: Int, - val filesCountLimit: Int?, - val totalSize: Double, - val totalSizeLimit: Double?, - val total30DDLTraffic: Double, - val total30DDLTrafficLimit: Double? - ) } diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileResponseSerializer.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileResponseSerializer.kt index 9714803..0de0ac9 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileResponseSerializer.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileResponseSerializer.kt @@ -20,7 +20,7 @@ import kotlinx.serialization.json.put /** * Serializer for [GofileResponse]. */ -class GofileResponseSerializer(private val dataSerializer: KSerializer) : KSerializer> { +internal class GofileResponseSerializer(private val dataSerializer: KSerializer) : KSerializer> { @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) override val descriptor = buildSerialDescriptor("GofileResponse", PolymorphicKind.SEALED) { element( diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileUploadFileResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileUploadFileResponse.kt new file mode 100644 index 0000000..6d22af6 --- /dev/null +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileUploadFileResponse.kt @@ -0,0 +1,23 @@ +package dev.s7a.gofile + +import kotlinx.serialization.Serializable + +/** + * @property downloadPage A url to download the uploaded file. + * @property code A code to download the uploaded file. + * @property parentFolder The parent folder id of the uploaded file. + * @property fileId A id of the uploaded file. + * @property fileName A name of the upload file. + * @property md5 A checksum of the uploaded file. + * @property guestToken If you don't specify a token in the request, Gofile.io will create a guest token. + */ +@Serializable +data class GofileUploadFileResponse( + val downloadPage: String, + val code: String, + val parentFolder: String, + val fileId: String, + val fileName: String, + val md5: String, + val guestToken: String? = null +) diff --git a/src/commonTest/kotlin/Tests.kt b/src/commonTest/kotlin/Tests.kt index 8feb629..ea181bf 100644 --- a/src/commonTest/kotlin/Tests.kt +++ b/src/commonTest/kotlin/Tests.kt @@ -39,7 +39,7 @@ class Tests { headers = headersOf(HttpHeaders.ContentType, "application/json") ) } - assertEquals("store1", GofileClient(mockEngine).getServerName()) + assertEquals("store1", GofileClient(mockEngine).getServer().getOrNull()?.server) } } @@ -70,7 +70,7 @@ class Tests { val mockEngine = MockEngine { respondError(HttpStatusCode.InternalServerError) } - assertNull(GofileClient(mockEngine).getServerName()) + assertNull(GofileClient(mockEngine).getServer().getOrNull()) } }