Skip to content

Commit 4039195

Browse files
Update Java SDK to support empty POST bodies (#17)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent af856a2 commit 4039195

File tree

175 files changed

+1917
-764
lines changed

Some content is hidden

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

175 files changed

+1917
-764
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@ jobs:
2020
- name: Compile
2121
run: ./gradlew compileJava
2222

23-
publish:
23+
test:
2424
needs: [ compile ]
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout repo
28+
uses: actions/checkout@v3
29+
30+
- name: Set up Java
31+
id: setup-jre
32+
uses: actions/setup-java@v1
33+
with:
34+
java-version: "11"
35+
architecture: x64
36+
37+
- name: Test
38+
run: ./gradlew test
39+
publish:
40+
needs: [ compile, test ]
2541
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
2642
runs-on: ubuntu-latest
2743

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies {
1616
api 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
1717
api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.3'
1818
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3'
19+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
20+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
1921
}
2022

2123
spotless {
@@ -29,12 +31,16 @@ java {
2931
withJavadocJar()
3032
}
3133

34+
test {
35+
useJUnitPlatform()
36+
}
37+
3238
publishing {
3339
publications {
3440
maven(MavenPublication) {
3541
groupId = 'dev.merge'
3642
artifactId = 'merge-java-client'
37-
version = '0.1.2'
43+
version = '0.1.3'
3844
from components.java
3945
}
4046
}

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

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

1818
protected final Supplier<CrmClient> crmClient;
1919

20-
protected final Supplier<FilestorageClient> filestorageClient;
21-
2220
protected final Supplier<HrisClient> hrisClient;
2321

22+
protected final Supplier<FilestorageClient> filestorageClient;
23+
2424
protected final Supplier<TicketingClient> ticketingClient;
2525

2626
protected final Supplier<AccountingClient> accountingClient;
@@ -29,8 +29,8 @@ public MergeApiClient(ClientOptions clientOptions) {
2929
this.clientOptions = clientOptions;
3030
this.atsClient = Suppliers.memoize(() -> new AtsClient(clientOptions));
3131
this.crmClient = Suppliers.memoize(() -> new CrmClient(clientOptions));
32-
this.filestorageClient = Suppliers.memoize(() -> new FilestorageClient(clientOptions));
3332
this.hrisClient = Suppliers.memoize(() -> new HrisClient(clientOptions));
33+
this.filestorageClient = Suppliers.memoize(() -> new FilestorageClient(clientOptions));
3434
this.ticketingClient = Suppliers.memoize(() -> new TicketingClient(clientOptions));
3535
this.accountingClient = Suppliers.memoize(() -> new AccountingClient(clientOptions));
3636
}
@@ -43,14 +43,14 @@ public CrmClient crm() {
4343
return this.crmClient.get();
4444
}
4545

46-
public FilestorageClient filestorage() {
47-
return this.filestorageClient.get();
48-
}
49-
5046
public HrisClient hris() {
5147
return this.hrisClient.get();
5248
}
5349

50+
public FilestorageClient filestorage() {
51+
return this.filestorageClient.get();
52+
}
53+
5454
public TicketingClient ticketing() {
5555
return this.ticketingClient.get();
5656
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.merge.api.core;
2+
3+
public final class ApiError extends RuntimeException {
4+
private final int statusCode;
5+
6+
private final Object body;
7+
8+
public ApiError(int statusCode, Object body) {
9+
this.statusCode = statusCode;
10+
this.body = body;
11+
}
12+
13+
public int statusCode() {
14+
return this.statusCode;
15+
}
16+
17+
public Object body() {
18+
return this.body;
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "ApiError{" + "statusCode: " + statusCode + ", body: " + body + "}";
24+
}
25+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private ClientOptions(
2323
this.headers = new HashMap<>();
2424
this.headers.putAll(headers);
2525
this.headers.putAll(Map.of(
26-
"X-Fern-SDK-Name", "com.merge.fern:api-sdk", "X-Fern-SDK-Version", "0.1.2", "X-Fern-Language", "JAVA"));
26+
"X-Fern-SDK-Name", "com.merge.fern:api-sdk", "X-Fern-SDK-Version", "0.1.3", "X-Fern-Language", "JAVA"));
2727
this.headerSuppliers = headerSuppliers;
2828
this.httpClient = httpClient;
2929
;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.merge.api.resources.accounting.accountdetails;
22

3+
import com.merge.api.core.ApiError;
34
import com.merge.api.core.ClientOptions;
45
import com.merge.api.core.ObjectMappers;
56
import com.merge.api.core.RequestOptions;
67
import com.merge.api.resources.accounting.types.AccountDetails;
8+
import java.io.IOException;
79
import okhttp3.Headers;
810
import okhttp3.HttpUrl;
911
import okhttp3.Request;
@@ -36,8 +38,10 @@ public AccountDetails retrieve(RequestOptions requestOptions) {
3638
if (_response.isSuccessful()) {
3739
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AccountDetails.class);
3840
}
39-
throw new RuntimeException();
40-
} catch (Exception e) {
41+
throw new ApiError(
42+
_response.code(),
43+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
44+
} catch (IOException e) {
4145
throw new RuntimeException(e);
4246
}
4347
}

src/main/java/com/merge/api/resources/accounting/accounts/AccountsClient.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.merge.api.resources.accounting.accounts;
22

3+
import com.merge.api.core.ApiError;
34
import com.merge.api.core.ClientOptions;
45
import com.merge.api.core.ObjectMappers;
56
import com.merge.api.core.RequestOptions;
@@ -10,6 +11,7 @@
1011
import com.merge.api.resources.accounting.types.AccountResponse;
1112
import com.merge.api.resources.accounting.types.MetaResponse;
1213
import com.merge.api.resources.accounting.types.PaginatedAccountList;
14+
import java.io.IOException;
1315
import java.util.HashMap;
1416
import java.util.Map;
1517
import okhttp3.Headers;
@@ -95,8 +97,10 @@ public PaginatedAccountList list(AccountsListRequest request, RequestOptions req
9597
if (_response.isSuccessful()) {
9698
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), PaginatedAccountList.class);
9799
}
98-
throw new RuntimeException();
99-
} catch (Exception e) {
100+
throw new ApiError(
101+
_response.code(),
102+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
103+
} catch (IOException e) {
100104
throw new RuntimeException(e);
101105
}
102106
}
@@ -138,8 +142,10 @@ public AccountResponse create(AccountEndpointRequest request, RequestOptions req
138142
if (_response.isSuccessful()) {
139143
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AccountResponse.class);
140144
}
141-
throw new RuntimeException();
142-
} catch (Exception e) {
145+
throw new ApiError(
146+
_response.code(),
147+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
148+
} catch (IOException e) {
143149
throw new RuntimeException(e);
144150
}
145151
}
@@ -181,8 +187,10 @@ public Account retrieve(String id, AccountsRetrieveRequest request, RequestOptio
181187
if (_response.isSuccessful()) {
182188
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Account.class);
183189
}
184-
throw new RuntimeException();
185-
} catch (Exception e) {
190+
throw new ApiError(
191+
_response.code(),
192+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
193+
} catch (IOException e) {
186194
throw new RuntimeException(e);
187195
}
188196
}
@@ -207,8 +215,10 @@ public MetaResponse metaPostRetrieve(RequestOptions requestOptions) {
207215
if (_response.isSuccessful()) {
208216
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), MetaResponse.class);
209217
}
210-
throw new RuntimeException();
211-
} catch (Exception e) {
218+
throw new ApiError(
219+
_response.code(),
220+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
221+
} catch (IOException e) {
212222
throw new RuntimeException(e);
213223
}
214224
}

