-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRawAppsClient.java
More file actions
176 lines (168 loc) · 7.7 KB
/
RawAppsClient.java
File metadata and controls
176 lines (168 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.pipedream.api.resources.apps;
import com.pipedream.api.core.BaseClientApiException;
import com.pipedream.api.core.BaseClientException;
import com.pipedream.api.core.BaseClientHttpResponse;
import com.pipedream.api.core.ClientOptions;
import com.pipedream.api.core.ObjectMappers;
import com.pipedream.api.core.QueryStringMapper;
import com.pipedream.api.core.RequestOptions;
import com.pipedream.api.core.pagination.SyncPagingIterable;
import com.pipedream.api.resources.apps.requests.AppsListRequest;
import com.pipedream.api.types.App;
import com.pipedream.api.types.GetAppResponse;
import com.pipedream.api.types.ListAppsResponse;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class RawAppsClient {
protected final ClientOptions clientOptions;
public RawAppsClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}
/**
* Retrieve all available apps with optional filtering and sorting
*/
public BaseClientHttpResponse<SyncPagingIterable<App>> list() {
return list(AppsListRequest.builder().build());
}
/**
* Retrieve all available apps with optional filtering and sorting
*/
public BaseClientHttpResponse<SyncPagingIterable<App>> list(AppsListRequest request) {
return list(request, null);
}
/**
* Retrieve all available apps with optional filtering and sorting
*/
public BaseClientHttpResponse<SyncPagingIterable<App>> list(
AppsListRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v1/connect/apps");
if (request.getAfter().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "after", request.getAfter().get(), false);
}
if (request.getBefore().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "before", request.getBefore().get(), false);
}
if (request.getLimit().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "limit", request.getLimit().get(), false);
}
if (request.getQ().isPresent()) {
QueryStringMapper.addQueryParameter(httpUrl, "q", request.getQ().get(), false);
}
if (request.getSortKey().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "sort_key", request.getSortKey().get(), false);
}
if (request.getSortDirection().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "sort_direction", request.getSortDirection().get(), false);
}
if (request.getHasComponents().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "has_components", request.getHasComponents().get(), false);
}
if (request.getHasActions().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "has_actions", request.getHasActions().get(), false);
}
if (request.getHasTriggers().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "has_triggers", request.getHasTriggers().get(), false);
}
if (request.getCategoryIds().isPresent()) {
QueryStringMapper.addQueryParameter(
httpUrl, "category_ids", request.getCategoryIds().get(), true);
}
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.build();
OkHttpClient client = clientOptions.httpClient();
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
client = clientOptions.httpClientWithTimeout(requestOptions);
}
try (Response response = client.newCall(okhttpRequest).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
ListAppsResponse parsedResponse =
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListAppsResponse.class);
Optional<String> startingAfter = parsedResponse.getPageInfo().getEndCursor();
AppsListRequest nextRequest = AppsListRequest.builder()
.from(request)
.after(startingAfter)
.build();
List<App> result = parsedResponse.getData();
return new BaseClientHttpResponse<>(
new SyncPagingIterable<App>(startingAfter.isPresent(), result, parsedResponse, () -> list(
nextRequest, requestOptions)
.body()),
response);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new BaseClientApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
response);
} catch (IOException e) {
throw new BaseClientException("Network error executing HTTP request", e);
}
}
/**
* Get detailed information about a specific app by ID or name slug
*/
public BaseClientHttpResponse<GetAppResponse> retrieve(String appId) {
return retrieve(appId, null);
}
/**
* Get detailed information about a specific app by ID or name slug
*/
public BaseClientHttpResponse<GetAppResponse> retrieve(String appId, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v1/connect/apps")
.addPathSegment(appId)
.build();
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Accept", "application/json")
.build();
OkHttpClient client = clientOptions.httpClient();
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
client = clientOptions.httpClientWithTimeout(requestOptions);
}
try (Response response = client.newCall(okhttpRequest).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return new BaseClientHttpResponse<>(
ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetAppResponse.class), response);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new BaseClientApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
response);
} catch (IOException e) {
throw new BaseClientException("Network error executing HTTP request", e);
}
}
}