Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add the dependency in your `pom.xml` file:
<dependency>
<groupId>com.pipedream</groupId>
<artifactId>pipedream</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</dependency>
```

Expand All @@ -45,10 +45,10 @@ public class Example {
.builder()
.clientId("<clientId>")
.clientSecret("<clientSecret>")
.projectId("YOUR_PROJECT_ID")
.build();

client.actions().run(
"project_id",
RunActionOpts
.builder()
.id("id")
Expand Down Expand Up @@ -93,9 +93,9 @@ When the API returns a non-success status code (4xx or 5xx response), an API exc
```java
import com.pipedream.api.core.PipedreamApiApiException;

try {
try{
client.actions().run(...);
} catch (PipedreamApiApiException e) {
} catch (PipedreamApiApiException e){
// Do something with the API exception...
}
```
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
api 'org.apache.commons:commons-text:1.13.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
}


Expand All @@ -48,7 +49,7 @@ java {

group = 'com.pipedream'

version = '1.0.5'
version = '1.0.6'

jar {
dependsOn(":generatePomFileForMavenPublication")
Expand Down Expand Up @@ -79,7 +80,7 @@ publishing {
maven(MavenPublication) {
groupId = 'com.pipedream'
artifactId = 'pipedream'
version = '1.0.5'
version = '1.0.6'
from components.java
pom {
name = 'pipedream'
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/pipedream/api/AsyncBaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.pipedream.api.resources.apps.AsyncAppsClient;
import com.pipedream.api.resources.components.AsyncComponentsClient;
import com.pipedream.api.resources.deployedtriggers.AsyncDeployedTriggersClient;
import com.pipedream.api.resources.filestash.AsyncFileStashClient;
import com.pipedream.api.resources.oauthtokens.AsyncOauthTokensClient;
import com.pipedream.api.resources.projects.AsyncProjectsClient;
import com.pipedream.api.resources.proxy.AsyncProxyClient;
Expand Down Expand Up @@ -40,6 +41,8 @@ public class AsyncBaseClient {

protected final Supplier<AsyncProjectsClient> projectsClient;

protected final Supplier<AsyncFileStashClient> fileStashClient;

protected final Supplier<AsyncProxyClient> proxyClient;

protected final Supplier<AsyncTokensClient> tokensClient;
Expand All @@ -57,6 +60,7 @@ public AsyncBaseClient(ClientOptions clientOptions) {
this.triggersClient = Suppliers.memoize(() -> new AsyncTriggersClient(clientOptions));
this.deployedTriggersClient = Suppliers.memoize(() -> new AsyncDeployedTriggersClient(clientOptions));
this.projectsClient = Suppliers.memoize(() -> new AsyncProjectsClient(clientOptions));
this.fileStashClient = Suppliers.memoize(() -> new AsyncFileStashClient(clientOptions));
this.proxyClient = Suppliers.memoize(() -> new AsyncProxyClient(clientOptions));
this.tokensClient = Suppliers.memoize(() -> new AsyncTokensClient(clientOptions));
this.oauthTokensClient = Suppliers.memoize(() -> new AsyncOauthTokensClient(clientOptions));
Expand Down Expand Up @@ -98,6 +102,10 @@ public AsyncProjectsClient projects() {
return this.projectsClient.get();
}

public AsyncFileStashClient fileStash() {
return this.fileStashClient.get();
}

public AsyncProxyClient proxy() {
return this.proxyClient.get();
}
Expand Down
93 changes: 60 additions & 33 deletions src/main/java/com/pipedream/api/AsyncBaseClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
import com.pipedream.api.core.Environment;
import com.pipedream.api.core.OAuthTokenSupplier;
import com.pipedream.api.resources.oauthtokens.OauthTokensClient;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import okhttp3.OkHttpClient;

public class AsyncBaseClientBuilder<T extends AsyncBaseClientBuilder<T>> {
public class AsyncBaseClientBuilder {
private Optional<Integer> timeout = Optional.empty();

private Optional<Integer> maxRetries = Optional.empty();

private final Map<String, String> customHeaders = new HashMap<>();

private String clientId = System.getenv("PIPEDREAM_CLIENT_ID");

private String clientSecret = System.getenv("PIPEDREAM_CLIENT_SECRET");
Expand All @@ -25,72 +29,84 @@ public class AsyncBaseClientBuilder<T extends AsyncBaseClientBuilder<T>> {

private OkHttpClient httpClient;

private String projectId;

/**
* Sets clientId.
* Defaults to the PIPEDREAM_CLIENT_ID environment variable.
*/
@SuppressWarnings("unchecked")
public T clientId(String clientId) {
public AsyncBaseClientBuilder clientId(String clientId) {
this.clientId = clientId;
return (T) this;
return this;
}

/**
* Sets clientSecret.
* Defaults to the PIPEDREAM_CLIENT_SECRET environment variable.
*/
@SuppressWarnings("unchecked")
public T clientSecret(String clientSecret) {
public AsyncBaseClientBuilder clientSecret(String clientSecret) {
this.clientSecret = clientSecret;
return (T) this;
return this;
}

/**
* Sets projectEnvironment
*/
@SuppressWarnings("unchecked")
public T projectEnvironment(String projectEnvironment) {
public AsyncBaseClientBuilder projectEnvironment(String projectEnvironment) {
this.projectEnvironment = projectEnvironment;
return (T) this;
return this;
}

@SuppressWarnings("unchecked")
public T environment(Environment environment) {
public AsyncBaseClientBuilder environment(Environment environment) {
this.environment = environment;
return (T) this;
return this;
}

@SuppressWarnings("unchecked")
public T url(String url) {
public AsyncBaseClientBuilder url(String url) {
this.environment = Environment.custom(url);
return (T) this;
return this;
}

/**
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
*/
@SuppressWarnings("unchecked")
public T timeout(int timeout) {
public AsyncBaseClientBuilder timeout(int timeout) {
this.timeout = Optional.of(timeout);
return (T) this;
return this;
}

/**
* Sets the maximum number of retries for the client. Defaults to 2 retries.
*/
@SuppressWarnings("unchecked")
public T maxRetries(int maxRetries) {
public AsyncBaseClientBuilder maxRetries(int maxRetries) {
this.maxRetries = Optional.of(maxRetries);
return (T) this;
return this;
}

/**
* Sets the underlying OkHttp client
*/
@SuppressWarnings("unchecked")
public T httpClient(OkHttpClient httpClient) {
public AsyncBaseClientBuilder httpClient(OkHttpClient httpClient) {
this.httpClient = httpClient;
return (T) this;
return this;
}

/**
* Add a custom header to be sent with all requests.
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
*
* @param name The header name
* @param value The header value
* @return This builder for method chaining
*/
public AsyncBaseClientBuilder addHeader(String name, String value) {
this.customHeaders.put(name, value);
return this;
}

public AsyncBaseClientBuilder projectId(String projectId) {
this.projectId = projectId;
return this;
}

protected ClientOptions buildClientOptions() {
Expand All @@ -102,6 +118,9 @@ protected ClientOptions buildClientOptions() {
setHttpClient(builder);
setTimeouts(builder);
setRetries(builder);
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
builder.addHeader(header.getKey(), header.getValue());
}
setAdditional(builder);
return builder.build();
}
Expand All @@ -124,7 +143,7 @@ protected void setEnvironment(ClientOptions.Builder builder) {
*
* Example:
* <pre>{@code
* @Override
* &#64;Override
* protected void setAuthentication(ClientOptions.Builder builder) {
* super.setAuthentication(builder); // Keep existing auth
* builder.addHeader("X-API-Key", this.apiKey);
Expand All @@ -133,8 +152,12 @@ protected void setEnvironment(ClientOptions.Builder builder) {
*/
protected void setAuthentication(ClientOptions.Builder builder) {
if (this.clientId != null && this.clientSecret != null) {
OauthTokensClient authClient = new OauthTokensClient(
ClientOptions.builder().environment(this.environment).build());
ClientOptions.Builder authClientOptionsBuilder =
ClientOptions.builder().environment(this.environment);
if (this.projectId != null) {
authClientOptionsBuilder.projectId(this.projectId);
}
OauthTokensClient authClient = new OauthTokensClient(authClientOptionsBuilder.build());
OAuthTokenSupplier oAuthTokenSupplier =
new OAuthTokenSupplier(this.clientId, this.clientSecret, authClient);
builder.addHeader("Authorization", oAuthTokenSupplier);
Expand All @@ -149,7 +172,7 @@ protected void setAuthentication(ClientOptions.Builder builder) {
*
* Example:
* <pre>{@code
* @Override
* &#64;Override
* protected void setCustomHeaders(ClientOptions.Builder builder) {
* super.setCustomHeaders(builder); // Keep existing headers
* builder.addHeader("X-Trace-ID", generateTraceId());
Expand All @@ -168,7 +191,11 @@ protected void setCustomHeaders(ClientOptions.Builder builder) {
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setVariables(ClientOptions.Builder builder) {}
protected void setVariables(ClientOptions.Builder builder) {
if (this.projectId != null) {
builder.projectId(this.projectId);
}
}

/**
* Sets the request timeout configuration.
Expand Down Expand Up @@ -215,9 +242,9 @@ protected void setHttpClient(ClientOptions.Builder builder) {
*
* Example:
* <pre>{@code
* @Override
* &#64;Override
* protected void setAdditional(ClientOptions.Builder builder) {
* builder.addHeader("X-Request-ID", () -> UUID.randomUUID().toString());
* builder.addHeader("X-Request-ID", () -&gt; UUID.randomUUID().toString());
* builder.addHeader("X-Client-Version", "1.0.0");
* }
* }</pre>
Expand All @@ -231,7 +258,7 @@ protected void setAdditional(ClientOptions.Builder builder) {}
*
* Example:
* <pre>{@code
* @Override
* &#64;Override
* protected void validateConfiguration() {
* super.validateConfiguration(); // Run parent validations
* if (tenantId == null || tenantId.isEmpty()) {
Expand Down
44 changes: 0 additions & 44 deletions src/main/java/com/pipedream/api/AsyncPipedreamClient.java

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/com/pipedream/api/AsyncPipedreamClientBuilder.java

This file was deleted.

Loading
Loading