src/main/java/com/merge/api/resources/accounting/accounttoken/AccountTokenClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.merge.api.resources.accounting.accounttoken;
22

3+
import com.merge.api.core.ApiError;
34
import com.merge.api.core.ClientOptions;
45
import com.merge.api.core.ObjectMappers;
56
import com.merge.api.core.RequestOptions;
67
import com.merge.api.resources.accounting.types.AccountToken;
8+
import java.io.IOException;
79
import okhttp3.Headers;
810
import okhttp3.HttpUrl;
911
import okhttp3.Request;
@@ -37,8 +39,10 @@ public AccountToken retrieve(String publicToken, RequestOptions requestOptions)
3739
if (_response.isSuccessful()) {
3840
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AccountToken.class);
3941
}
40-
throw new RuntimeException();
41-
} catch (Exception e) {
42+
throw new ApiError(
43+
_response.code(),
44+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
45+
} catch (IOException e) {
4246
throw new RuntimeException(e);
4347
}
4448
}

src/main/java/com/merge/api/resources/accounting/addresses/AddressesClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.merge.api.resources.accounting.addresses;
22

3+
import com.merge.api.core.ApiError;
34
import com.merge.api.core.ClientOptions;
45
import com.merge.api.core.ObjectMappers;
56
import com.merge.api.core.RequestOptions;
67
import com.merge.api.resources.accounting.addresses.requests.AddressesRetrieveRequest;
78
import com.merge.api.resources.accounting.types.Address;
9+
import java.io.IOException;
810
import okhttp3.Headers;
911
import okhttp3.HttpUrl;
1012
import okhttp3.Request;
@@ -52,8 +54,10 @@ public Address retrieve(String id, AddressesRetrieveRequest request, RequestOpti
5254
if (_response.isSuccessful()) {
5355
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Address.class);
5456
}
55-
throw new RuntimeException();
56-
} catch (Exception e) {
57+
throw new ApiError(
58+
_response.code(),
59+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
60+
} catch (IOException e) {
5761
throw new RuntimeException(e);
5862
}
5963
}

src/main/java/com/merge/api/resources/accounting/asyncpassthrough/AsyncPassthroughClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.merge.api.resources.accounting.asyncpassthrough;
22

3+
import com.merge.api.core.ApiError;
34
import com.merge.api.core.ClientOptions;
45
import com.merge.api.core.ObjectMappers;
56
import com.merge.api.core.RequestOptions;
67
import com.merge.api.resources.accounting.types.AsyncPassthroughReciept;
78
import com.merge.api.resources.accounting.types.DataPassthroughRequest;
89
import com.merge.api.resources.accounting.types.RemoteResponse;
10+
import java.io.IOException;
911
import okhttp3.Headers;
1012
import okhttp3.HttpUrl;
1113
import okhttp3.MediaType;
@@ -47,8 +49,10 @@ public AsyncPassthroughReciept create(DataPassthroughRequest request, RequestOpt
4749
if (_response.isSuccessful()) {
4850
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AsyncPassthroughReciept.class);
4951
}
50-
throw new RuntimeException();
51-
} catch (Exception e) {
52+
throw new ApiError(
53+
_response.code(),
54+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
55+
} catch (IOException e) {
5256
throw new RuntimeException(e);
5357
}
5458
}
@@ -74,8 +78,10 @@ public RemoteResponse retrieve(String asyncPassthroughReceiptId, RequestOptions
7478
if (_response.isSuccessful()) {
7579
return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RemoteResponse.class);
7680
}
77-
throw new RuntimeException();
78-
} catch (Exception e) {
81+
throw new ApiError(
82+
_response.code(),
83+
ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class));
84+
} catch (IOException e) {
7985
throw new RuntimeException(e);
8086
}
8187
}

0 commit comments

Comments
 (0)