3
3
package com.openlayer.api.client.okhttp
4
4
5
5
import com.fasterxml.jackson.databind.json.JsonMapper
6
- import com.openlayer.api.client.OpenlayerClientAsync
7
- import com.openlayer.api.client.OpenlayerClientAsyncImpl
8
- import com.openlayer.api.core.ClientOptions
6
+ import com.google.common.collect.Multimap
9
7
import java.net.Proxy
10
8
import java.time.Clock
11
9
import java.time.Duration
10
+ import java.util.Optional
11
+ import com.openlayer.api.core.ClientOptions
12
+ import com.openlayer.api.core.http.HttpClient
13
+ import com.openlayer.api.client.OpenlayerClientAsync
14
+ import com.openlayer.api.client.OpenlayerClientAsyncImpl
12
15
13
16
class OpenlayerOkHttpClientAsync private constructor() {
14
17
15
18
companion object {
16
19
17
- @JvmStatic fun builder () = Builder ()
20
+ @JvmStatic
21
+ fun builder () = Builder ()
18
22
19
- @JvmStatic fun fromEnv (): OpenlayerClientAsync = builder().fromEnv().build()
23
+ @JvmStatic
24
+ fun fromEnv (): OpenlayerClientAsync = builder().fromEnv().build()
20
25
}
21
26
22
27
class Builder {
@@ -32,15 +37,21 @@ class OpenlayerOkHttpClientAsync private constructor() {
32
37
this .baseUrl = baseUrl
33
38
}
34
39
35
- fun jsonMapper (jsonMapper : JsonMapper ) = apply { clientOptions.jsonMapper(jsonMapper) }
40
+ fun jsonMapper (jsonMapper : JsonMapper ) = apply {
41
+ clientOptions.jsonMapper(jsonMapper)
42
+ }
36
43
37
- fun clock (clock : Clock ) = apply { clientOptions.clock(clock) }
44
+ fun clock (clock : Clock ) = apply {
45
+ clientOptions.clock(clock)
46
+ }
38
47
39
48
fun headers (headers : Map <String , Iterable <String >>) = apply {
40
49
clientOptions.headers(headers)
41
50
}
42
51
43
- fun putHeader (name : String , value : String ) = apply { clientOptions.putHeader(name, value) }
52
+ fun putHeader (name : String , value : String ) = apply {
53
+ clientOptions.putHeader(name, value)
54
+ }
44
55
45
56
fun putHeaders (name : String , values : Iterable <String >) = apply {
46
57
clientOptions.putHeaders(name, values)
@@ -50,34 +61,42 @@ class OpenlayerOkHttpClientAsync private constructor() {
50
61
clientOptions.putAllHeaders(headers)
51
62
}
52
63
53
- fun removeHeader (name : String ) = apply { clientOptions.removeHeader(name) }
64
+ fun removeHeader (name : String ) = apply {
65
+ clientOptions.removeHeader(name)
66
+ }
54
67
55
- fun timeout (timeout : Duration ) = apply { this .timeout = timeout }
68
+ fun timeout (timeout : Duration ) = apply {
69
+ this .timeout = timeout
70
+ }
56
71
57
- fun maxRetries (maxRetries : Int ) = apply { clientOptions.maxRetries(maxRetries) }
72
+ fun maxRetries (maxRetries : Int ) = apply {
73
+ clientOptions.maxRetries(maxRetries)
74
+ }
58
75
59
- fun proxy (proxy : Proxy ) = apply { this .proxy = proxy }
76
+ fun proxy (proxy : Proxy ) = apply {
77
+ this .proxy = proxy
78
+ }
60
79
61
80
fun responseValidation (responseValidation : Boolean ) = apply {
62
81
clientOptions.responseValidation(responseValidation)
63
82
}
64
83
65
- fun apiKey (apiKey : String? ) = apply { clientOptions.apiKey(apiKey) }
84
+ fun apiKey (apiKey : String? ) = apply {
85
+ clientOptions.apiKey(apiKey)
86
+ }
66
87
67
- fun fromEnv () = apply { clientOptions.fromEnv() }
88
+ fun fromEnv () = apply {
89
+ clientOptions.fromEnv()
90
+ }
68
91
69
92
fun build (): OpenlayerClientAsync {
70
- return OpenlayerClientAsyncImpl (
71
- clientOptions
72
- .httpClient(
73
- OkHttpClient .builder()
74
- .baseUrl(baseUrl)
75
- .timeout(timeout)
76
- .proxy(proxy)
77
- .build()
78
- )
79
- .build()
80
- )
93
+ return OpenlayerClientAsyncImpl (clientOptions
94
+ .httpClient(OkHttpClient .builder()
95
+ .baseUrl(baseUrl)
96
+ .timeout(timeout)
97
+ .proxy(proxy)
98
+ .build())
99
+ .build())
81
100
}
82
101
}
83
102
}
0 commit comments