Skip to content

Commit

Permalink
Upgrade Ktor Client to 2.0 and Kotlin Gradle Plugin to 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kkostov committed Jan 31, 2024
1 parent a3ed289 commit 21090b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
12 changes: 7 additions & 5 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugins {
}

android {
compileSdk 31
compileSdk 33

defaultConfig {
minSdk 21
targetSdk 31
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -37,7 +37,7 @@ android {
namespace 'com.telemetrydeck.sdk'
}

def ktor_version = '1.6.7'
def ktor_version = '2.3.7'
def logback_version = '1.2.10'
def kotlinx_coroutines_version = '1.6.0'
dependencies {
Expand All @@ -50,8 +50,10 @@ dependencies {
implementation "io.ktor:ktor-client-cio:$ktor_version"
// HTTP Serialization
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties:1.3.2"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-properties:1.5.1"
// HTTP Logging
implementation "ch.qos.logback:logback-classic:$logback_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
Expand Down
21 changes: 12 additions & 9 deletions lib/src/main/java/com/telemetrydeck/sdk/TelemetryClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.telemetrydeck.sdk

import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.client.features.logging.*
import io.ktor.client.plugins.DefaultRequest
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.DEFAULT
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.json
import java.net.URL
import java.util.*

Expand All @@ -16,7 +19,9 @@ import java.util.*
*/
internal class TelemetryClient(private val telemetryAppID: UUID, private val apiBaseURL: URL, private val showDebugLogs: Boolean, private val debugLogger: DebugLogger?) {
private val client: HttpClient = HttpClient(CIO) {
install(JsonFeature)
install(ContentNegotiation) {
json()
}
if (showDebugLogs && debugLogger != null) {
install(Logging) {
logger = Logger.DEFAULT
Expand All @@ -32,10 +37,8 @@ internal class TelemetryClient(private val telemetryAppID: UUID, private val api
suspend fun send(
signals: List<Signal>
) {
val response: HttpResponse = client.request {
method = HttpMethod.Post
url(getServiceUrl())
body = signals
val response = client.post(getServiceUrl()) {
setBody(signals)
}
println(response.status)
client.close()
Expand Down

0 comments on commit 21090b0

Please sign in to comment.