Skip to content

Commit bb175e6

Browse files
committed
chore: add explicitApi mode in the core internal library
1 parent 8a45649 commit bb175e6

File tree

15 files changed

+45
-44
lines changed

15 files changed

+45
-44
lines changed

ychat-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ kover {
1818
}
1919

2020
kotlin {
21+
explicitApi()
2122
android()
2223
jvm()
2324
listOf(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package co.yml.ychat.core.model
22

3-
actual typealias FileBytes = ByteArray
3+
public actual typealias FileBytes = ByteArray
44

5-
actual fun FileBytes.toByteArray(): ByteArray {
5+
public actual fun FileBytes.toByteArray(): ByteArray {
66
return this
77
}

ychat-core/src/androidMain/kotlin/co/yml/ychat/core/network/factories/HttpEngineFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package co.yml.ychat.core.network.factories
33
import io.ktor.client.engine.HttpClientEngine
44
import io.ktor.client.engine.okhttp.OkHttp
55

6-
actual object HttpEngineFactory {
7-
actual fun getEngine(): HttpClientEngine {
6+
public actual object HttpEngineFactory {
7+
public actual fun getEngine(): HttpClientEngine {
88
return OkHttp.create()
99
}
1010
}

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/exceptions/YChatException.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package co.yml.ychat.core.exceptions
22

3-
class YChatException(
3+
public class YChatException(
44
message: String? = null,
55
cause: Throwable? = null,
6-
var statusCode: Int? = null,
6+
public var statusCode: Int? = null,
77
) : Exception(message, cause) {
88

9-
constructor(
9+
public constructor(
1010
cause: Throwable?,
1111
statusCode: Int? = null
1212
) : this(message = null, cause = cause, statusCode = statusCode)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package co.yml.ychat.core.model
22

3-
expect class FileBytes
3+
public expect class FileBytes
44

5-
expect fun FileBytes.toByteArray(): ByteArray
5+
public expect fun FileBytes.toByteArray(): ByteArray

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/network/extensions/ApiResultExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.ktor.client.statement.bodyAsText
99
import io.ktor.http.isSuccess
1010
import io.ktor.util.toMap
1111

12-
suspend inline fun <reified T> HttpResponse.toApiResult(): ApiResult<T> {
12+
public suspend inline fun <reified T> HttpResponse.toApiResult(): ApiResult<T> {
1313
val headers = this.headers.toMap()
1414
val statusCode = this.status.value
1515
return if (!this.status.isSuccess()) {
@@ -21,14 +21,14 @@ suspend inline fun <reified T> HttpResponse.toApiResult(): ApiResult<T> {
2121
}
2222
}
2323

24-
fun <T> ResponseException.toApiResult(): ApiResult<T> {
24+
public fun <T> ResponseException.toApiResult(): ApiResult<T> {
2525
return ApiResult(
2626
statusCode = this.response.status.value,
2727
exception = YChatException(this.cause, this.response.status.value)
2828
)
2929
}
3030

31-
fun <T> Throwable.toApiResult(): ApiResult<T> {
31+
public fun <T> Throwable.toApiResult(): ApiResult<T> {
3232
return ApiResult(
3333
statusCode = null,
3434
exception = YChatException(this.cause)

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/network/factories/HttpClientFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package co.yml.ychat.core.network.factories
22

33
import io.ktor.client.HttpClient
44

5-
interface HttpClientFactory {
6-
fun getHttpClient(): HttpClient
5+
public interface HttpClientFactory {
6+
public fun getHttpClient(): HttpClient
77
}

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/network/factories/HttpEngineFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package co.yml.ychat.core.network.factories
22

33
import io.ktor.client.engine.HttpClientEngine
44

5-
expect object HttpEngineFactory {
6-
actual fun getEngine(): HttpClientEngine
5+
public expect object HttpEngineFactory {
6+
public actual fun getEngine(): HttpClientEngine
77
}

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/network/infrastructure/ApiExecutor.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import io.ktor.http.HttpMethod
1717
import io.ktor.utils.io.errors.IOException
1818
import kotlin.collections.set
1919

20-
class ApiExecutor(private val httpClientFactory: HttpClientFactory) {
20+
public class ApiExecutor(private val httpClientFactory: HttpClientFactory) {
2121

2222
private val httpClient by lazy { httpClientFactory.getHttpClient() }
2323

@@ -29,39 +29,39 @@ class ApiExecutor(private val httpClientFactory: HttpClientFactory) {
2929

3030
private var query: HashMap<String, String> = HashMap()
3131

32-
val formParts = mutableListOf<FormPart<*>>()
32+
public val formParts: MutableList<FormPart<*>> = mutableListOf()
3333

34-
fun setEndpoint(endpoint: String): ApiExecutor {
34+
public fun setEndpoint(endpoint: String): ApiExecutor {
3535
this.endpoint = endpoint
3636
return this
3737
}
3838

39-
fun setHttpMethod(httpMethod: HttpMethod): ApiExecutor {
39+
public fun setHttpMethod(httpMethod: HttpMethod): ApiExecutor {
4040
this.httpMethod = httpMethod
4141
return this
4242
}
4343

44-
fun setBody(body: Any): ApiExecutor {
44+
public fun setBody(body: Any): ApiExecutor {
4545
this.body = body
4646
return this
4747
}
4848

49-
fun addQuery(key: String, value: String): ApiExecutor {
49+
public fun addQuery(key: String, value: String): ApiExecutor {
5050
this.query[key] = value
5151
return this
5252
}
5353

54-
fun addQuery(key: String, value: List<String>): ApiExecutor {
54+
public fun addQuery(key: String, value: List<String>): ApiExecutor {
5555
this.query[key] = value.joinToString(",")
5656
return this
5757
}
5858

59-
fun <T : Any> addFormPart(key: String, value: T): ApiExecutor {
59+
public fun <T : Any> addFormPart(key: String, value: T): ApiExecutor {
6060
formParts += FormPart(key, value)
6161
return this
6262
}
6363

64-
fun addFormPart(key: String, fileName: String, value: ByteArray): ApiExecutor {
64+
public fun addFormPart(key: String, fileName: String, value: ByteArray): ApiExecutor {
6565
val headers = Headers.build {
6666
append(HttpHeaders.ContentType, ContentType.Application.OctetStream.contentType)
6767
append(HttpHeaders.ContentDisposition, "filename=$fileName")
@@ -70,7 +70,7 @@ class ApiExecutor(private val httpClientFactory: HttpClientFactory) {
7070
return this
7171
}
7272

73-
suspend inline fun <reified T> execute(): ApiResult<T> {
73+
public suspend inline fun <reified T> execute(): ApiResult<T> {
7474
return try {
7575
val response = if (formParts.isEmpty()) executeRequest() else executeRequestAsForm()
7676
return response.toApiResult()
@@ -81,15 +81,15 @@ class ApiExecutor(private val httpClientFactory: HttpClientFactory) {
8181
}
8282
}
8383

84-
suspend fun executeRequest(): HttpResponse {
84+
public suspend fun executeRequest(): HttpResponse {
8585
return httpClient.request(endpoint) {
8686
url { query.forEach { parameters.append(it.key, it.value) } }
8787
method = httpMethod
8888
this.setBody(this@ApiExecutor.body)
8989
}
9090
}
9191

92-
suspend fun executeRequestAsForm(): HttpResponse {
92+
public suspend fun executeRequestAsForm(): HttpResponse {
9393
return httpClient.submitFormWithBinaryData(
9494
url = endpoint,
9595
formData = formData { formParts.forEach { append(it) } }

ychat-core/src/commonMain/kotlin/co/yml/ychat/core/network/infrastructure/ApiResult.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package co.yml.ychat.core.network.infrastructure
33
import co.yml.ychat.core.exceptions.YChatException
44

55
/** Encapsulates an outcome from source api. */
6-
data class ApiResult<T>(
6+
public data class ApiResult<T>(
77
val body: T? = null,
88
val headers: Map<String, List<String>> = mapOf(),
99
val statusCode: Int? = null,
@@ -14,14 +14,14 @@ data class ApiResult<T>(
1414
val isSuccessful: Boolean = exception == null
1515

1616
/** Try to get [body], if it is null an [YChatException] will be thrown. */
17-
fun getBodyOrThrow(): T {
17+
public fun getBodyOrThrow(): T {
1818
val exception = exception
1919
?: YChatException("Could not retrieve body from ApiResult.")
2020
return body ?: throw exception
2121
}
2222

2323
/** Throw an [exception] when [isSuccessful] is false. */
24-
fun ensureSuccess() {
24+
public fun ensureSuccess() {
2525
if (!isSuccessful)
2626
throw exception ?: YChatException("Api request was not successful.")
2727
}

0 commit comments

Comments
 (0)