Skip to content

Commit

Permalink
Merge pull request #6 from matsumo0922/bump-up-version
Browse files Browse the repository at this point in the history
Bump up version to v0.0.7
  • Loading branch information
matsumo0922 authored Jan 17, 2025
2 parents 7e49284 + 8625fe1 commit d20baa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal fun buildHttpClient(
formatter: Json,
cookieStorage: PersistentCookieStorage,
csrfToken: CSRFToken? = null,
logLevel: LogLevel = LogLevel.NONE,
isEnableContentNegotiation: Boolean = true,
): HttpClient {
val customLogger = object : Logger {
Expand All @@ -34,7 +35,7 @@ internal fun buildHttpClient(

val client = HttpClient {
install(Logging) {
level = LogLevel.INFO
level = logLevel
logger = customLogger
}

Expand All @@ -59,13 +60,14 @@ internal fun buildHttpClient(
validateResponse {
val isError = !it.status.isSuccess()
val isJson = it.contentType()?.match(ContentType.Application.Json) == true
val response = it.bodyAsText()

if (isError && isJson) {
if (isError && isJson && logLevel != LogLevel.NONE) {
val response = it.bodyAsText()
Napier.d { "JSON: $response" }
}

if (it.status == HttpStatusCode.NotFound || it.status.value >= 400) {
val response = it.bodyAsText()
error("HTTP ${it.status.value}: $response")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.matsumo.fankt.fanbox

import de.jensklingenberg.ktorfit.Ktorfit
import io.ktor.client.HttpClient
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.statement.HttpStatement
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -53,6 +54,7 @@ import me.matsumo.fankt.fanbox.repository.FanboxSearchRepository
import me.matsumo.fankt.fanbox.repository.FanboxUserRepository

class Fanbox(
private val logLevel: LogLevel = LogLevel.NONE,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
) {
private val scope = CoroutineScope(ioDispatcher + SupervisorJob())
Expand Down Expand Up @@ -91,17 +93,17 @@ class Fanbox(
private fun buildKtorfit(csrfToken: CSRFToken?) {
val ktorfit = Ktorfit.Builder()
.baseUrl("https://api.fanbox.cc/")
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, true))
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, logLevel, true))
.build()

val ktorfitWithoutContentNegotiation = Ktorfit.Builder()
.baseUrl("https://api.fanbox.cc/")
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, false))
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, logLevel, false))
.build()

val ktorfitDownload = Ktorfit.Builder()
.baseUrl("https://downloads.fanbox.cc/")
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, true))
.httpClient(buildHttpClient(formatter, cookieStorage, csrfToken, logLevel, true))
.build()

val postApi = ktorfit.createFanboxPostApi()
Expand All @@ -126,7 +128,7 @@ class Fanbox(
}

suspend fun getHttpClient(isEnableContentNegotiation: Boolean = true): HttpClient {
return buildHttpClient(formatter, cookieStorage, tokenDao.getLatestToken().first(), isEnableContentNegotiation)
return buildHttpClient(formatter, cookieStorage, tokenDao.getLatestToken().first(), logLevel, isEnableContentNegotiation)
}

suspend fun setFanboxSessionId(sessionId: String) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
# Application
versionName = "0.0.6"
versionCode = "6"
versionName = "0.0.7"
versionCode = "7"

# SDK
minSdk = "26"
Expand Down

0 comments on commit d20baa6

Please # to comment.