Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.2"
".": "0.1.0-alpha.3"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 7
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brand-dev%2Fbrand.dev-2df861cbe235900388f93a2e603090b713f6c5029e4daf2220bddface7882032.yml
openapi_spec_hash: d5a5643aea6c45631d7df49692cf9328
config_hash: bb3f3ba0dca413263e40968648f9a1a6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brand-dev%2Fbrand.dev-103a28182099d9866bc8c40db00f3356fe5be36302874e7ee84ee4fd2f593859.yml
openapi_spec_hash: 30241efa79f9aab6e430c29383d9a2cf
config_hash: 4ab8d35881cc0191126ff443317e03ba
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.1.0-alpha.3 (2025-06-13)

Full Changelog: [v0.1.0-alpha.2...v0.1.0-alpha.3](https://github.com/brand-dot-dev/java-sdk/compare/v0.1.0-alpha.2...v0.1.0-alpha.3)

### Features

* **api:** manual updates ([54375eb](https://github.com/brand-dot-dev/java-sdk/commit/54375ebc6a0bb8bcbf42b65a82acadf9bd783336))
* **client:** add a `withOptions` method ([3cfe90c](https://github.com/brand-dot-dev/java-sdk/commit/3cfe90c94543b1c271026eaeed3b4b941a311d81))
* **client:** implement per-endpoint base URL support ([a01b1d5](https://github.com/brand-dot-dev/java-sdk/commit/a01b1d5539251f6fb2d99b6e5d2b0a3d7ab075cb))

## 0.1.0-alpha.2 (2025-06-06)

Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/brand-dot-dev/java-sdk/compare/v0.1.0-alpha.1...v0.1.0-alpha.2)
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.branddev.api/brand-dev-java)](https://central.sonatype.com/artifact/com.branddev.api/brand-dev-java/0.1.0-alpha.2)
[![javadoc](https://javadoc.io/badge2/com.branddev.api/brand-dev-java/0.1.0-alpha.2/javadoc.svg)](https://javadoc.io/doc/com.branddev.api/brand-dev-java/0.1.0-alpha.2)
[![Maven Central](https://img.shields.io/maven-central/v/com.branddev.api/brand-dev-java)](https://central.sonatype.com/artifact/com.branddev.api/brand-dev-java/0.1.0-alpha.3)
[![javadoc](https://javadoc.io/badge2/com.branddev.api/brand-dev-java/0.1.0-alpha.3/javadoc.svg)](https://javadoc.io/doc/com.branddev.api/brand-dev-java/0.1.0-alpha.3)

<!-- x-release-please-end -->

Expand All @@ -13,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/).

<!-- x-release-please-start-version -->

Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.branddev.api/brand-dev-java/0.1.0-alpha.2).
Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.branddev.api/brand-dev-java/0.1.0-alpha.3).

<!-- x-release-please-end -->

Expand All @@ -24,7 +24,7 @@ Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.branddev.api/b
### Gradle

```kotlin
implementation("com.branddev.api:brand-dev-java:0.1.0-alpha.2")
implementation("com.branddev.api:brand-dev-java:0.1.0-alpha.3")
```

### Maven
Expand All @@ -33,7 +33,7 @@ implementation("com.branddev.api:brand-dev-java:0.1.0-alpha.2")
<dependency>
<groupId>com.branddev.api</groupId>
<artifactId>brand-dev-java</artifactId>
<version>0.1.0-alpha.2</version>
<version>0.1.0-alpha.3</version>
</dependency>
```

Expand Down Expand Up @@ -107,6 +107,21 @@ See this table for the available options:
> Don't create more than one client in the same application. Each client has a connection pool and
> thread pools, which are more efficient to share between requests.

### Modifying configuration

To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service:

```java
import com.branddev.api.client.BrandDevClient;

BrandDevClient clientWithOptions = client.withOptions(optionsBuilder -> {
optionsBuilder.baseUrl("https://example.com");
optionsBuilder.maxRetries(42);
});
```

The `withOptions()` method does not affect the original client or service.

## Requests and responses

To send a request to the Brand Dev 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 Java class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ class BrandDevOkHttpClient private constructor() {
fun build(): BrandDevClient =
BrandDevClientImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
.baseUrl(clientOptions.baseUrl())
.timeout(timeout)
.proxy(proxy)
.build()
)
.httpClient(OkHttpClient.builder().timeout(timeout).proxy(proxy).build())
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,7 @@ class BrandDevOkHttpClientAsync private constructor() {
fun build(): BrandDevClientAsync =
BrandDevClientAsyncImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
.baseUrl(clientOptions.baseUrl())
.timeout(timeout)
.proxy(proxy)
.build()
)
.httpClient(OkHttpClient.builder().timeout(timeout).proxy(proxy).build())
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.branddev.api.client.okhttp

import com.branddev.api.core.RequestOptions
import com.branddev.api.core.Timeout
import com.branddev.api.core.checkRequired
import com.branddev.api.core.http.Headers
import com.branddev.api.core.http.HttpClient
import com.branddev.api.core.http.HttpMethod
Expand All @@ -17,7 +16,6 @@ import java.time.Duration
import java.util.concurrent.CompletableFuture
import okhttp3.Call
import okhttp3.Callback
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
Expand All @@ -28,8 +26,7 @@ import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import okio.BufferedSink

class OkHttpClient
private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) :
class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) :
HttpClient {

override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
Expand Down Expand Up @@ -140,11 +137,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
}

private fun HttpRequest.toUrl(): String {
url?.let {
return it
}

val builder = baseUrl.newBuilder()
val builder = baseUrl.toHttpUrl().newBuilder()
pathSegments.forEach(builder::addPathSegment)
queryParams.keys().forEach { key ->
queryParams.values(key).forEach { builder.addQueryParameter(key, it) }
Expand Down Expand Up @@ -194,12 +187,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

class Builder internal constructor() {

private var baseUrl: HttpUrl? = null
private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }

fun timeout(timeout: Timeout) = apply { this.timeout = timeout }

fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
Expand All @@ -214,8 +204,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
.writeTimeout(timeout.write())
.callTimeout(timeout.request())
.proxy(proxy)
.build(),
checkRequired("baseUrl", baseUrl),
.build()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package com.branddev.api.client

import com.branddev.api.core.ClientOptions
import com.branddev.api.services.blocking.BrandService
import java.util.function.Consumer

/**
* A client for interacting with the Brand Dev REST API synchronously. You can also switch to
Expand Down Expand Up @@ -33,6 +35,13 @@ interface BrandDevClient {
*/
fun withRawResponse(): WithRawResponse

/**
* Returns a view of this service with the given option modifications applied.
*
* The original service is not modified.
*/
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BrandDevClient

fun brand(): BrandService

/**
Expand All @@ -51,6 +60,13 @@ interface BrandDevClient {
/** A view of [BrandDevClient] that provides access to raw HTTP responses for each method. */
interface WithRawResponse {

/**
* Returns a view of this service with the given option modifications applied.
*
* The original service is not modified.
*/
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BrandDevClient.WithRawResponse

fun brand(): BrandService.WithRawResponse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package com.branddev.api.client

import com.branddev.api.core.ClientOptions
import com.branddev.api.services.async.BrandServiceAsync
import java.util.function.Consumer

/**
* A client for interacting with the Brand Dev REST API asynchronously. You can also switch to
Expand Down Expand Up @@ -33,6 +35,13 @@ interface BrandDevClientAsync {
*/
fun withRawResponse(): WithRawResponse

/**
* Returns a view of this service with the given option modifications applied.
*
* The original service is not modified.
*/
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BrandDevClientAsync

fun brand(): BrandServiceAsync

/**
Expand All @@ -53,6 +62,15 @@ interface BrandDevClientAsync {
*/
interface WithRawResponse {

/**
* Returns a view of this service with the given option modifications applied.
*
* The original service is not modified.
*/
fun withOptions(
modifier: Consumer<ClientOptions.Builder>
): BrandDevClientAsync.WithRawResponse

fun brand(): BrandServiceAsync.WithRawResponse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.branddev.api.core.ClientOptions
import com.branddev.api.core.getPackageVersion
import com.branddev.api.services.async.BrandServiceAsync
import com.branddev.api.services.async.BrandServiceAsyncImpl
import java.util.function.Consumer

class BrandDevClientAsyncImpl(private val clientOptions: ClientOptions) : BrandDevClientAsync {

Expand All @@ -32,6 +33,9 @@ class BrandDevClientAsyncImpl(private val clientOptions: ClientOptions) : BrandD

override fun withRawResponse(): BrandDevClientAsync.WithRawResponse = withRawResponse

override fun withOptions(modifier: Consumer<ClientOptions.Builder>): BrandDevClientAsync =
BrandDevClientAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())

override fun brand(): BrandServiceAsync = brand

override fun close() = clientOptions.httpClient.close()
Expand All @@ -43,6 +47,13 @@ class BrandDevClientAsyncImpl(private val clientOptions: ClientOptions) : BrandD
BrandServiceAsyncImpl.WithRawResponseImpl(clientOptions)
}

override fun withOptions(
modifier: Consumer<ClientOptions.Builder>
): BrandDevClientAsync.WithRawResponse =
BrandDevClientAsyncImpl.WithRawResponseImpl(
clientOptions.toBuilder().apply(modifier::accept).build()
)

override fun brand(): BrandServiceAsync.WithRawResponse = brand
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.branddev.api.core.ClientOptions
import com.branddev.api.core.getPackageVersion
import com.branddev.api.services.blocking.BrandService
import com.branddev.api.services.blocking.BrandServiceImpl
import java.util.function.Consumer

class BrandDevClientImpl(private val clientOptions: ClientOptions) : BrandDevClient {

Expand All @@ -30,6 +31,9 @@ class BrandDevClientImpl(private val clientOptions: ClientOptions) : BrandDevCli

override fun withRawResponse(): BrandDevClient.WithRawResponse = withRawResponse

override fun withOptions(modifier: Consumer<ClientOptions.Builder>): BrandDevClient =
BrandDevClientImpl(clientOptions.toBuilder().apply(modifier::accept).build())

override fun brand(): BrandService = brand

override fun close() = clientOptions.httpClient.close()
Expand All @@ -41,6 +45,13 @@ class BrandDevClientImpl(private val clientOptions: ClientOptions) : BrandDevCli
BrandServiceImpl.WithRawResponseImpl(clientOptions)
}

override fun withOptions(
modifier: Consumer<ClientOptions.Builder>
): BrandDevClient.WithRawResponse =
BrandDevClientImpl.WithRawResponseImpl(
clientOptions.toBuilder().apply(modifier::accept).build()
)

override fun brand(): BrandService.WithRawResponse = brand
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.branddev.api.core.http.QueryParams
import com.branddev.api.core.http.RetryingHttpClient
import com.fasterxml.jackson.databind.json.JsonMapper
import java.time.Clock
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

class ClientOptions
private constructor(
Expand All @@ -17,7 +19,7 @@ private constructor(
@get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean,
@get:JvmName("jsonMapper") val jsonMapper: JsonMapper,
@get:JvmName("clock") val clock: Clock,
@get:JvmName("baseUrl") val baseUrl: String,
private val baseUrl: String?,
@get:JvmName("headers") val headers: Headers,
@get:JvmName("queryParams") val queryParams: QueryParams,
@get:JvmName("responseValidation") val responseValidation: Boolean,
Expand All @@ -32,6 +34,8 @@ private constructor(
}
}

fun baseUrl(): String = baseUrl ?: PRODUCTION_URL

fun toBuilder() = Builder().from(this)

companion object {
Expand Down Expand Up @@ -59,7 +63,7 @@ private constructor(
private var checkJacksonVersionCompatibility: Boolean = true
private var jsonMapper: JsonMapper = jsonMapper()
private var clock: Clock = Clock.systemUTC()
private var baseUrl: String = PRODUCTION_URL
private var baseUrl: String? = null
private var headers: Headers.Builder = Headers.builder()
private var queryParams: QueryParams.Builder = QueryParams.builder()
private var responseValidation: Boolean = false
Expand Down Expand Up @@ -92,7 +96,10 @@ private constructor(

fun clock(clock: Clock) = apply { this.clock = clock }

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
fun baseUrl(baseUrl: String?) = apply { this.baseUrl = baseUrl }

/** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
fun baseUrl(baseUrl: Optional<String>) = baseUrl(baseUrl.getOrNull())

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
Expand Down Expand Up @@ -184,8 +191,6 @@ private constructor(

fun removeAllQueryParams(keys: Set<String>) = apply { queryParams.removeAll(keys) }

fun baseUrl(): String = baseUrl

fun fromEnv() = apply {
System.getenv("BRAND_DEV_BASE_URL")?.let { baseUrl(it) }
System.getenv("BRAND_DEV_API_KEY")?.let { apiKey(it) }
Expand Down
Loading