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.28"
".": "0.1.0-alpha.29"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.1.0-alpha.29 (2025-07-22)

Full Changelog: [v0.1.0-alpha.28...v0.1.0-alpha.29](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.28...v0.1.0-alpha.29)

### Features

* **client:** add `{QueryParams,Headers}#put(String, JsonValue)` methods ([6994f02](https://github.com/OneBusAway/java-sdk/commit/6994f026a6c7abb90a0bfec9ebb213f51dcf9347))
* **client:** allow configuring env via system properties ([8f26ee5](https://github.com/OneBusAway/java-sdk/commit/8f26ee53d24819972943490215990c79d929b2fd))

## 0.1.0-alpha.28 (2025-07-19)

Full Changelog: [v0.1.0-alpha.27...v0.1.0-alpha.28](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.27...v0.1.0-alpha.28)
Expand Down
37 changes: 22 additions & 15 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/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.28)
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.28/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.28)
[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.29)
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.29/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.29)

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

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

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

The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.28).
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.29).

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

Expand All @@ -26,7 +26,7 @@ The REST API documentation can be found on [developer.onebusaway.org](https://de
### Gradle

```kotlin
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.28")
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.29")
```

### Maven
Expand All @@ -35,7 +35,7 @@ implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.28")
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-sdk-java</artifactId>
<version>0.1.0-alpha.28</version>
<version>0.1.0-alpha.29</version>
</dependency>
```

Expand All @@ -53,21 +53,23 @@ import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveParams;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveResponse;

// Configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
// Configures using the `onebusawaysdk.onebusawayApiKey` and `onebusawaysdk.baseUrl` system properties
// Or configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.fromEnv();

CurrentTimeRetrieveResponse currentTime = client.currentTime().retrieve();
```

## Client configuration

Configure the client using environment variables:
Configure the client using system properties or environment variables:

```java
import org.onebusaway.client.OnebusawaySdkClient;
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient;

// Configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
// Configures using the `onebusawaysdk.onebusawayApiKey` and `onebusawaysdk.baseUrl` system properties
// Or configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.fromEnv();
```

Expand All @@ -89,18 +91,21 @@ import org.onebusaway.client.OnebusawaySdkClient;
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient;

OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder()
// Configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
// Configures using the `onebusawaysdk.onebusawayApiKey` and `onebusawaysdk.baseUrl` system properties
Or configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
.fromEnv()
.apiKey("My API Key")
.build();
```

See this table for the available options:

| Setter | Environment variable | Required | Default value |
| --------- | ------------------------- | -------- | ----------------------------------------- |
| `apiKey` | `ONEBUSAWAY_API_KEY` | true | - |
| `baseUrl` | `ONEBUSAWAY_SDK_BASE_URL` | true | `"https://api.pugetsound.onebusaway.org"` |
| Setter | System property | Environment variable | Required | Default value |
| --------- | -------------------------------- | ------------------------- | -------- | ----------------------------------------- |
| `apiKey` | `onebusawaysdk.onebusawayApiKey` | `ONEBUSAWAY_API_KEY` | true | - |
| `baseUrl` | `onebusawaysdk.baseUrl` | `ONEBUSAWAY_SDK_BASE_URL` | true | `"https://api.pugetsound.onebusaway.org"` |

System properties take precedence over environment variables.

> [!TIP]
> Don't create more than one client in the same application. Each client has a connection pool and
Expand Down Expand Up @@ -146,7 +151,8 @@ import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveParams;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveResponse;

// Configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
// Configures using the `onebusawaysdk.onebusawayApiKey` and `onebusawaysdk.baseUrl` system properties
// Or configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.fromEnv();

CompletableFuture<CurrentTimeRetrieveResponse> currentTime = client.async().currentTime().retrieve();
Expand All @@ -161,7 +167,8 @@ import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClientAsync;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveParams;
import org.onebusaway.models.currenttime.CurrentTimeRetrieveResponse;

// Configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
// Configures using the `onebusawaysdk.onebusawayApiKey` and `onebusawaysdk.baseUrl` system properties
// Or configures using the `ONEBUSAWAY_API_KEY` and `ONEBUSAWAY_SDK_BASE_URL` environment variables
OnebusawaySdkClientAsync client = OnebusawaySdkOkHttpClientAsync.fromEnv();

CompletableFuture<CurrentTimeRetrieveResponse> currentTime = client.currentTime().retrieve();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {

allprojects {
group = "org.onebusaway"
version = "0.1.0-alpha.28" // x-release-please-version
version = "0.1.0-alpha.29" // x-release-please-version
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ private constructor(
fun timeout(): Timeout = timeout

fun fromEnv() = apply {
System.getenv("ONEBUSAWAY_SDK_BASE_URL")?.let { baseUrl(it) }
System.getenv("ONEBUSAWAY_API_KEY")?.let { apiKey(it) }
(System.getProperty("onebusawaysdk.baseUrl")
?: System.getenv("ONEBUSAWAY_SDK_BASE_URL"))
?.let { baseUrl(it) }
(System.getProperty("onebusawaysdk.onebusawayApiKey")
?: System.getenv("ONEBUSAWAY_API_KEY"))
?.let { apiKey(it) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// File generated from our OpenAPI spec by Stainless.

package org.onebusaway.core.http

import java.util.TreeMap
import org.onebusaway.core.JsonArray
import org.onebusaway.core.JsonBoolean
import org.onebusaway.core.JsonMissing
import org.onebusaway.core.JsonNull
import org.onebusaway.core.JsonNumber
import org.onebusaway.core.JsonObject
import org.onebusaway.core.JsonString
import org.onebusaway.core.JsonValue
import org.onebusaway.core.toImmutable

class Headers
Expand Down Expand Up @@ -28,6 +38,19 @@ private constructor(
TreeMap(String.CASE_INSENSITIVE_ORDER)
private var size: Int = 0

fun put(name: String, value: JsonValue): Builder = apply {
when (value) {
is JsonMissing,
is JsonNull -> {}
is JsonBoolean -> put(name, value.value.toString())
is JsonNumber -> put(name, value.value.toString())
is JsonString -> put(name, value.value)
is JsonArray -> value.values.forEach { put(name, it) }
is JsonObject ->
value.values.forEach { (nestedName, value) -> put("$name.$nestedName", value) }
}
}

fun put(name: String, value: String) = apply {
map.getOrPut(name) { mutableListOf() }.add(value)
size++
Expand All @@ -41,15 +64,6 @@ private constructor(
headers.names().forEach { put(it, headers.values(it)) }
}

fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }

fun removeAll(names: Set<String>) = apply { names.forEach(::remove) }

fun clear() = apply {
map.clear()
size = 0
}

fun replace(name: String, value: String) = apply {
remove(name)
put(name, value)
Expand All @@ -68,6 +82,15 @@ private constructor(
headers.names().forEach { replace(it, headers.values(it)) }
}

fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }

fun removeAll(names: Set<String>) = apply { names.forEach(::remove) }

fun clear() = apply {
map.clear()
size = 0
}

fun build() =
Headers(
map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

package org.onebusaway.core.http

import org.onebusaway.core.JsonArray
import org.onebusaway.core.JsonBoolean
import org.onebusaway.core.JsonMissing
import org.onebusaway.core.JsonNull
import org.onebusaway.core.JsonNumber
import org.onebusaway.core.JsonObject
import org.onebusaway.core.JsonString
import org.onebusaway.core.JsonValue
import org.onebusaway.core.toImmutable

class QueryParams
Expand All @@ -28,6 +36,19 @@ private constructor(
private val map: MutableMap<String, MutableList<String>> = mutableMapOf()
private var size: Int = 0

fun put(key: String, value: JsonValue): Builder = apply {
when (value) {
is JsonMissing,
is JsonNull -> {}
is JsonBoolean -> put(key, value.value.toString())
is JsonNumber -> put(key, value.value.toString())
is JsonString -> put(key, value.value)
is JsonArray -> value.values.forEach { put(key, it) }
is JsonObject ->
value.values.forEach { (nestedKey, value) -> put("$key[$nestedKey]", value) }
}
}

fun put(key: String, value: String) = apply {
map.getOrPut(key) { mutableListOf() }.add(value)
size++
Expand Down