-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d9dc4a
commit 5ed607a
Showing
71 changed files
with
7,541 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
src/main/java/com/flatfile/api/resources/apps/AppsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
package com.flatfile.api.resources.apps; | ||
|
||
import com.flatfile.api.core.ApiError; | ||
import com.flatfile.api.core.ClientOptions; | ||
import com.flatfile.api.core.ObjectMappers; | ||
import com.flatfile.api.core.RequestOptions; | ||
import com.flatfile.api.resources.apps.types.AppCreate; | ||
import com.flatfile.api.resources.apps.types.AppPatch; | ||
import com.flatfile.api.resources.apps.types.AppResponse; | ||
import com.flatfile.api.resources.apps.types.AppsResponse; | ||
import com.flatfile.api.resources.commons.types.AppId; | ||
import java.io.IOException; | ||
import okhttp3.Headers; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.MediaType; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
|
||
public class AppsClient { | ||
protected final ClientOptions clientOptions; | ||
|
||
public AppsClient(ClientOptions clientOptions) { | ||
this.clientOptions = clientOptions; | ||
} | ||
|
||
/** | ||
* Returns apps in an account | ||
*/ | ||
public AppsResponse list(RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("apps") | ||
.build(); | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("GET", null) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
try { | ||
Response response = | ||
clientOptions.httpClient().newCall(okhttpRequest).execute(); | ||
if (response.isSuccessful()) { | ||
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), AppsResponse.class); | ||
} | ||
throw new ApiError( | ||
response.code(), | ||
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Returns apps in an account | ||
*/ | ||
public AppsResponse list() { | ||
return list(null); | ||
} | ||
|
||
/** | ||
* Returns an app | ||
*/ | ||
public AppResponse get(AppId appId, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("apps") | ||
.addPathSegment(appId.toString()) | ||
.build(); | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("GET", null) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
try { | ||
Response response = | ||
clientOptions.httpClient().newCall(okhttpRequest).execute(); | ||
if (response.isSuccessful()) { | ||
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), AppResponse.class); | ||
} | ||
throw new ApiError( | ||
response.code(), | ||
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Returns an app | ||
*/ | ||
public AppResponse get(AppId appId) { | ||
return get(appId, null); | ||
} | ||
|
||
/** | ||
* Updates an app | ||
*/ | ||
public AppResponse update(AppId appId) { | ||
return update(appId, AppPatch.builder().build()); | ||
} | ||
|
||
/** | ||
* Updates an app | ||
*/ | ||
public AppResponse update(AppId appId, AppPatch request, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("apps") | ||
.addPathSegment(appId.toString()) | ||
.build(); | ||
RequestBody body; | ||
try { | ||
body = RequestBody.create( | ||
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json")); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("PATCH", body) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
try { | ||
Response response = | ||
clientOptions.httpClient().newCall(okhttpRequest).execute(); | ||
if (response.isSuccessful()) { | ||
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), AppResponse.class); | ||
} | ||
throw new ApiError( | ||
response.code(), | ||
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Updates an app | ||
*/ | ||
public AppResponse update(AppId appId, AppPatch request) { | ||
return update(appId, request, null); | ||
} | ||
|
||
/** | ||
* Creates an app | ||
*/ | ||
public AppResponse create(AppCreate request, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("apps") | ||
.build(); | ||
RequestBody body; | ||
try { | ||
body = RequestBody.create( | ||
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json")); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("POST", body) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
try { | ||
Response response = | ||
clientOptions.httpClient().newCall(okhttpRequest).execute(); | ||
if (response.isSuccessful()) { | ||
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), AppResponse.class); | ||
} | ||
throw new ApiError( | ||
response.code(), | ||
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Creates an app | ||
*/ | ||
public AppResponse create(AppCreate request) { | ||
return create(request, null); | ||
} | ||
} |
Oops, something went wrong.