From 85eec63933ab936d7362df9d75ab4772f4ce3787 Mon Sep 17 00:00:00 2001 From: Ely Deckers Date: Mon, 23 Aug 2021 22:49:09 +0200 Subject: [PATCH] fix: deprecation errors following OkHttp upgrade --- .../java/io/deckers/blob_courier/send/BlobSender.kt | 8 ++++---- .../blob_courier/send/SenderParameterFactory.kt | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/io/deckers/blob_courier/send/BlobSender.kt b/android/src/main/java/io/deckers/blob_courier/send/BlobSender.kt index fd6b13ef..99b55e77 100644 --- a/android/src/main/java/io/deckers/blob_courier/send/BlobSender.kt +++ b/android/src/main/java/io/deckers/blob_courier/send/BlobSender.kt @@ -59,21 +59,21 @@ class BlobSender( val response = sendRequestCall.execute() - val responseBody = response.body()?.string().orEmpty() + val responseBody = response.body?.string().orEmpty() li("Finished unmanaged send") return Success( mapOf( "response" to mapOf( - "code" to response.code(), + "code" to response.code, "data" to if (senderParameters.returnResponse) responseBody else "", - "headers" to mapHeadersToMap(response.headers()) + "headers" to mapHeadersToMap(response.headers) ) ) ) } catch (e: IOException) { - if (sendRequestCall.isCanceled) { + if (sendRequestCall.isCanceled()) { return Failure(createErrorFromThrowable(ERROR_CANCELED_EXCEPTION, e)) } diff --git a/android/src/main/java/io/deckers/blob_courier/send/SenderParameterFactory.kt b/android/src/main/java/io/deckers/blob_courier/send/SenderParameterFactory.kt index 58dd5419..8e5b4d94 100644 --- a/android/src/main/java/io/deckers/blob_courier/send/SenderParameterFactory.kt +++ b/android/src/main/java/io/deckers/blob_courier/send/SenderParameterFactory.kt @@ -32,11 +32,8 @@ import io.deckers.blob_courier.common.maybe import io.deckers.blob_courier.common.right import io.deckers.blob_courier.common.testKeep import io.deckers.blob_courier.common.validationContext -import io.deckers.blob_courier.upload.FilePayload -import io.deckers.blob_courier.upload.StringPayload -import io.deckers.blob_courier.upload.UploaderParameters -import okhttp3.MediaType -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody import java.net.URL @@ -61,8 +58,8 @@ data class SenderParameters( fun SenderParameters.toRequestBody(contentResolver: ContentResolver): RequestBody = InputStreamRequestBody( - mediaType.let(MediaType::parse) - ?: MediaType.get(DEFAULT_MIME_TYPE), + mediaType.toMediaTypeOrNull() + ?: DEFAULT_MIME_TYPE.toMediaType(), contentResolver, absoluteFilePath )