Skip to content

Commit 5edcac2

Browse files
Java SDK generator update (#46)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 425d2b2 commit 5edcac2

File tree

192 files changed

+4880
-4609
lines changed

Some content is hidden

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

192 files changed

+4880
-4609
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.

src/main/java/com/merge/api/MergeApiClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public class MergeApiClient {
1818

1919
protected final Supplier<AtsClient> atsClient;
2020

21-
protected final Supplier<FilestorageClient> filestorageClient;
22-
2321
protected final Supplier<CrmClient> crmClient;
2422

23+
protected final Supplier<FilestorageClient> filestorageClient;
24+
2525
protected final Supplier<HrisClient> hrisClient;
2626

2727
protected final Supplier<TicketingClient> ticketingClient;
@@ -31,8 +31,8 @@ public class MergeApiClient {
3131
public MergeApiClient(ClientOptions clientOptions) {
3232
this.clientOptions = clientOptions;
3333
this.atsClient = Suppliers.memoize(() -> new AtsClient(clientOptions));
34-
this.filestorageClient = Suppliers.memoize(() -> new FilestorageClient(clientOptions));
3534
this.crmClient = Suppliers.memoize(() -> new CrmClient(clientOptions));
35+
this.filestorageClient = Suppliers.memoize(() -> new FilestorageClient(clientOptions));
3636
this.hrisClient = Suppliers.memoize(() -> new HrisClient(clientOptions));
3737
this.ticketingClient = Suppliers.memoize(() -> new TicketingClient(clientOptions));
3838
this.accountingClient = Suppliers.memoize(() -> new AccountingClient(clientOptions));
@@ -42,14 +42,14 @@ public AtsClient ats() {
4242
return this.atsClient.get();
4343
}
4444

45-
public FilestorageClient filestorage() {
46-
return this.filestorageClient.get();
47-
}
48-
4945
public CrmClient crm() {
5046
return this.crmClient.get();
5147
}
5248

49+
public FilestorageClient filestorage() {
50+
return this.filestorageClient.get();
51+
}
52+
5353
public HrisClient hris() {
5454
return this.hrisClient.get();
5555
}

src/main/java/com/merge/api/core/ApiError.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.merge.api.core;
5+
6+
/**
7+
* This exception type will be thrown for any non-2XX API responses.
8+
*/
9+
public class MergeApiApiError extends MergeApiError {
10+
/**
11+
* The error code of the response that triggered the exception.
12+
*/
13+
private final int statusCode;
14+
15+
/**
16+
* The body of the response that triggered the exception.
17+
*/
18+
private final Object body;
19+
20+
public MergeApiApiError(String message, int statusCode, Object body) {
21+
super(message);
22+
this.statusCode = statusCode;
23+
this.body = body;
24+
}
25+
26+
/**
27+
* @return the statusCode
28+
*/
29+
public int statusCode() {
30+
return this.statusCode;
31+
}
32+
33+
/**
34+
* @return the body
35+
*/
36+
public Object body() {
37+
return this.body;
38+
}
39+
40+
@java.lang.Override
41+
public String toString() {
42+
return "MergeApiApiError{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: " + body
43+
+ "}";
44+
}
45+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.merge.api.core;
5+
6+
/**
7+
* This class serves as the base exception for all errors in the SDK.
8+
*/
9+
public class MergeApiError extends RuntimeException {
10+
public MergeApiError(String message) {
11+
super(message);
12+
}
13+
14+
public MergeApiError(String message, Exception e) {
15+
super(message, e);
16+
}
17+
}

src/main/java/com/merge/api/core/RequestOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static final class Builder {
5252

5353
private String accountToken = null;
5454

55-
private Optional<Integer> timeout = null;
55+
private Optional<Integer> timeout = Optional.empty();
5656

5757
private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS;
5858

src/main/java/com/merge/api/resources/accounting/accountdetails/AccountDetailsClient.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*/
44
package com.merge.api.resources.accounting.accountdetails;
55

6-
import com.merge.api.core.ApiError;
76
import com.merge.api.core.ClientOptions;
7+
import com.merge.api.core.MergeApiApiError;
8+
import com.merge.api.core.MergeApiError;
89
import com.merge.api.core.ObjectMappers;
910
import com.merge.api.core.RequestOptions;
1011
import com.merge.api.resources.accounting.types.AccountDetails;
@@ -44,22 +45,22 @@ public AccountDetails retrieve(RequestOptions requestOptions) {
4445
.headers(Headers.of(clientOptions.headers(requestOptions)))
4546
.addHeader("Content-Type", "application/json")
4647
.build();
47-
try {
48-
OkHttpClient client = clientOptions.httpClient();
49-
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
50-
client = clientOptions.httpClientWithTimeout(requestOptions);
51-
}
52-
Response response = client.newCall(okhttpRequest).execute();
48+
OkHttpClient client = clientOptions.httpClient();
49+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
50+
client = clientOptions.httpClientWithTimeout(requestOptions);
51+
}
52+
try (Response response = client.newCall(okhttpRequest).execute()) {
5353
ResponseBody responseBody = response.body();
5454
if (response.isSuccessful()) {
5555
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AccountDetails.class);
5656
}
57-
throw new ApiError(
57+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
58+
throw new MergeApiApiError(
59+
"Error with status code " + response.code(),
5860
response.code(),
59-
ObjectMappers.JSON_MAPPER.readValue(
60-
responseBody != null ? responseBody.string() : "{}", Object.class));
61+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
6162
} catch (IOException e) {
62-
throw new RuntimeException(e);
63+
throw new MergeApiError("Network error executing HTTP request", e);
6364
}
6465
}
6566
}

src/main/java/com/merge/api/resources/accounting/accountingperiods/AccountingPeriodsClient.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*/
44
package com.merge.api.resources.accounting.accountingperiods;
55

6-
import com.merge.api.core.ApiError;
76
import com.merge.api.core.ClientOptions;
7+
import com.merge.api.core.MergeApiApiError;
8+
import com.merge.api.core.MergeApiError;
89
import com.merge.api.core.ObjectMappers;
910
import com.merge.api.core.RequestOptions;
1011
import com.merge.api.resources.accounting.accountingperiods.requests.AccountingPeriodsListRequest;
@@ -68,22 +69,22 @@ public PaginatedAccountingPeriodList list(AccountingPeriodsListRequest request,
6869
.headers(Headers.of(clientOptions.headers(requestOptions)))
6970
.addHeader("Content-Type", "application/json");
7071
Request okhttpRequest = _requestBuilder.build();
71-
try {
72-
OkHttpClient client = clientOptions.httpClient();
73-
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
74-
client = clientOptions.httpClientWithTimeout(requestOptions);
75-
}
76-
Response response = client.newCall(okhttpRequest).execute();
72+
OkHttpClient client = clientOptions.httpClient();
73+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
74+
client = clientOptions.httpClientWithTimeout(requestOptions);
75+
}
76+
try (Response response = client.newCall(okhttpRequest).execute()) {
7777
ResponseBody responseBody = response.body();
7878
if (response.isSuccessful()) {
7979
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PaginatedAccountingPeriodList.class);
8080
}
81-
throw new ApiError(
81+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
82+
throw new MergeApiApiError(
83+
"Error with status code " + response.code(),
8284
response.code(),
83-
ObjectMappers.JSON_MAPPER.readValue(
84-
responseBody != null ? responseBody.string() : "{}", Object.class));
85+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
8586
} catch (IOException e) {
86-
throw new RuntimeException(e);
87+
throw new MergeApiError("Network error executing HTTP request", e);
8788
}
8889
}
8990

@@ -120,22 +121,22 @@ public AccountingPeriod retrieve(
120121
.headers(Headers.of(clientOptions.headers(requestOptions)))
121122
.addHeader("Content-Type", "application/json");
122123
Request okhttpRequest = _requestBuilder.build();
123-
try {
124-
OkHttpClient client = clientOptions.httpClient();
125-
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
126-
client = clientOptions.httpClientWithTimeout(requestOptions);
127-
}
128-
Response response = client.newCall(okhttpRequest).execute();
124+
OkHttpClient client = clientOptions.httpClient();
125+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
126+
client = clientOptions.httpClientWithTimeout(requestOptions);
127+
}
128+
try (Response response = client.newCall(okhttpRequest).execute()) {
129129
ResponseBody responseBody = response.body();
130130
if (response.isSuccessful()) {
131131
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AccountingPeriod.class);
132132
}
133-
throw new ApiError(
133+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
134+
throw new MergeApiApiError(
135+
"Error with status code " + response.code(),
134136
response.code(),
135-
ObjectMappers.JSON_MAPPER.readValue(
136-
responseBody != null ? responseBody.string() : "{}", Object.class));
137+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
137138
} catch (IOException e) {
138-
throw new RuntimeException(e);
139+
throw new MergeApiError("Network error executing HTTP request", e);
139140
}
140141
}
141142
}

0 commit comments

Comments
 (0)