Skip to content

Commit fd6995d

Browse files
File stash downloads and stricter prop values (#128)
* Add new API to download files from a file stash * Specify the possible prop values (instead of `Object`)
1 parent 4960e00 commit fd6995d

File tree

10 files changed

+496
-18
lines changed

10 files changed

+496
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Add the dependency in your `pom.xml` file:
2525
<dependency>
2626
<groupId>com.pipedream</groupId>
2727
<artifactId>pipedream</artifactId>
28-
<version>1.0.4</version>
28+
<version>1.0.5</version>
2929
</dependency>
3030
```
3131

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ java {
4848

4949
group = 'com.pipedream'
5050

51-
version = '1.0.4'
51+
version = '1.0.5'
5252

5353
jar {
5454
dependsOn(":generatePomFileForMavenPublication")
@@ -79,7 +79,7 @@ publishing {
7979
maven(MavenPublication) {
8080
groupId = 'com.pipedream'
8181
artifactId = 'pipedream'
82-
version = '1.0.4'
82+
version = '1.0.5'
8383
from components.java
8484
pom {
8585
name = 'pipedream'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ private ClientOptions(
3535
this.headers.putAll(headers);
3636
this.headers.putAll(new HashMap<String, String>() {
3737
{
38-
put("User-Agent", "com.pipedream:pipedream/1.0.4");
38+
put("User-Agent", "com.pipedream:pipedream/1.0.5");
3939
put("X-Fern-Language", "JAVA");
4040
put("X-Fern-SDK-Name", "com.pipedream.fern:api-sdk");
41-
put("X-Fern-SDK-Version", "1.0.4");
41+
put("X-Fern-SDK-Version", "1.0.5");
4242
}
4343
});
4444
this.headerSuppliers = headerSuppliers;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.pipedream.api.resources.filestash;
5+
6+
import com.pipedream.api.core.ClientOptions;
7+
import com.pipedream.api.core.RequestOptions;
8+
import com.pipedream.api.resources.filestash.requests.FileStashDownloadFileRequest;
9+
import java.util.concurrent.CompletableFuture;
10+
11+
public class AsyncFileStashClient {
12+
protected final ClientOptions clientOptions;
13+
14+
private final AsyncRawFileStashClient rawClient;
15+
16+
public AsyncFileStashClient(ClientOptions clientOptions) {
17+
this.clientOptions = clientOptions;
18+
this.rawClient = new AsyncRawFileStashClient(clientOptions);
19+
}
20+
21+
/**
22+
* Get responses with HTTP metadata like headers
23+
*/
24+
public AsyncRawFileStashClient withRawResponse() {
25+
return this.rawClient;
26+
}
27+
28+
/**
29+
* Download a file from File Stash
30+
*/
31+
public CompletableFuture<Void> downloadFile(FileStashDownloadFileRequest request) {
32+
return this.rawClient.downloadFile(request).thenApply(response -> response.body());
33+
}
34+
35+
/**
36+
* Download a file from File Stash
37+
*/
38+
public CompletableFuture<Void> downloadFile(FileStashDownloadFileRequest request, RequestOptions requestOptions) {
39+
return this.rawClient.downloadFile(request, requestOptions).thenApply(response -> response.body());
40+
}
41+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.pipedream.api.resources.filestash;
5+
6+
import com.fasterxml.jackson.core.JsonProcessingException;
7+
import com.pipedream.api.core.BaseClientApiException;
8+
import com.pipedream.api.core.BaseClientException;
9+
import com.pipedream.api.core.BaseClientHttpResponse;
10+
import com.pipedream.api.core.ClientOptions;
11+
import com.pipedream.api.core.ObjectMappers;
12+
import com.pipedream.api.core.QueryStringMapper;
13+
import com.pipedream.api.core.RequestOptions;
14+
import com.pipedream.api.errors.TooManyRequestsError;
15+
import com.pipedream.api.resources.filestash.requests.FileStashDownloadFileRequest;
16+
import java.io.IOException;
17+
import java.util.concurrent.CompletableFuture;
18+
import okhttp3.Call;
19+
import okhttp3.Callback;
20+
import okhttp3.Headers;
21+
import okhttp3.HttpUrl;
22+
import okhttp3.OkHttpClient;
23+
import okhttp3.Request;
24+
import okhttp3.Response;
25+
import okhttp3.ResponseBody;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
public class AsyncRawFileStashClient {
29+
protected final ClientOptions clientOptions;
30+
31+
public AsyncRawFileStashClient(ClientOptions clientOptions) {
32+
this.clientOptions = clientOptions;
33+
}
34+
35+
/**
36+
* Download a file from File Stash
37+
*/
38+
public CompletableFuture<BaseClientHttpResponse<Void>> downloadFile(FileStashDownloadFileRequest request) {
39+
return downloadFile(request, null);
40+
}
41+
42+
/**
43+
* Download a file from File Stash
44+
*/
45+
public CompletableFuture<BaseClientHttpResponse<Void>> downloadFile(
46+
FileStashDownloadFileRequest request, RequestOptions requestOptions) {
47+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
48+
.newBuilder()
49+
.addPathSegments("v1/connect")
50+
.addPathSegment(clientOptions.projectId())
51+
.addPathSegments("file_stash/download");
52+
QueryStringMapper.addQueryParameter(httpUrl, "s3_key", request.getS3Key(), false);
53+
Request.Builder _requestBuilder = new Request.Builder()
54+
.url(httpUrl.build())
55+
.method("GET", null)
56+
.headers(Headers.of(clientOptions.headers(requestOptions)))
57+
.addHeader("Accept", "application/json");
58+
Request okhttpRequest = _requestBuilder.build();
59+
OkHttpClient client = clientOptions.httpClient();
60+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
61+
client = clientOptions.httpClientWithTimeout(requestOptions);
62+
}
63+
CompletableFuture<BaseClientHttpResponse<Void>> future = new CompletableFuture<>();
64+
client.newCall(okhttpRequest).enqueue(new Callback() {
65+
@Override
66+
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
67+
try (ResponseBody responseBody = response.body()) {
68+
if (response.isSuccessful()) {
69+
future.complete(new BaseClientHttpResponse<>(null, response));
70+
return;
71+
}
72+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
73+
try {
74+
if (response.code() == 429) {
75+
future.completeExceptionally(new TooManyRequestsError(
76+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response));
77+
return;
78+
}
79+
} catch (JsonProcessingException ignored) {
80+
// unable to map error response, throwing generic error
81+
}
82+
future.completeExceptionally(new BaseClientApiException(
83+
"Error with status code " + response.code(),
84+
response.code(),
85+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
86+
response));
87+
return;
88+
} catch (IOException e) {
89+
future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e));
90+
}
91+
}
92+
93+
@Override
94+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
95+
future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e));
96+
}
97+
});
98+
return future;
99+
}
100+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.pipedream.api.resources.filestash;
5+
6+
import com.pipedream.api.core.ClientOptions;
7+
import com.pipedream.api.core.RequestOptions;
8+
import com.pipedream.api.resources.filestash.requests.FileStashDownloadFileRequest;
9+
10+
public class FileStashClient {
11+
protected final ClientOptions clientOptions;
12+
13+
private final RawFileStashClient rawClient;
14+
15+
public FileStashClient(ClientOptions clientOptions) {
16+
this.clientOptions = clientOptions;
17+
this.rawClient = new RawFileStashClient(clientOptions);
18+
}
19+
20+
/**
21+
* Get responses with HTTP metadata like headers
22+
*/
23+
public RawFileStashClient withRawResponse() {
24+
return this.rawClient;
25+
}
26+
27+
/**
28+
* Download a file from File Stash
29+
*/
30+
public void downloadFile(FileStashDownloadFileRequest request) {
31+
this.rawClient.downloadFile(request).body();
32+
}
33+
34+
/**
35+
* Download a file from File Stash
36+
*/
37+
public void downloadFile(FileStashDownloadFileRequest request, RequestOptions requestOptions) {
38+
this.rawClient.downloadFile(request, requestOptions).body();
39+
}
40+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
package com.pipedream.api.resources.filestash;
5+
6+
import com.fasterxml.jackson.core.JsonProcessingException;
7+
import com.pipedream.api.core.BaseClientApiException;
8+
import com.pipedream.api.core.BaseClientException;
9+
import com.pipedream.api.core.BaseClientHttpResponse;
10+
import com.pipedream.api.core.ClientOptions;
11+
import com.pipedream.api.core.ObjectMappers;
12+
import com.pipedream.api.core.QueryStringMapper;
13+
import com.pipedream.api.core.RequestOptions;
14+
import com.pipedream.api.errors.TooManyRequestsError;
15+
import com.pipedream.api.resources.filestash.requests.FileStashDownloadFileRequest;
16+
import java.io.IOException;
17+
import okhttp3.Headers;
18+
import okhttp3.HttpUrl;
19+
import okhttp3.OkHttpClient;
20+
import okhttp3.Request;
21+
import okhttp3.Response;
22+
import okhttp3.ResponseBody;
23+
24+
public class RawFileStashClient {
25+
protected final ClientOptions clientOptions;
26+
27+
public RawFileStashClient(ClientOptions clientOptions) {
28+
this.clientOptions = clientOptions;
29+
}
30+
31+
/**
32+
* Download a file from File Stash
33+
*/
34+
public BaseClientHttpResponse<Void> downloadFile(FileStashDownloadFileRequest request) {
35+
return downloadFile(request, null);
36+
}
37+
38+
/**
39+
* Download a file from File Stash
40+
*/
41+
public BaseClientHttpResponse<Void> downloadFile(
42+
FileStashDownloadFileRequest request, RequestOptions requestOptions) {
43+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
44+
.newBuilder()
45+
.addPathSegments("v1/connect")
46+
.addPathSegment(clientOptions.projectId())
47+
.addPathSegments("file_stash/download");
48+
QueryStringMapper.addQueryParameter(httpUrl, "s3_key", request.getS3Key(), false);
49+
Request.Builder _requestBuilder = new Request.Builder()
50+
.url(httpUrl.build())
51+
.method("GET", null)
52+
.headers(Headers.of(clientOptions.headers(requestOptions)))
53+
.addHeader("Accept", "application/json");
54+
Request okhttpRequest = _requestBuilder.build();
55+
OkHttpClient client = clientOptions.httpClient();
56+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
57+
client = clientOptions.httpClientWithTimeout(requestOptions);
58+
}
59+
try (Response response = client.newCall(okhttpRequest).execute()) {
60+
ResponseBody responseBody = response.body();
61+
if (response.isSuccessful()) {
62+
return new BaseClientHttpResponse<>(null, response);
63+
}
64+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
65+
try {
66+
if (response.code() == 429) {
67+
throw new TooManyRequestsError(
68+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response);
69+
}
70+
} catch (JsonProcessingException ignored) {
71+
// unable to map error response, throwing generic error
72+
}
73+
throw new BaseClientApiException(
74+
"Error with status code " + response.code(),
75+
response.code(),
76+
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class),
77+
response);
78+
} catch (IOException e) {
79+
throw new BaseClientException("Network error executing HTTP request", e);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)