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
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

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

This package is currently in beta (pre-v1.0.0). We expect some breaking changes to rarely-used areas of the SDK, and appreciate your [feedback](https://www.github.com/Finch-API/finch-api-java/issues).

The Finch Java SDK is similar to the Finch 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 API documentation can be found [here](https://developer.tryfinch.com/).
The API documentation can be found [in the Finch Documentation Center](https://developer.tryfinch.com/).

---

Expand Down Expand Up @@ -79,30 +77,30 @@ Read the documentation for more configuration options.

### Example: creating a resource

To create a new hris directory, first use the `HrisDirectoryListIndividualsParams` builder to specify attributes,
then pass that to the `listIndividuals` method of the `directory` service.
To create a new hris directory, first use the `HrisDirectoryListParams` builder to specify attributes,
then pass that to the `list` method of the `directory` service.

```java
import com.tryfinch.api.models.HrisDirectoryListIndividualsPage;
import com.tryfinch.api.models.HrisDirectoryListIndividualsParams;
import com.tryfinch.api.models.HrisDirectoryListPage;
import com.tryfinch.api.models.HrisDirectoryListParams;
import com.tryfinch.api.models.Page;

HrisDirectoryListIndividualsParams params = HrisDirectoryListIndividualsParams.builder()
HrisDirectoryListParams params = HrisDirectoryListParams.builder()
.candidateId("<candidate id>")
.build();
HrisDirectoryListIndividualsPage hrisDirectory = client.directory().listIndividuals(params);
HrisDirectoryListPage hrisDirectory = client.directory().list(params);
```

### Example: listing resources

The Finch API provides a `listIndividuals` method to get a paginated list of directory.
The Finch API provides a `list` method to get a paginated list of directory.
You can retrieve the first page by:

```java
import com.tryfinch.api.models.IndividualInDirectory;
import com.tryfinch.api.models.Page;

HrisDirectoryListIndividualsPage page = client.directory().listIndividuals();
HrisDirectoryListPage page = client.directory().list();
for (IndividualInDirectory directory : page.individuals()) {
System.out.println(directory);
}
Expand All @@ -118,14 +116,14 @@ See [Pagination](#pagination) below for more information on transparently workin

To make a request to the Finch API, you generally build an instance of the appropriate `Params` class.

In [Example: creating a resource](#example-creating-a-resource) above, we used the `HrisDirectoryListIndividualsParams.builder()` to pass to
the `listIndividuals` method of the `directory` service.
In [Example: creating a resource](#example-creating-a-resource) above, we used the `HrisDirectoryListParams.builder()` to pass to
the `list` method of the `directory` service.

Sometimes, the API may support other properties that are not yet supported in the Java SDK types. In that case,
you can attach them using the `putAdditionalProperty` method.

```java
HrisDirectoryListIndividualsParams params = HrisDirectoryListIndividualsParams.builder()
HrisDirectoryListParams params = HrisDirectoryListParams.builder()
// ... normal properties
.putAdditionalProperty("secret_param", "4242")
.build();
Expand All @@ -138,7 +136,7 @@ HrisDirectoryListIndividualsParams params = HrisDirectoryListIndividualsParams.b
When receiving a response, the Finch Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `FinchInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model.

```java
HrisDirectoryListIndividualsPage hrisDirectory = client.directory().listIndividuals().validate();
HrisDirectoryListPage hrisDirectory = client.directory().list().validate();
```

### Response properties as JSON
Expand Down Expand Up @@ -187,13 +185,13 @@ which automatically handles fetching more pages for you:

```java
// As an Iterable:
HrisDirectoryListIndividualsPage page = client.directory().listIndividuals(params);
HrisDirectoryListPage page = client.directory().list(params);
for (IndividualInDirectory directory : page.autoPager()) {
System.out.println(directory);
};

// As a Stream:
client.directory().listIndividuals(params).autoPager().stream()
client.directory().list(params).autoPager().stream()
.limit(50)
.forEach(directory -> System.out.println(directory));
```
Expand All @@ -202,7 +200,7 @@ client.directory().listIndividuals(params).autoPager().stream()

```java
// Using forEach, which returns CompletableFuture<Void>:
asyncClient.directory().listIndividuals(params).autoPager()
asyncClient.directory().list(params).autoPager()
.forEach(directory -> System.out.println(directory), executor);
```

Expand All @@ -214,7 +212,7 @@ A page of results has a `data()` method to fetch the list of objects, as well as
`hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.

```java
HrisDirectoryListIndividualsPage page = client.directory().listIndividuals(params);
HrisDirectoryListPage page = client.directory().list(params);
while (page != null) {
for (IndividualInDirectory directory : page.individuals()) {
System.out.println(directory);
Expand Down Expand Up @@ -301,3 +299,14 @@ FinchClient client = FinchOkHttpClient.builder()
))
.build();
```

## Semantic Versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
2. Changes that we do not expect to impact the vast majority of users in practice.

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/Finch-API/finch-api-java/issues) with questions, bugs, or suggestions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import com.tryfinch.api.errors.FinchInvalidDataException
import java.util.Objects
import java.util.Optional

@JsonDeserialize(builder = BenfitContribution.Builder::class)
@JsonDeserialize(builder = BenefitContribution.Builder::class)
@NoAutoDetect
class BenfitContribution
class BenefitContribution
private constructor(
private val type: JsonField<Type>,
private val amount: JsonField<Long>,
Expand All @@ -46,7 +46,7 @@ private constructor(
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties

fun validate(): BenfitContribution = apply {
fun validate(): BenefitContribution = apply {
if (!validated) {
type()
amount()
Expand All @@ -61,7 +61,7 @@ private constructor(
return true
}

return other is BenfitContribution &&
return other is BenefitContribution &&
this.type == other.type &&
this.amount == other.amount &&
this.additionalProperties == other.additionalProperties
Expand All @@ -80,7 +80,7 @@ private constructor(
}

override fun toString() =
"BenfitContribution{type=$type, amount=$amount, additionalProperties=$additionalProperties}"
"BenefitContribution{type=$type, amount=$amount, additionalProperties=$additionalProperties}"

companion object {

Expand All @@ -94,10 +94,10 @@ private constructor(
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(benfitContribution: BenfitContribution) = apply {
this.type = benfitContribution.type
this.amount = benfitContribution.amount
additionalProperties(benfitContribution.additionalProperties)
internal fun from(benefitContribution: BenefitContribution) = apply {
this.type = benefitContribution.type
this.amount = benefitContribution.amount
additionalProperties(benefitContribution.additionalProperties)
}

/** Contribution type. */
Expand Down Expand Up @@ -130,8 +130,8 @@ private constructor(
this.additionalProperties.putAll(additionalProperties)
}

fun build(): BenfitContribution =
BenfitContribution(
fun build(): BenefitContribution =
BenefitContribution(
type,
amount,
additionalProperties.toUnmodifiable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ private constructor(
private val type: JsonField<BenefitType>,
private val description: JsonField<String>,
private val frequency: JsonField<BenefitFrequency>,
private val companyContribution: JsonField<BenfitContribution>,
private val employeeDeduction: JsonField<BenfitContribution>,
private val companyContribution: JsonField<BenefitContribution>,
private val employeeDeduction: JsonField<BenefitContribution>,
private val additionalProperties: Map<String, JsonValue>,
) {

Expand All @@ -43,10 +43,10 @@ private constructor(
fun frequency(): Optional<BenefitFrequency> =
Optional.ofNullable(frequency.getNullable("frequency"))

fun companyContribution(): Optional<BenfitContribution> =
fun companyContribution(): Optional<BenefitContribution> =
Optional.ofNullable(companyContribution.getNullable("company_contribution"))

fun employeeDeduction(): Optional<BenfitContribution> =
fun employeeDeduction(): Optional<BenefitContribution> =
Optional.ofNullable(employeeDeduction.getNullable("employee_deduction"))

@JsonProperty("benefit_id") @ExcludeMissing fun _benefitId() = benefitId
Expand Down Expand Up @@ -127,8 +127,8 @@ private constructor(
private var type: JsonField<BenefitType> = JsonMissing.of()
private var description: JsonField<String> = JsonMissing.of()
private var frequency: JsonField<BenefitFrequency> = JsonMissing.of()
private var companyContribution: JsonField<BenfitContribution> = JsonMissing.of()
private var employeeDeduction: JsonField<BenfitContribution> = JsonMissing.of()
private var companyContribution: JsonField<BenefitContribution> = JsonMissing.of()
private var employeeDeduction: JsonField<BenefitContribution> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
Expand Down Expand Up @@ -168,21 +168,21 @@ private constructor(
@ExcludeMissing
fun frequency(frequency: JsonField<BenefitFrequency>) = apply { this.frequency = frequency }

fun companyContribution(companyContribution: BenfitContribution) =
fun companyContribution(companyContribution: BenefitContribution) =
companyContribution(JsonField.of(companyContribution))

@JsonProperty("company_contribution")
@ExcludeMissing
fun companyContribution(companyContribution: JsonField<BenfitContribution>) = apply {
fun companyContribution(companyContribution: JsonField<BenefitContribution>) = apply {
this.companyContribution = companyContribution
}

fun employeeDeduction(employeeDeduction: BenfitContribution) =
fun employeeDeduction(employeeDeduction: BenefitContribution) =
employeeDeduction(JsonField.of(employeeDeduction))

@JsonProperty("employee_deduction")
@ExcludeMissing
fun employeeDeduction(employeeDeduction: JsonField<BenfitContribution>) = apply {
fun employeeDeduction(employeeDeduction: JsonField<BenefitContribution>) = apply {
this.employeeDeduction = employeeDeduction
}

Expand Down
Loading