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.25.0"
".": "0.26.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 103
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-326205df28a52e9ad57c34d7ed1ec85fadd67f9a041df2882ebaa65f6de09930.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-8663e8fc543041d9694eddcd2f7e9784611369606700f99340e6dc80607b2dfa.yml
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 0.26.0 (2025-01-30)

Full Changelog: [v0.25.0...v0.26.0](https://github.com/orbcorp/orb-java/compare/v0.25.0...v0.26.0)

### Features

* **api:** api update ([#222](https://github.com/orbcorp/orb-java/issues/222)) ([91cf3b9](https://github.com/orbcorp/orb-java/commit/91cf3b98866b16ce93da2db1381631b01f8eb865))


### Chores

* **internal:** codegen related update ([#217](https://github.com/orbcorp/orb-java/issues/217)) ([648708a](https://github.com/orbcorp/orb-java/commit/648708a1c05f37147b1dfefcb1a9f9e6774296b6))
* **internal:** codegen related update ([#220](https://github.com/orbcorp/orb-java/issues/220)) ([6975f2c](https://github.com/orbcorp/orb-java/commit/6975f2c9cfa3661ee487a8941d1fc22c0de7e5d7))
* **internal:** codegen related update ([#221](https://github.com/orbcorp/orb-java/issues/221)) ([61fa6a7](https://github.com/orbcorp/orb-java/commit/61fa6a7956a5849b58d4210f73debcc823c9d43e))
* **internal:** swap `checkNotNull` to `checkRequired` ([#219](https://github.com/orbcorp/orb-java/issues/219)) ([c77af54](https://github.com/orbcorp/orb-java/commit/c77af5465b01148fb1c84c0612e11fef5e0433c5))

## 0.25.0 (2025-01-23)

Full Changelog: [v0.24.0...v0.25.0](https://github.com/orbcorp/orb-java/compare/v0.24.0...v0.25.0)
Expand Down
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

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

[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.25.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.26.0)

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

The Orb Java SDK provides convenient access to the Orb REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property.
The Orb Java SDK provides convenient access to the Orb REST API from applications written in Java.

The Orb Java SDK is similar to the Orb Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions.

## Documentation
The REST API documentation can be found on [docs.withorb.com](https://docs.withorb.com/reference/api-reference).

The REST API documentation can be found on [docs.withorb.com](https://docs.withorb.com/reference/api-reference).

---

## Getting started

### Install dependencies

#### Gradle
## Installation

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

### Gradle

```kotlin
implementation("com.withorb.api:orb-java:0.25.0")
implementation("com.withorb.api:orb-java:0.26.0")
```

#### Maven
### Maven

```xml
<dependency>
<groupId>com.withorb.api</groupId>
<artifactId>orb-java</artifactId>
<version>0.25.0</version>
<version>0.26.0</version>
</dependency>
```

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

## Requirements

This library requires Java 8 or later.

## Usage

### Configure the client

Use `OrbOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
Expand Down Expand Up @@ -383,7 +383,3 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/orbcorp/orb-java/issues) with questions, bugs, or suggestions.

## Requirements

This library requires Java 8 or later.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "com.withorb.api"
version = "0.25.0" // x-release-please-version
version = "0.26.0" // x-release-please-version
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.withorb.api.client.okhttp

import com.withorb.api.core.RequestOptions
import com.withorb.api.core.checkRequired
import com.withorb.api.core.http.Headers
import com.withorb.api.core.http.HttpClient
import com.withorb.api.core.http.HttpMethod
Expand Down Expand Up @@ -192,7 +193,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
.proxy(proxy)
.build(),
checkNotNull(baseUrl) { "`baseUrl` is required but was not set" },
checkRequired("baseUrl", baseUrl),
)
}
}
3 changes: 1 addition & 2 deletions orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

package com.withorb.api.core

@JvmSynthetic
internal fun <T : Any> checkRequired(name: String, value: T?): T =
fun <T : Any> checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required, but was not set" }

@JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.withorb.api.core.http

import com.withorb.api.core.checkRequired
import com.withorb.api.core.toImmutable

class HttpRequest
Expand Down Expand Up @@ -134,7 +135,7 @@ private constructor(

fun build(): HttpRequest =
HttpRequest(
checkNotNull(method) { "`method` is required but was not set" },
checkRequired("method", method),
url,
pathSegments.toImmutable(),
headers.build(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.withorb.api.core.http

import com.withorb.api.core.RequestOptions
import com.withorb.api.core.checkRequired
import com.withorb.api.errors.OrbIoException
import java.io.IOException
import java.time.Clock
Expand Down Expand Up @@ -259,7 +260,7 @@ private constructor(

fun build(): HttpClient =
RetryingHttpClient(
checkNotNull(httpClient) { "`httpClient` is required but was not set" },
checkRequired("httpClient", httpClient),
clock,
maxRetries,
idempotencyHeader,
Expand Down
64 changes: 28 additions & 36 deletions orb-java-core/src/main/kotlin/com/withorb/api/models/Coupon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ private constructor(

fun discount(discount: JsonField<Discount>) = apply { this.discount = discount }

fun discount(percentageDiscount: PercentageDiscount) =
discount(Discount.ofPercentageDiscount(percentageDiscount))
fun discount(percentage: PercentageDiscount) = discount(Discount.ofPercentage(percentage))

fun discount(amountDiscount: AmountDiscount) =
discount(Discount.ofAmountDiscount(amountDiscount))
fun discount(amount: AmountDiscount) = discount(Discount.ofAmount(amount))

/**
* This allows for a coupon's discount to apply for a limited time (determined in months); a
Expand Down Expand Up @@ -330,31 +328,29 @@ private constructor(
@JsonSerialize(using = Discount.Serializer::class)
class Discount
private constructor(
private val percentageDiscount: PercentageDiscount? = null,
private val amountDiscount: AmountDiscount? = null,
private val percentage: PercentageDiscount? = null,
private val amount: AmountDiscount? = null,
private val _json: JsonValue? = null,
) {

fun percentageDiscount(): Optional<PercentageDiscount> =
Optional.ofNullable(percentageDiscount)
fun percentage(): Optional<PercentageDiscount> = Optional.ofNullable(percentage)

fun amountDiscount(): Optional<AmountDiscount> = Optional.ofNullable(amountDiscount)
fun amount(): Optional<AmountDiscount> = Optional.ofNullable(amount)

fun isPercentageDiscount(): Boolean = percentageDiscount != null
fun isPercentage(): Boolean = percentage != null

fun isAmountDiscount(): Boolean = amountDiscount != null
fun isAmount(): Boolean = amount != null

fun asPercentageDiscount(): PercentageDiscount =
percentageDiscount.getOrThrow("percentageDiscount")
fun asPercentage(): PercentageDiscount = percentage.getOrThrow("percentage")

fun asAmountDiscount(): AmountDiscount = amountDiscount.getOrThrow("amountDiscount")
fun asAmount(): AmountDiscount = amount.getOrThrow("amount")

fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)

fun <T> accept(visitor: Visitor<T>): T {
return when {
percentageDiscount != null -> visitor.visitPercentageDiscount(percentageDiscount)
amountDiscount != null -> visitor.visitAmountDiscount(amountDiscount)
percentage != null -> visitor.visitPercentage(percentage)
amount != null -> visitor.visitAmount(amount)
else -> visitor.unknown(_json)
}
}
Expand All @@ -368,12 +364,12 @@ private constructor(

accept(
object : Visitor<Unit> {
override fun visitPercentageDiscount(percentageDiscount: PercentageDiscount) {
percentageDiscount.validate()
override fun visitPercentage(percentage: PercentageDiscount) {
percentage.validate()
}

override fun visitAmountDiscount(amountDiscount: AmountDiscount) {
amountDiscount.validate()
override fun visitAmount(amount: AmountDiscount) {
amount.validate()
}
}
)
Expand All @@ -385,35 +381,32 @@ private constructor(
return true
}

return /* spotless:off */ other is Discount && percentageDiscount == other.percentageDiscount && amountDiscount == other.amountDiscount /* spotless:on */
return /* spotless:off */ other is Discount && percentage == other.percentage && amount == other.amount /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentageDiscount, amountDiscount) /* spotless:on */
override fun hashCode(): Int = /* spotless:off */ Objects.hash(percentage, amount) /* spotless:on */

override fun toString(): String =
when {
percentageDiscount != null -> "Discount{percentageDiscount=$percentageDiscount}"
amountDiscount != null -> "Discount{amountDiscount=$amountDiscount}"
percentage != null -> "Discount{percentage=$percentage}"
amount != null -> "Discount{amount=$amount}"
_json != null -> "Discount{_unknown=$_json}"
else -> throw IllegalStateException("Invalid Discount")
}

companion object {

@JvmStatic
fun ofPercentageDiscount(percentageDiscount: PercentageDiscount) =
Discount(percentageDiscount = percentageDiscount)
fun ofPercentage(percentage: PercentageDiscount) = Discount(percentage = percentage)

@JvmStatic
fun ofAmountDiscount(amountDiscount: AmountDiscount) =
Discount(amountDiscount = amountDiscount)
@JvmStatic fun ofAmount(amount: AmountDiscount) = Discount(amount = amount)
}

interface Visitor<out T> {

fun visitPercentageDiscount(percentageDiscount: PercentageDiscount): T
fun visitPercentage(percentage: PercentageDiscount): T

fun visitAmountDiscount(amountDiscount: AmountDiscount): T
fun visitAmount(amount: AmountDiscount): T

fun unknown(json: JsonValue?): T {
throw OrbInvalidDataException("Unknown Discount: $json")
Expand All @@ -431,13 +424,13 @@ private constructor(
"percentage" -> {
tryDeserialize(node, jacksonTypeRef<PercentageDiscount>()) { it.validate() }
?.let {
return Discount(percentageDiscount = it, _json = json)
return Discount(percentage = it, _json = json)
}
}
"amount" -> {
tryDeserialize(node, jacksonTypeRef<AmountDiscount>()) { it.validate() }
?.let {
return Discount(amountDiscount = it, _json = json)
return Discount(amount = it, _json = json)
}
}
}
Expand All @@ -454,9 +447,8 @@ private constructor(
provider: SerializerProvider
) {
when {
value.percentageDiscount != null ->
generator.writeObject(value.percentageDiscount)
value.amountDiscount != null -> generator.writeObject(value.amountDiscount)
value.percentage != null -> generator.writeObject(value.percentage)
value.amount != null -> generator.writeObject(value.amount)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid Discount")
}
Expand Down
Loading