Skip to content

Commit 09dd34e

Browse files
committed
Migrate to okhttp 4.6.0
1 parent a1e02cd commit 09dd34e

12 files changed

Lines changed: 37 additions & 37 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<commons-beanutils.version>1.9.4</commons-beanutils.version>
2424
<java-websocket.version>1.5.1</java-websocket.version>
2525
<socket.io-client.version>1.0.0</socket.io-client.version>
26-
<okhttp.version>3.14.9</okhttp.version>
26+
<okhttp.version>4.6.0</okhttp.version> <!-- version is aligned to ktor-client -->
2727
<pircbotx.version>2.1</pircbotx.version>
2828
<kotlin-either.version>2.0.1</kotlin-either.version>
2929
<guava.version>25.1-jre</guava.version>

src/main/kotlin/failchat/github/GithubClient.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.JsonNode
44
import com.fasterxml.jackson.databind.ObjectMapper
55
import failchat.exception.UnexpectedResponseCodeException
66
import failchat.exception.UnexpectedResponseException
7-
import failchat.util.isEmpty
87
import failchat.util.thenUse
98
import failchat.util.toFuture
109
import mu.KLogging
@@ -29,8 +28,8 @@ class GithubClient(
2928
return httpClient.newCall(request)
3029
.toFuture()
3130
.thenUse {
32-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
33-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
31+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
32+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
3433
val releasesNode = objectMapper.readTree(responseBody.string())
3534
findLatestRelease(releasesNode) ?: throw NoReleasesFoundException()
3635
}

src/main/kotlin/failchat/goodgame/GgApi2Client.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class GgApi2Client(
2929

3030
val response = httpClient.newCall(request).await()
3131

32-
if (response.code() != 200) throw UnexpectedResponseCodeException(response.code())
33-
val responseBody = response.body() ?: throw UnexpectedResponseException("null body")
32+
if (response.code != 200) throw UnexpectedResponseCodeException(response.code)
33+
val responseBody = response.body ?: throw UnexpectedResponseException("null body")
3434
val responseNode = objectMapper.readTree(responseBody.string())
3535

3636

src/main/kotlin/failchat/goodgame/GgApiClient.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class GgApiClient(
3636
return httpClient.newCall(request)
3737
.await()
3838
.use {
39-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
40-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
39+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
40+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
4141
val jsContent = responseBody.string()
4242
parseGlobalEmoticons(jsContent) + parseChannelEmoticons(jsContent)
4343
}
@@ -84,8 +84,8 @@ class GgApiClient(
8484
return httpClient.newCall(request)
8585
.await()
8686
.use {
87-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
88-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
87+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
88+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
8989
objectMapper.readTree(responseBody.string())
9090
}
9191
}

src/main/kotlin/failchat/peka2tv/Peka2tvApiClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class Peka2tvApiClient(
7272
return httpClient.newCall(request)
7373
.toFuture()
7474
.thenUse {
75-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
76-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
75+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
76+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
7777
return@thenUse objectMapper.readTree(responseBody.string())
7878
}
7979
}

src/main/kotlin/failchat/reporter/GAEventReporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GAEventReporter(
5353
.newCall(request)
5454
.await()
5555
.use { response ->
56-
val code = response.code()
56+
val code = response.code
5757
if (code !in 200..299) throw UnexpectedResponseCodeException(code)
5858
logger.info("Event successfully reported: {}.{}", category, action)
5959
}

src/main/kotlin/failchat/twitch/BttvApiClient.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class BttvApiClient(
2828
return httpClient.newCall(request)
2929
.toFuture()
3030
.thenUse {
31-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
32-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
31+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
32+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
3333
val bodyString = responseBody.string()
3434
return@thenUse parseEmoticons(bodyString, Origin.BTTV_GLOBAL)
3535
}
@@ -50,12 +50,12 @@ class BttvApiClient(
5050
return httpClient.newCall(request)
5151
.toFuture()
5252
.thenUse {
53-
when (it.code()) {
53+
when (it.code) {
5454
200 -> {}
5555
404 -> throw BttvChannelNotFoundException(channel)
56-
else -> throw UnexpectedResponseCodeException(it.code())
56+
else -> throw UnexpectedResponseCodeException(it.code)
5757
}
58-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
58+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
5959
val bodyString = responseBody.string()
6060
return@thenUse parseEmoticons(bodyString, Origin.BTTV_CHANNEL)
6161
}

src/main/kotlin/failchat/twitch/FfzApiClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FfzApiClient(
2424
.build()
2525

2626
val parsedBody = httpClient.newCall(request).await().use {
27-
if (it.code() == 404) throw FfzChannelNotFoundException(roomName)
27+
if (it.code == 404) throw FfzChannelNotFoundException(roomName)
2828
val bodyText = it.getBodyIfStatusIs(200).nonNullBody.string()
2929
objectMapper.readTree(bodyText)
3030
}

src/main/kotlin/failchat/twitch/SevenTvApiClient.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class SevenTvApiClient(
2626
return httpClient.newCall(request)
2727
.await()
2828
.use {
29-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
30-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
29+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
30+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
3131
val bodyString = responseBody.string()
3232
parseEmoticons(bodyString, Origin.SEVEN_TV_GLOBAL)
3333
}
@@ -48,9 +48,9 @@ class SevenTvApiClient(
4848
return httpClient.newCall(request)
4949
.await()
5050
.use {
51-
if (it.code() == 404) throw SevenTvChannelNotFoundException(channelName)
52-
if (it.code() != 200) throw UnexpectedResponseCodeException(it.code())
53-
val responseBody = it.body() ?: throw UnexpectedResponseException("null body")
51+
if (it.code == 404) throw SevenTvChannelNotFoundException(channelName)
52+
if (it.code != 200) throw UnexpectedResponseCodeException(it.code)
53+
val responseBody = it.body ?: throw UnexpectedResponseException("null body")
5454
val bodyString = responseBody.string()
5555
parseEmoticons(bodyString, Origin.SEVEN_TV_CHANNEL)
5656
}

src/main/kotlin/failchat/util/OkHttp.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import failchat.exception.UnexpectedResponseException
55
import okhttp3.Call
66
import okhttp3.Callback
77
import okhttp3.MediaType
8+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
89
import okhttp3.RequestBody
910
import okhttp3.Response
1011
import okhttp3.ResponseBody
@@ -14,8 +15,8 @@ import kotlin.coroutines.resume
1415
import kotlin.coroutines.resumeWithException
1516
import kotlin.coroutines.suspendCoroutine
1617

17-
val jsonMediaType: MediaType = MediaType.parse("application/json")!!
18-
val textMediaType: MediaType = MediaType.parse("text/plain")!!
18+
val jsonMediaType: MediaType = "application/json".toMediaTypeOrNull()!!
19+
val textMediaType: MediaType = "text/plain".toMediaTypeOrNull()!!
1920
val emptyBody: RequestBody = RequestBody.create(textMediaType, "")
2021

2122
fun Call.toFuture(): CompletableFuture<Response> {
@@ -47,11 +48,11 @@ suspend fun Call.await(): Response {
4748
}
4849

4950
fun Response.getBodyIfStatusIs(expectedStatus: Int): Response {
50-
if (this.code() != expectedStatus) {
51-
throw UnexpectedResponseCodeException(this.code(), request().url().toString())
51+
if (this.code != expectedStatus) {
52+
throw UnexpectedResponseCodeException(this.code, request.url.toString())
5253
}
5354
return this
5455
}
5556

5657
val Response.nonNullBody: ResponseBody
57-
get() = this.body() ?: throw UnexpectedResponseException("null body")
58+
get() = this.body ?: throw UnexpectedResponseException("null body")

0 commit comments

Comments
 (0)