Skip to content

Commit 03987f5

Browse files
committed
Update OkHttp and R8 rule
1 parent 8cc8cb4 commit 03987f5

File tree

3 files changed

+12
-57
lines changed

3 files changed

+12
-57
lines changed

studyplus-android-sdk/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ android {
77
minSdkVersion versions.minSdk
88
targetSdkVersion versions.targetSdk
99

10-
consumerProguardFiles 'lib-proguard-rules.txt'
11-
1210
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1311
}
1412

@@ -47,7 +45,7 @@ dependencies {
4745
implementation "androidx.annotation:annotation:$versions.annotation"
4846
implementation "androidx.core:core-ktx:$versions.core_ktx"
4947

50-
def okhttp = "3.14.2"
48+
def okhttp = "4.2.0"
5149
implementation "com.squareup.okhttp3:okhttp:$okhttp"
5250

5351
testImplementation 'junit:junit:4.12'

studyplus-android-sdk/lib-proguard-rules.txt

Lines changed: 0 additions & 44 deletions
This file was deleted.

studyplus-android-sdk/src/main/java/jp/studyplus/android/sdk/internal/api/ApiService.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import jp.studyplus.android.sdk.BuildConfig
44
import kotlinx.coroutines.CompletableDeferred
55
import kotlinx.coroutines.Deferred
66
import okhttp3.*
7+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
8+
import okhttp3.RequestBody.Companion.toRequestBody
79
import org.json.JSONObject
810
import java.io.IOException
911

1012
internal class ApiService(private val client: OkHttpClient) {
1113
fun post(auth: String, json: String): Deferred<Long?> {
1214
val body = createPostBody(json)
1315
val request = Request.Builder()
14-
.header("Accept", HEADER_JSON)
15-
.header("Content-type", HEADER_JSON)
16-
.addHeader("Authorization", auth)
17-
.url("$ENDPOINT/v1/study_records")
18-
.post(body)
19-
.build()
16+
.header("Accept", HEADER_JSON)
17+
.header("Content-type", HEADER_JSON)
18+
.addHeader("Authorization", auth)
19+
.url("$ENDPOINT/v1/study_records")
20+
.post(body)
21+
.build()
2022

2123
return execute(client.newCall(request))
2224
}
@@ -27,10 +29,9 @@ internal class ApiService(private val client: OkHttpClient) {
2729
}
2830
}
2931

30-
private val JSON_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8")
32+
private val JSON_MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()
3133

32-
internal fun createPostBody(json: String) =
33-
RequestBody.create(JSON_MEDIA_TYPE, json)
34+
internal fun createPostBody(json: String) = json.toRequestBody(JSON_MEDIA_TYPE)
3435

3536
internal fun execute(call: Call): Deferred<Long?> {
3637
val deferred = CompletableDeferred<Long?>()
@@ -51,7 +52,7 @@ internal fun execute(call: Call): Deferred<Long?> {
5152

5253
override fun onResponse(call: Call, response: Response) {
5354
if (response.isSuccessful) {
54-
val parsedJson = JSONObject(response.body()?.string() ?: EMPTY_JSON)
55+
val parsedJson = JSONObject(response.body?.string() ?: EMPTY_JSON)
5556
val recordId = parsedJson.optLong(RECORD_ID, INVALID_RECORD_ID)
5657

5758
if (recordId != INVALID_RECORD_ID) {

0 commit comments

Comments
 (0)