From ad7c0cf81ae1f3478058cd6bced10563a5c74935 Mon Sep 17 00:00:00 2001 From: Ali Albaali Date: Wed, 27 Jan 2021 22:09:25 +0300 Subject: [PATCH] Add docs for predefined fetchers, decoders and mappers --- .../kamel/core/config/KamelConfigBuilder.kt | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/kamel-core/src/main/kotlin/io/kamel/core/config/KamelConfigBuilder.kt b/kamel-core/src/main/kotlin/io/kamel/core/config/KamelConfigBuilder.kt index 48e74707..01b100f1 100644 --- a/kamel-core/src/main/kotlin/io/kamel/core/config/KamelConfigBuilder.kt +++ b/kamel-core/src/main/kotlin/io/kamel/core/config/KamelConfigBuilder.kt @@ -14,6 +14,11 @@ import io.kamel.core.mapper.URIMapper import io.kamel.core.mapper.URLMapper import io.ktor.client.* import io.ktor.client.engine.* +import io.ktor.http.* +import java.io.File +import java.net.URI +import java.net.URL +import java.util.* public class KamelConfigBuilder { @@ -61,18 +66,44 @@ public class KamelConfigBuilder { } -public fun KamelConfigBuilder.httpFetcher(engine: HttpClientEngine, block: HttpClientConfig<*>.() -> Unit = {}): Unit = - fetcher(HttpFetcher(HttpClient(engine, block))) - -public fun KamelConfigBuilder.httpFetcher(block: HttpClientConfig<*>.() -> Unit = {}): Unit = - fetcher(HttpFetcher(HttpClient(block))) - +/** + * Adds an Http fetcher to the [KamelConfigBuilder] using the specified [engine] + * and an optional [block] for configuring this client. + */ +public fun KamelConfigBuilder.httpFetcher( + engine: HttpClientEngine, + block: HttpClientConfig<*>.() -> Unit = {} +): Unit = fetcher(HttpFetcher(HttpClient(engine, block))) + +/** + * Adds an Http fetcher to the [KamelConfigBuilder] by loading an [HttpClientEngine] from [ServiceLoader] + * and an optional [block] for configuring this client. + */ +public fun KamelConfigBuilder.httpFetcher( + block: HttpClientConfig<*>.() -> Unit = {} +): Unit = fetcher(HttpFetcher(HttpClient(block))) + +/** + * Adds a [File] fetcher to the [KamelConfigBuilder]. + */ public fun KamelConfigBuilder.fileFetcher(): Unit = fetcher(FileFetcher) +/** + * Adds an [ImageBitmap] decoder to the [KamelConfigBuilder]. + */ public fun KamelConfigBuilder.imageBitmapDecoder(): Unit = decoder(ImageBitmapDecoder) +/** + * Adds a [URL] to [Url] mapper to the [KamelConfigBuilder]. + */ public fun KamelConfigBuilder.urlMapper(): Unit = mapper(URLMapper) +/** + * Adds a [String] to [Url] mapper to the [KamelConfigBuilder]. + */ public fun KamelConfigBuilder.stringMapper(): Unit = mapper(StringMapper) +/** + * Adds a [URI] to [Url] mapper to the [KamelConfigBuilder]. + */ public fun KamelConfigBuilder.uriMapper(): Unit = mapper(URIMapper)