Skip to content

Commit

Permalink
Merge pull request #21 from kkostov/some-upgrades
Browse files Browse the repository at this point in the history
Ktor Client and Gradle Plugin Updates
  • Loading branch information
winsmith authored Feb 1, 2024
2 parents f5c6a46 + 21090b0 commit e34d954
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'com.android.tools.build:gradle:8.2.2'
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
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ android.enableJetifier=true
kotlin.code.style=official

-Dorg.gradle.warning.mode=all
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
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 e34d954

Please sign in to comment.