Skip to content
Merged
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
16 changes: 16 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,25 @@ LICENSE
reference.md

# Base client files (temporary)
src/main/java/com/pipedream/api/AsyncBaseClientBuilder.java
src/main/java/com/pipedream/api/BaseClientBuilder.java

# Custom Pipedream client files
src/main/java/com/pipedream/api/AsyncPipedreamClient.java
src/main/java/com/pipedream/api/AsyncPipedreamClientBuilder.java
src/main/java/com/pipedream/api/PipedreamClient.java
src/main/java/com/pipedream/api/PipedreamClientBuilder.java

# Custom Proxy files
src/main/java/com/pipedream/api/resources/proxy/AsyncProxyClient.java
src/main/java/com/pipedream/api/resources/proxy/ProxyClient.java

# Custom Workflow files
src/main/java/com/pipedream/api/resources/workflows/AsyncWorkflowsClient.java
src/main/java/com/pipedream/api/resources/workflows/requests/InvokeWorkflowOpts.java
src/main/java/com/pipedream/api/resources/workflows/requests/InvokeWorkflowForExternalUserOpts.java
src/main/java/com/pipedream/api/resources/workflows/AsyncRawWorkflowsClient.java
src/main/java/com/pipedream/api/resources/workflows/WorkflowsClient.java
src/main/java/com/pipedream/api/resources/workflows/RawWorkflowsClient.java
src/main/java/com/pipedream/api/resources/workflows/package-info.java
src/main/java/com/pipedream/api/types/HTTPAuthType.java
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
53 changes: 45 additions & 8 deletions src/main/java/com/pipedream/api/AsyncBaseClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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;

Expand All @@ -15,6 +17,8 @@ public class AsyncBaseClientBuilder<T extends AsyncBaseClientBuilder<T>> {

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,6 +29,8 @@ public class AsyncBaseClientBuilder<T extends AsyncBaseClientBuilder<T>> {

private OkHttpClient httpClient;

private String projectId;

/**
* Sets clientId.
* Defaults to the PIPEDREAM_CLIENT_ID environment variable.
Expand Down Expand Up @@ -93,6 +99,26 @@ public T httpClient(OkHttpClient httpClient) {
return (T) 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
*/
@SuppressWarnings("unchecked")
public T addHeader(String name, String value) {
this.customHeaders.put(name, value);
return (T) this;
}

@SuppressWarnings("unchecked")
public T projectId(String projectId) {
this.projectId = projectId;
return (T) this;
}

protected ClientOptions buildClientOptions() {
ClientOptions.Builder builder = ClientOptions.builder();
setEnvironment(builder);
Expand All @@ -102,6 +128,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 +153,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 +162,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 +182,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 +201,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 +252,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 +268,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
8 changes: 8 additions & 0 deletions src/main/java/com/pipedream/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.pipedream.api.resources.apps.AppsClient;
import com.pipedream.api.resources.components.ComponentsClient;
import com.pipedream.api.resources.deployedtriggers.DeployedTriggersClient;
import com.pipedream.api.resources.filestash.FileStashClient;
import com.pipedream.api.resources.oauthtokens.OauthTokensClient;
import com.pipedream.api.resources.projects.ProjectsClient;
import com.pipedream.api.resources.proxy.ProxyClient;
Expand Down Expand Up @@ -40,6 +41,8 @@ public class BaseClient {

protected final Supplier<ProjectsClient> projectsClient;

protected final Supplier<FileStashClient> fileStashClient;

protected final Supplier<ProxyClient> proxyClient;

protected final Supplier<TokensClient> tokensClient;
Expand All @@ -57,6 +60,7 @@ public BaseClient(ClientOptions clientOptions) {
this.triggersClient = Suppliers.memoize(() -> new TriggersClient(clientOptions));
this.deployedTriggersClient = Suppliers.memoize(() -> new DeployedTriggersClient(clientOptions));
this.projectsClient = Suppliers.memoize(() -> new ProjectsClient(clientOptions));
this.fileStashClient = Suppliers.memoize(() -> new FileStashClient(clientOptions));
this.proxyClient = Suppliers.memoize(() -> new ProxyClient(clientOptions));
this.tokensClient = Suppliers.memoize(() -> new TokensClient(clientOptions));
this.oauthTokensClient = Suppliers.memoize(() -> new OauthTokensClient(clientOptions));
Expand Down Expand Up @@ -98,6 +102,10 @@ public ProjectsClient projects() {
return this.projectsClient.get();
}

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

public ProxyClient proxy() {
return this.proxyClient.get();
}
Expand Down
Loading