Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## (Upcoming)

**Kotlin 1.9.23**

- Updated the language level to 1.9.23
- Minor source changes to satisfy _ktlint_
- Minor changes due to new language level and library versions

**Version Catalogs**
- Adopted _version catalog_ dependency management.

## Version 5.0.0 (6 March, 2022)

A new stable release for your favourite Retrofit call adapter. v5 is a culmination of a lot of community contributions and an overhaul of the internals of the library.
Expand Down
32 changes: 14 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.jlleitschuh.gradle.ktlint.KtlintExtension

plugins {
kotlin("jvm") version "1.6.0"
id("org.jetbrains.dokka") version "1.6.0"
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.dokka)
alias(libs.plugins.ktlint)
`maven-publish`
}

Expand All @@ -25,7 +25,7 @@ val test by tasks.getting(Test::class) {
}

configure<KtlintExtension> {
version.set("0.43.0")
version.set("0.47.1")
ignoreFailures.set(false)
disabledRules.set(setOf("no-wildcard-imports"))
}
Expand All @@ -43,22 +43,18 @@ publishing {
}

dependencies {
val coroutinesVersion = "1.5.2"
val retrofitVersion = "2.9.0"
val okHttpVersion = "4.9.3"
val kotestVersion = "5.0.1"

api("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
api("com.squareup.retrofit2:retrofit:$retrofitVersion")
api("com.squareup.okhttp3:okhttp:$okHttpVersion")
api(libs.coroutines)
api(libs.retrofit)
api(libs.okhttp)
api(libs.okio)

testImplementation("com.squareup.okhttp3:mockwebserver:$okHttpVersion")
testImplementation("com.google.guava:guava:31.0.1-jre")
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("com.squareup.moshi:moshi-kotlin:1.12.0")
testImplementation("com.squareup.retrofit2:converter-moshi:$retrofitVersion")
testImplementation(libs.okhttp.mock.webserver)
testImplementation(libs.guava)
testImplementation(libs.kotest.runner)
testImplementation(libs.kotest.assertion)
testImplementation(libs.moshi)
testImplementation(libs.retrofit.converter.moshi)
}

tasks.dokkaGfm.configure {
Expand Down
38 changes: 38 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[versions]
coroutines = "1.5.2"
dokka = "1.9.20"
guava = "33.0.0-jre"
jupiter = "5.6.0"
kotest = "5.8.1"
kotlin = "1.9.23"
ktlint = "12.1.0"
moshi = "1.12.0"
okhttp = "4.12.0"
okio = "3.9.0"
retrofit = "2.9.0"
serialization = "1.6.3"
serialization-converter = "1.0.0"


[libraries]
coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jupiter" }
jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "jupiter" }
kotest-assertion = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-runner = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
moshi = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttp-mock-webserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okhttp" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converter-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }
serialization-converter = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter", version.ref = "serialization-converter" }
serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }


[plugins]
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
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.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 6 additions & 6 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
kotlin("plugin.serialization") version "1.5.31"
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.serialization)
}

group = "com.haroldadmin"
Expand All @@ -20,11 +20,11 @@ tasks.withType<KotlinCompile> {

dependencies {
implementation(project(":"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0")
implementation(libs.serialization.json)
implementation(libs.serialization.converter)

testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation(libs.jupiter.api)
testRuntimeOnly(libs.jupiter.engine)
}

tasks.getByName<Test>("test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import retrofit2.Retrofit

val url = "https://jsonplaceholder.typicode.com"
val contentType = "application/json".toMediaType()
private const val url = "https://jsonplaceholder.typicode.com"
private val contentType = "application/json".toMediaType()

val loggingInterceptor = { chain: Interceptor.Chain ->
val method = chain.request().method
Expand All @@ -24,7 +24,6 @@ val loggingInterceptor = { chain: Interceptor.Chain ->

val okHttp = OkHttpClient.Builder().addInterceptor(loggingInterceptor).build()

@OptIn(ExperimentalSerializationApi::class)
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(url)
.addCallAdapterFactory(NetworkResponseAdapterFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.haroldadmin.cnradapter.sample

import com.haroldadmin.cnradapter.CompletableResponse
import com.haroldadmin.cnradapter.NetworkResponse
import kotlinx.serialization.Serializable
import retrofit2.http.Body
Expand Down
17 changes: 8 additions & 9 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/5.4.1/userguide/multi_project_builds.html
*/

rootProject.name = "coroutines-network-response-adapter"

pluginManagement {
repositories {
gradlePluginPortal()
}
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}

include("sample")
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.lang.reflect.Type
*/
internal class DeferredNetworkResponseAdapter<S, E>(
private val successType: Type,
private val errorConverter: Converter<ResponseBody, E>,
private val errorConverter: Converter<ResponseBody, E>
) : CallAdapter<S, Deferred<NetworkResponse<S, E>>> {
override fun responseType(): Type {
return successType
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/haroldadmin/cnradapter/NetworkResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public sealed interface NetworkResponse<S, E> {
*/
public data class ServerError<S, E>(
public override val body: E?,
public val response: Response<*>?,
public val response: Response<*>?
) : Error<S, E> {
/**
* The status code returned by the server.
Expand All @@ -109,7 +109,7 @@ public sealed interface NetworkResponse<S, E> {
* The result of a network connectivity error
*/
public data class NetworkError<S, E>(
public override val error: IOException,
public override val error: IOException
) : Error<S, E> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private fun <S, E> parseSuccessfulResponse(response: Response<S>, successType: T
*/
internal fun <S, E> Throwable.asNetworkResponse(
successType: Type,
errorConverter: Converter<ResponseBody, E>,
errorConverter: Converter<ResponseBody, E>
): NetworkResponse<S, E> {
return when (this) {
is IOException -> NetworkResponse.NetworkError(this)
Expand Down