Skip to content

Commit 365f58b

Browse files
author
Jedlix
committed
Version 1.0.0
1 parent 8225fd0 commit 365f58b

File tree

7 files changed

+90
-89
lines changed

7 files changed

+90
-89
lines changed

build.gradle.kts

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
4-
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
3+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
4+
id("org.jmailen.kotlinter") version "3.14.0"
55
}
66

77
buildscript {
@@ -12,10 +12,11 @@ buildscript {
1212
dependencies {
1313
val androidGradlePluginVersion: String by project
1414
val kotlinVersion: String by project
15+
val dokkaVersion: String by project
1516
classpath("com.android.tools.build:gradle:$androidGradlePluginVersion")
1617
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
1718
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
18-
classpath("org.jetbrains.dokka:dokka-gradle-plugin:$kotlinVersion")
19+
classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion")
1920
}
2021
}
2122

@@ -46,20 +47,12 @@ nexusPublishing {
4647
}
4748

4849
allprojects {
49-
apply(plugin = "org.jlleitschuh.gradle.ktlint")
50+
apply(plugin = "org.jmailen.kotlinter")
5051

51-
ktlint {
52-
version.set("0.43.2")
53-
enableExperimentalRules.set(false)
54-
ignoreFailures.set(false)
55-
disabledRules.set(setOf("no-blank-line-before-rbrace", "no-wildcard-imports"))
56-
verbose.set(true)
57-
filter {
58-
exclude { it.file.path.contains("build/") }
59-
}
60-
reporters {
61-
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE)
62-
}
52+
// Workaround for Kapt not setting the proper JVM target
53+
// See https://youtrack.jetbrains.com/issue/KT-55947/Unable-to-set-kapt-jvm-target-version
54+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
55+
kotlinOptions.jvmTarget = "11"
6356
}
6457
}
6558

example/build.gradle.kts

+16-11
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ plugins {
66
}
77

