Skip to content

Commit 10fb83f

Browse files
feat(client): add a withOptions method
1 parent 3c2b9e1 commit 10fb83f

File tree

117 files changed

+1589
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1589
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ See this table for the available options:
106106
> Don't create more than one client in the same application. Each client has a connection pool and
107107
> thread pools, which are more efficient to share between requests.
108108
109+
### Modifying configuration
110+
111+
To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service:
112+
113+
```kotlin
114+
import org.onebusaway.client.OnebusawaySdkClient
115+
116+
val clientWithOptions: OnebusawaySdkClient = client.withOptions {
117+
it.baseUrl("https://example.com")
118+
it.maxRetries(42)
119+
}
120+
```
121+
122+
The `withOptions()` method does not affect the original client or service.
123+
109124
## Requests and responses
110125

111126
To send a request to the Onebusaway SDK API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Kotlin class.

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClient.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package org.onebusaway.client
44

5+
import org.onebusaway.core.ClientOptions
56
import org.onebusaway.services.blocking.AgenciesWithCoverageService
67
import org.onebusaway.services.blocking.AgencyService
78
import org.onebusaway.services.blocking.ArrivalAndDepartureService
@@ -60,6 +61,13 @@ interface OnebusawaySdkClient {
6061
*/
6162
fun withRawResponse(): WithRawResponse
6263

64+
/**
65+
* Returns a view of this service with the given option modifications applied.
66+
*
67+
* The original service is not modified.
68+
*/
69+
fun withOptions(modifier: (ClientOptions.Builder) -> Unit): OnebusawaySdkClient
70+
6371
fun agenciesWithCoverage(): AgenciesWithCoverageService
6472

6573
fun agency(): AgencyService
@@ -134,6 +142,15 @@ interface OnebusawaySdkClient {
134142
*/
135143
interface WithRawResponse {
136144

145+
/**
146+
* Returns a view of this service with the given option modifications applied.
147+
*
148+
* The original service is not modified.
149+
*/
150+
fun withOptions(
151+
modifier: (ClientOptions.Builder) -> Unit
152+
): OnebusawaySdkClient.WithRawResponse
153+
137154
fun agenciesWithCoverage(): AgenciesWithCoverageService.WithRawResponse
138155

139156
fun agency(): AgencyService.WithRawResponse

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsync.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package org.onebusaway.client
44

5+
import org.onebusaway.core.ClientOptions
56
import org.onebusaway.services.async.AgenciesWithCoverageServiceAsync
67
import org.onebusaway.services.async.AgencyServiceAsync
78
import org.onebusaway.services.async.ArrivalAndDepartureServiceAsync
@@ -60,6 +61,13 @@ interface OnebusawaySdkClientAsync {
6061
*/
6162
fun withRawResponse(): WithRawResponse
6263

64+
/**
65+
* Returns a view of this service with the given option modifications applied.
66+
*
67+
* The original service is not modified.
68+
*/
69+
fun withOptions(modifier: (ClientOptions.Builder) -> Unit): OnebusawaySdkClientAsync
70+
6371
fun agenciesWithCoverage(): AgenciesWithCoverageServiceAsync
6472

6573
fun agency(): AgencyServiceAsync
@@ -135,6 +143,15 @@ interface OnebusawaySdkClientAsync {
135143
*/
136144
interface WithRawResponse {
137145

146+
/**
147+
* Returns a view of this service with the given option modifications applied.
148+
*
149+
* The original service is not modified.
150+
*/
151+
fun withOptions(
152+
modifier: (ClientOptions.Builder) -> Unit
153+
): OnebusawaySdkClientAsync.WithRawResponse
154+
138155
fun agenciesWithCoverage(): AgenciesWithCoverageServiceAsync.WithRawResponse
139156

140157
fun agency(): AgencyServiceAsync.WithRawResponse

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ class OnebusawaySdkClientAsyncImpl(private val clientOptions: ClientOptions) :
191191

192192
override fun withRawResponse(): OnebusawaySdkClientAsync.WithRawResponse = withRawResponse
193193

194+
override fun withOptions(modifier: (ClientOptions.Builder) -> Unit): OnebusawaySdkClientAsync =
195+
OnebusawaySdkClientAsyncImpl(clientOptions.toBuilder().apply(modifier).build())
196+
194197
override fun agenciesWithCoverage(): AgenciesWithCoverageServiceAsync = agenciesWithCoverage
195198

196199
override fun agency(): AgencyServiceAsync = agency
@@ -366,6 +369,13 @@ class OnebusawaySdkClientAsyncImpl(private val clientOptions: ClientOptions) :
366369
ShapeServiceAsyncImpl.WithRawResponseImpl(clientOptions)
367370
}
368371

372+
override fun withOptions(
373+
modifier: (ClientOptions.Builder) -> Unit
374+
): OnebusawaySdkClientAsync.WithRawResponse =
375+
OnebusawaySdkClientAsyncImpl.WithRawResponseImpl(
376+
clientOptions.toBuilder().apply(modifier).build()
377+
)
378+
369379
override fun agenciesWithCoverage(): AgenciesWithCoverageServiceAsync.WithRawResponse =
370380
agenciesWithCoverage
371381

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class OnebusawaySdkClientImpl(private val clientOptions: ClientOptions) : Onebus
182182

183183
override fun withRawResponse(): OnebusawaySdkClient.WithRawResponse = withRawResponse
184184

185+
override fun withOptions(modifier: (ClientOptions.Builder) -> Unit): OnebusawaySdkClient =
186+
OnebusawaySdkClientImpl(clientOptions.toBuilder().apply(modifier).build())
187+
185188
override fun agenciesWithCoverage(): AgenciesWithCoverageService = agenciesWithCoverage
186189

187190
override fun agency(): AgencyService = agency
@@ -355,6 +358,13 @@ class OnebusawaySdkClientImpl(private val clientOptions: ClientOptions) : Onebus
355358
ShapeServiceImpl.WithRawResponseImpl(clientOptions)
356359
}
357360

361+
override fun withOptions(
362+
modifier: (ClientOptions.Builder) -> Unit
363+
): OnebusawaySdkClient.WithRawResponse =
364+
OnebusawaySdkClientImpl.WithRawResponseImpl(
365+
clientOptions.toBuilder().apply(modifier).build()
366+
)
367+
358368
override fun agenciesWithCoverage(): AgenciesWithCoverageService.WithRawResponse =
359369
agenciesWithCoverage
360370

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsync.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.onebusaway.services.async
44

55
import com.google.errorprone.annotations.MustBeClosed
6+
import org.onebusaway.core.ClientOptions
67
import org.onebusaway.core.RequestOptions
78
import org.onebusaway.core.http.HttpResponseFor
89
import org.onebusaway.models.agencieswithcoverage.AgenciesWithCoverageListParams
@@ -15,6 +16,13 @@ interface AgenciesWithCoverageServiceAsync {
1516
*/
1617
fun withRawResponse(): WithRawResponse
1718

19+
/**
20+
* Returns a view of this service with the given option modifications applied.
21+
*
22+
* The original service is not modified.
23+
*/
24+
fun withOptions(modifier: (ClientOptions.Builder) -> Unit): AgenciesWithCoverageServiceAsync
25+
1826
/**
1927
* Returns a list of all transit agencies currently supported by OneBusAway along with the
2028
* center of their coverage area.
@@ -34,6 +42,15 @@ interface AgenciesWithCoverageServiceAsync {
3442
*/
3543
interface WithRawResponse {
3644

45+
/**
46+
* Returns a view of this service with the given option modifications applied.
47+
*
48+
* The original service is not modified.
49+
*/
50+
fun withOptions(
51+
modifier: (ClientOptions.Builder) -> Unit
52+
): AgenciesWithCoverageServiceAsync.WithRawResponse
53+
3754
/**
3855
* Returns a raw HTTP response for `get /api/where/agencies-with-coverage.json`, but is
3956
* otherwise the same as [AgenciesWithCoverageServiceAsync.list].

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsyncImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ internal constructor(private val clientOptions: ClientOptions) : AgenciesWithCov
2727
override fun withRawResponse(): AgenciesWithCoverageServiceAsync.WithRawResponse =
2828
withRawResponse
2929

30+
override fun withOptions(
31+
modifier: (ClientOptions.Builder) -> Unit
32+
): AgenciesWithCoverageServiceAsync =
33+
AgenciesWithCoverageServiceAsyncImpl(clientOptions.toBuilder().apply(modifier).build())
34+
3035
override suspend fun list(
3136
params: AgenciesWithCoverageListParams,
3237
requestOptions: RequestOptions,
@@ -39,6 +44,13 @@ internal constructor(private val clientOptions: ClientOptions) : AgenciesWithCov
3944

4045
private val errorHandler: Handler<JsonValue> = errorHandler(clientOptions.jsonMapper)
4146

47+
override fun withOptions(
48+
modifier: (ClientOptions.Builder) -> Unit
49+
): AgenciesWithCoverageServiceAsync.WithRawResponse =
50+
AgenciesWithCoverageServiceAsyncImpl.WithRawResponseImpl(
51+
clientOptions.toBuilder().apply(modifier).build()
52+
)
53+
4254
private val listHandler: Handler<AgenciesWithCoverageListResponse> =
4355
jsonHandler<AgenciesWithCoverageListResponse>(clientOptions.jsonMapper)
4456
.withErrorHandler(errorHandler)

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsync.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.onebusaway.services.async
44

55
import com.google.errorprone.annotations.MustBeClosed
6+
import org.onebusaway.core.ClientOptions
67
import org.onebusaway.core.RequestOptions
78
import org.onebusaway.core.http.HttpResponseFor
89
import org.onebusaway.models.agency.AgencyRetrieveParams
@@ -15,6 +16,13 @@ interface AgencyServiceAsync {
1516
*/
1617
fun withRawResponse(): WithRawResponse
1718

19+
/**
20+
* Returns a view of this service with the given option modifications applied.
21+
*
22+
* The original service is not modified.
23+
*/
24+
fun withOptions(modifier: (ClientOptions.Builder) -> Unit): AgencyServiceAsync
25+
1826
/** Retrieve information for a specific transit agency identified by its unique ID. */
1927
suspend fun retrieve(
2028
agencyId: String,
@@ -38,6 +46,15 @@ interface AgencyServiceAsync {
3846
*/
3947
interface WithRawResponse {
4048

49+
/**
50+
* Returns a view of this service with the given option modifications applied.
51+
*
52+
* The original service is not modified.
53+
*/
54+
fun withOptions(
55+
modifier: (ClientOptions.Builder) -> Unit
56+
): AgencyServiceAsync.WithRawResponse
57+
4158
/**
4259
* Returns a raw HTTP response for `get /api/where/agency/{agencyID}.json`, but is otherwise
4360
* the same as [AgencyServiceAsync.retrieve].

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsyncImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class AgencyServiceAsyncImpl internal constructor(private val clientOptions: Cli
2727

2828
override fun withRawResponse(): AgencyServiceAsync.WithRawResponse = withRawResponse
2929

30+
override fun withOptions(modifier: (ClientOptions.Builder) -> Unit): AgencyServiceAsync =
31+
AgencyServiceAsyncImpl(clientOptions.toBuilder().apply(modifier).build())
32+
3033
override suspend fun retrieve(
3134
params: AgencyRetrieveParams,
3235
requestOptions: RequestOptions,
@@ -39,6 +42,13 @@ class AgencyServiceAsyncImpl internal constructor(private val clientOptions: Cli
3942

4043
private val errorHandler: Handler<JsonValue> = errorHandler(clientOptions.jsonMapper)
4144

45+
override fun withOptions(
46+
modifier: (ClientOptions.Builder) -> Unit
47+
): AgencyServiceAsync.WithRawResponse =
48+
AgencyServiceAsyncImpl.WithRawResponseImpl(
49+
clientOptions.toBuilder().apply(modifier).build()
50+
)
51+
4252
private val retrieveHandler: Handler<AgencyRetrieveResponse> =
4353
jsonHandler<AgencyRetrieveResponse>(clientOptions.jsonMapper)
4454
.withErrorHandler(errorHandler)

onebusaway-sdk-kotlin-core/src/main/kotlin/org/onebusaway/services/async/ArrivalAndDepartureServiceAsync.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.onebusaway.services.async
44

55
import com.google.errorprone.annotations.MustBeClosed
6+
import org.onebusaway.core.ClientOptions
67
import org.onebusaway.core.RequestOptions
78
import org.onebusaway.core.http.HttpResponseFor
89
import org.onebusaway.models.arrivalanddeparture.ArrivalAndDepartureListParams
@@ -17,6 +18,13 @@ interface ArrivalAndDepartureServiceAsync {
1718
*/
1819
fun withRawResponse(): WithRawResponse
1920

21+
/**
22+
* Returns a view of this service with the given option modifications applied.
23+
*
24+
* The original service is not modified.
25+
*/
26+
fun withOptions(modifier: (ClientOptions.Builder) -> Unit): ArrivalAndDepartureServiceAsync
27+
2028
/** arrival-and-departure-for-stop */
2129
suspend fun retrieve(
2230
stopId: String,
@@ -58,6 +66,15 @@ interface ArrivalAndDepartureServiceAsync {
5866
*/
5967
interface WithRawResponse {
6068

69+
/**
70+
* Returns a view of this service with the given option modifications applied.
71+
*
72+
* The original service is not modified.
73+
*/
74+
fun withOptions(
75+
modifier: (ClientOptions.Builder) -> Unit
76+
): ArrivalAndDepartureServiceAsync.WithRawResponse
77+
6178
/**
6279
* Returns a raw HTTP response for `get
6380
* /api/where/arrival-and-departure-for-stop/{stopID}.json`, but is otherwise the same as

0 commit comments

Comments
 (0)