88
android {
9-
compileSdk = 31
9+
compileSdk = 33
10+
namespace="com.jedlix.sdk.example"
1011
val buildCode: String? by project
1112

1213
defaultConfig {
1314
applicationId = "com.jedlix.sdk.example"
1415
minSdk = 21
15-
targetSdk = 31
1616
versionCode = buildCode?.toInt() ?: 1
1717
versionName = "1.0.0"
1818

@@ -47,16 +47,16 @@ android {
4747
}
4848

4949
dataBinding {
50-
isEnabled = true
50+
enable = true
5151
addKtx = true
5252
}
5353

5454
compileOptions {
55-
sourceCompatibility = JavaVersion.VERSION_1_8
56-
targetCompatibility = JavaVersion.VERSION_1_8
55+
sourceCompatibility = JavaVersion.VERSION_11
56+
targetCompatibility = JavaVersion.VERSION_11
5757
}
5858
kotlinOptions {
59-
jvmTarget = "1.8"
59+
jvmTarget = "11"
6060
}
6161
}
6262

@@ -80,17 +80,22 @@ dependencies {
8080
implementation("com.google.android.material:material:$materialVersion")
8181
implementation("androidx.constraintlayout:constraintlayout:$constraintLayoutVersion")
8282

83-
implementation(project(":sdk"))
83+
val exampleAsMavenLocal: String by project
84+
if (exampleAsMavenLocal.toBoolean()) {
85+
implementation("com.jedlix:sdk:1.6.0")
86+
} else {
87+
implementation(project(":sdk"))
88+
}
8489

85-
implementation("com.auth0.android:auth0:2.6.0")
90+
implementation("com.auth0.android:auth0:2.9.2")
8691
implementation("com.auth0.android:jwtdecode:2.0.1")
8792

8893
implementation("androidx.activity:activity-ktx:$androidxActivityVersion")
8994
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$androidxLifecycleVersion")
9095
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$androidxLifecycleVersion")
9196
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$androidxLifecycleVersion")
9297

93-
testImplementation("junit:junit:4.+")
94-
androidTestImplementation("androidx.test.ext:junit:1.1.3")
95-
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
98+
testImplementation("junit:junit:4.13.2")
99+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
100+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
96101
}

gradle.properties

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ android.useAndroidX=true
33
android.enableJetifier=true
44
kotlin.code.style=official
55

6-
androidGradlePluginVersion=7.0.4
7-
kotlinVersion=1.6.10
6+
androidGradlePluginVersion=8.0.0
7+
kotlinVersion=1.8.21
88

9-
androidCoreVersion=1.7.0
10-
appCompatVersion=1.4.0
11-
materialVersion=1.4.0
12-
constraintLayoutVersion=2.1.2
13-
serializationVersion=1.3.2
14-
ktorVersion=1.6.7
15-
androidxActivityVersion=1.4.0
16-
androidxLifecycleVersion=2.4.0
17-
androidxBrowserVersion=1.4.0
9+
androidCoreVersion=1.10.0
10+
appCompatVersion=1.6.1
11+
materialVersion=1.9.0
12+
constraintLayoutVersion=2.1.4
13+
serializationVersion=1.5.0
14+
ktorVersion=2.3.0
15+
androidxActivityVersion=1.7.1
16+
androidxLifecycleVersion=2.6.1
17+
androidxBrowserVersion=1.5.0
18+
dokkaVersion=1.8.10
1819

19-
sdkVersion=1.5.0
20+
sdkVersion=1.6.0
21+
exampleAsMavenLocal=false
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Wed Jan 05 11:34:33 CET 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

sdk/build.gradle.kts

+14-21
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ plugins {
88
}
99

1010
android {
11-
compileSdk = 31
11+
compileSdk = 33
12+
namespace="com.jedlix.sdk"
1213

1314
defaultConfig {
1415
minSdk = 21
15-
targetSdk = 31
1616

1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1818
}
@@ -26,11 +26,11 @@ android {
2626
}
2727
}
2828
compileOptions {
29-
sourceCompatibility = JavaVersion.VERSION_1_8
30-
targetCompatibility = JavaVersion.VERSION_1_8
29+
sourceCompatibility = JavaVersion.VERSION_11
30+
targetCompatibility = JavaVersion.VERSION_11
3131
}
3232
kotlinOptions {
33-
jvmTarget = "1.8"
33+
jvmTarget = "11"
3434
}
3535

3636
dependencies {
@@ -51,7 +51,8 @@ android {
5151

5252
implementation("io.ktor:ktor-client-core:$ktorVersion")
5353
implementation("io.ktor:ktor-client-android:$ktorVersion")
54-
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
54+
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
55+
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
5556
implementation("io.ktor:ktor-client-logging:$ktorVersion")
5657

5758
implementation("androidx.activity:activity-ktx:$androidxActivityVersion")
@@ -60,9 +61,9 @@ android {
6061
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$androidxLifecycleVersion")
6162
implementation("androidx.browser:browser:$androidxBrowserVersion")
6263

63-
testImplementation("junit:junit:4.+")
64-
androidTestImplementation("androidx.test.ext:junit:1.1.3")
65-
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
64+
testImplementation("junit:junit:4.13.2")
65+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
66+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
6667
}
6768
}
6869

@@ -83,17 +84,6 @@ val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
8384
from(dokkaHtml.outputDirectory)
8485
}
8586

86-
val androidSourcesJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
87-
dependsOn(javadocJar)
88-
archiveClassifier.set("sources")
89-
from(android.sourceSets["main"].java.srcDirs)
90-
}
91-
92-
artifacts {
93-
archives(javadocJar)
94-
archives(androidSourcesJar)
95-
}
96-
9787
afterEvaluate {
9888
publishing {
9989
publications {
@@ -118,7 +108,6 @@ afterEvaluate {
118108

119109
// Stub javadoc.jar artifact
120110
artifact(javadocJar.get())
121-
artifact(androidSourcesJar.get())
122111

123112
// Provide artifacts information required by Maven Central
124113
pom {
@@ -145,4 +134,8 @@ afterEvaluate {
145134
}
146135
}
147136
}
137+
138+
tasks.withType(AbstractPublishToMaven::class.java).configureEach {
139+
dependsOn(tasks.withType(Sign::class.java))
140+
}
148141
}

sdk/src/main/java/com/jedlix/sdk/JedlixSDK.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ class JedlixSDK private constructor(
9292
/**
9393
* Sets the [LogLevel] of the SDK
9494
*/
95-
var logLevel: LogLevel = if (BuildConfig.DEBUG) {
96-
LogLevel.ALL
97-
} else {
98-
LogLevel.ERRORS
99-
}
95+
var logLevel: LogLevel = LogLevel.ERRORS
10096

10197
/**
10298
* Provides the [Api] used by the SDK. Make sure [configure] has been called.

sdk/src/main/java/com/jedlix/sdk/networking/KtorApi.kt

+35-23
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,29 @@ package com.jedlix.sdk.networking
1818

1919
import com.jedlix.sdk.JedlixSDK
2020
import com.jedlix.sdk.networking.endpoint.EndpointNode
21-
import io.ktor.client.*
22-
import io.ktor.client.features.*
23-
import io.ktor.client.features.json.*
24-
import io.ktor.client.features.json.serializer.*
25-
import io.ktor.client.features.logging.*
26-
import io.ktor.client.request.*
27-
import io.ktor.client.statement.*
28-
import io.ktor.client.utils.*
29-
import io.ktor.http.*
30-
import io.ktor.util.*
31-
import io.ktor.utils.io.errors.*
21+
import io.ktor.client.HttpClient
22+
import io.ktor.client.plugins.HttpResponseValidator
23+
import io.ktor.client.plugins.HttpTimeout
24+
import io.ktor.client.plugins.ResponseException
25+
import io.ktor.client.plugins.addDefaultResponseValidation
26+
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
27+
import io.ktor.client.plugins.logging.LogLevel
28+
import io.ktor.client.plugins.logging.Logger
29+
import io.ktor.client.plugins.logging.Logging
30+
import io.ktor.client.request.headers
31+
import io.ktor.client.request.request
32+
import io.ktor.client.request.setBody
33+
import io.ktor.client.statement.bodyAsText
34+
import io.ktor.client.statement.request
35+
import io.ktor.http.ContentType
36+
import io.ktor.http.HttpMethod
37+
import io.ktor.http.HttpStatusCode
38+
import io.ktor.http.URLProtocol
39+
import io.ktor.http.contentType
40+
import io.ktor.http.encodedPath
41+
import io.ktor.http.fullPath
42+
import io.ktor.serialization.kotlinx.json.json
43+
import io.ktor.utils.io.errors.IOException
3244
import kotlinx.serialization.SerializationException
3345
import kotlinx.serialization.builtins.serializer
3446

@@ -48,8 +60,8 @@ internal class KtorApi(
4860

4961
private val client: HttpClient
5062
get() = HttpClient {
51-
install(JsonFeature) {
52-
serializer = KotlinxSerializer(json)
63+
install(ContentNegotiation) {
64+
json(json)
5365
}
5466
install(HttpTimeout) {
5567
connectTimeoutMillis = timeoutMillis
@@ -70,19 +82,19 @@ internal class KtorApi(
7082

7183
addDefaultResponseValidation()
7284
HttpResponseValidator {
73-
handleResponseException {
74-
throw when (it) {
85+
handleResponseExceptionWithRequest { exception, _ ->
86+
throw when (exception) {
7587
is ResponseException -> {
76-
val response = it.response
88+
val response = exception.response
7789
ApiException(
7890
response.status.value,
7991
response.request.url.fullPath,
8092
responseContentType = response.contentType()?.contentType,
8193
responseContentSubType = response.contentType()?.contentSubtype,
82-
responseBody = response.readText()
94+
responseBody = response.bodyAsText()
8395
)
8496
}
85-
else -> it
97+
else -> exception
8698
}
8799
}
88100
}
@@ -92,7 +104,7 @@ internal class KtorApi(
92104
return try {
93105
client.use { client ->
94106
val apiHost = host
95-
val response = client.request<HttpResponse> {
107+
val response = client.request {
96108
url {
97109
this.protocol = URLProtocol.HTTPS
98110
this.host = apiHost
@@ -111,7 +123,7 @@ internal class KtorApi(
111123
is Method.Get -> HttpMethod.Get
112124
is Method.MethodWithBody<*> -> {
113125
contentType(ContentType.Application.Json)
114-
body = method.body
126+
setBody(method.body)
115127
when (method) {
116128
is Method.Post<*> -> HttpMethod.Post
117129
is Method.Patch<*> -> HttpMethod.Patch
@@ -121,20 +133,20 @@ internal class KtorApi(
121133
is Method.Delete -> {
122134
// Api requires some body on delete requests
123135
contentType(ContentType.Application.Json)
124-
body = "{}"
136+
setBody("{}")
125137
HttpMethod.Delete
126138
}
127139
is Method.EmptyPost -> {
128140
contentType(ContentType.Application.Json)
129-
body = "{}"
141+
setBody("{}")
130142
HttpMethod.Post
131143
}
132144
}
133145
}
134146

135147
val content = when (response.status) {
136148
HttpStatusCode.NoContent -> json.encodeToString(Unit.serializer(), Unit)
137-
else -> response.readText()
149+
else -> response.bodyAsText()
138150
}
139151

140152
Response.Success(

0 commit comments

Comments
 (0)