Skip to content

Commit a06cb2c

Browse files
committed
Restore Pipedream client files
1 parent e0e36fc commit a06cb2c

File tree

5 files changed

+172
-0
lines changed

5 files changed

+172
-0
lines changed

.fernignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ src/main/java/com/pipedream/api/AsyncBaseClientBuilder.java
1414
src/main/java/com/pipedream/api/BaseClientBuilder.java
1515

1616
# Custom Pipedream client files
17+
src/main/java/com/pipedream/api/AsyncPipedreamClient.java
18+
src/main/java/com/pipedream/api/AsyncPipedreamClientBuilder.java
19+
src/main/java/com/pipedream/api/PipedreamClient.java
20+
src/main/java/com/pipedream/api/PipedreamClientBuilder.java
1721

1822
# Custom Proxy files
1923

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.pipedream.api;
2+
3+
import com.pipedream.api.core.ClientOptions;
4+
import com.pipedream.api.core.Environment;
5+
import com.pipedream.api.core.Suppliers;
6+
import com.pipedream.api.resources.workflows.WorkflowsClient;
7+
import java.util.Optional;
8+
import java.util.function.Supplier;
9+
10+
public class AsyncPipedreamClient extends AsyncBaseClient {
11+
private final Supplier<WorkflowsClient> workflowsClient;
12+
13+
public AsyncPipedreamClient(final ClientOptions clientOptions) {
14+
super(clientOptions);
15+
this.workflowsClient = Suppliers.memoize(() -> new WorkflowsClient(clientOptions));
16+
}
17+
18+
public static AsyncPipedreamClientBuilder builder() {
19+
return new AsyncPipedreamClientBuilder()
20+
.clientId(System.getenv("PIPEDREAM_CLIENT_ID"))
21+
.clientSecret(System.getenv("PIPEDREAM_CLIENT_SECRET"))
22+
.environment(Environment.PROD)
23+
.projectEnvironment(System.getenv("PIPEDREAM_PROJECT_ENVIRONMENT"))
24+
.projectId(System.getenv("PIPEDREAM_PROJECT_ID"));
25+
}
26+
27+
/**
28+
* Returns an access token that can be used to authenticate API requests
29+
*
30+
* @return the access token string (if available)
31+
*/
32+
public Optional<String> rawAccessToken() {
33+
final String authorizationHeader = this.clientOptions.headers(null).get("Authorization");
34+
35+
// The header might not be defined, so we wrap it as an Optional to
36+
// further process it. The processing consists of removing the `Bearer`
37+
// or `Basic` prefix from the header value.
38+
return Optional.ofNullable(authorizationHeader).map(h -> h.replaceFirst("^.*?\\s+", ""));
39+
}
40+
41+
public WorkflowsClient workflows() {
42+
return this.workflowsClient.get();
43+
}
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.pipedream.api;
2+
3+
import com.pipedream.api.core.ClientOptions;
4+
import com.pipedream.api.core.Environment;
5+
import org.apache.commons.text.StringSubstitutor;
6+
import org.apache.commons.text.lookup.StringLookupFactory;
7+
8+
/**
9+
* Builder for creating AsyncPipedreamClient instances.
10+
*/
11+
public final class AsyncPipedreamClientBuilder extends AsyncBaseClientBuilder<AsyncPipedreamClientBuilder> {
12+
private String projectId;
13+
14+
public AsyncPipedreamClient build() {
15+
return new AsyncPipedreamClient(buildClientOptions());
16+
}
17+
18+
public AsyncPipedreamClientBuilder environment(final Environment environment) {
19+
final String patchedUrl = patchUrl(environment.getUrl());
20+
final Environment withPatchedUrl = Environment.custom(patchedUrl);
21+
super.environment(withPatchedUrl);
22+
return this;
23+
}
24+
25+
public AsyncPipedreamClientBuilder projectId(final String projectId) {
26+
this.projectId = projectId;
27+
return this;
28+
}
29+
30+
@Override
31+
public void setVariables(ClientOptions.Builder builder) {
32+
builder.projectId(this.projectId);
33+
}
34+
35+
private static String patchUrl(final String templateUrl) {
36+
StringSubstitutor sub = new StringSubstitutor(StringLookupFactory.INSTANCE.environmentVariableStringLookup());
37+
38+
return sub.replace(templateUrl);
39+
}
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.pipedream.api;
2+
3+
import com.pipedream.api.core.ClientOptions;
4+
import com.pipedream.api.core.Environment;
5+
import com.pipedream.api.core.Suppliers;
6+
import com.pipedream.api.resources.workflows.WorkflowsClient;
7+
import java.util.Optional;
8+
import java.util.function.Supplier;
9+
10+
public class PipedreamClient extends BaseClient {
11+
private final Supplier<WorkflowsClient> workflowsClient;
12+
13+
public PipedreamClient(final ClientOptions clientOptions) {
14+
super(clientOptions);
15+
this.workflowsClient = Suppliers.memoize(() -> new WorkflowsClient(clientOptions));
16+
}
17+
18+
public static PipedreamClientBuilder builder() {
19+
return new PipedreamClientBuilder()
20+
.clientId(System.getenv("PIPEDREAM_CLIENT_ID"))
21+
.clientSecret(System.getenv("PIPEDREAM_CLIENT_SECRET"))
22+
.environment(Environment.PROD)
23+
.projectEnvironment(System.getenv("PIPEDREAM_PROJECT_ENVIRONMENT"))
24+
.projectId(System.getenv("PIPEDREAM_PROJECT_ID"));
25+
}
26+
27+
/**
28+
* Returns an access token that can be used to authenticate API requests
29+
*
30+
* @return the access token string (if available)
31+
*/
32+
public Optional<String> rawAccessToken() {
33+
final String authorizationHeader = this.clientOptions.headers(null).get("Authorization");
34+
35+
// The header might not be defined, so we wrap it as an Optional to
36+
// further process it. The processing consists of removing the `Bearer`
37+
// or `Basic` prefix from the header value.
38+
return Optional.ofNullable(authorizationHeader).map(h -> h.replaceFirst("^.*?\\s+", ""));
39+
}
40+
41+
public WorkflowsClient workflows() {
42+
return this.workflowsClient.get();
43+
}
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.pipedream.api;
2+
3+
import com.pipedream.api.core.ClientOptions;
4+
import com.pipedream.api.core.Environment;
5+
import org.apache.commons.text.StringSubstitutor;
6+
import org.apache.commons.text.lookup.StringLookupFactory;
7+
8+
/**
9+
* Builder for creating PipedreamClient instances.
10+
*/
11+
public final class PipedreamClientBuilder extends BaseClientBuilder<PipedreamClientBuilder> {
12+
private String projectId;
13+
14+
public PipedreamClient build() {
15+
return new PipedreamClient(buildClientOptions());
16+
}
17+
18+
public PipedreamClientBuilder environment(final Environment environment) {
19+
final String patchedUrl = patchUrl(environment.getUrl());
20+
final Environment withPatchedUrl = Environment.custom(patchedUrl);
21+
super.environment(withPatchedUrl);
22+
return this;
23+
}
24+
25+
public PipedreamClientBuilder projectId(final String projectId) {
26+
this.projectId = projectId;
27+
return this;
28+
}
29+
30+
@Override
31+
public void setVariables(ClientOptions.Builder builder) {
32+
builder.projectId(this.projectId);
33+
}
34+
35+
private static String patchUrl(final String templateUrl) {
36+
StringSubstitutor sub = new StringSubstitutor(StringLookupFactory.INSTANCE.environmentVariableStringLookup());
37+
38+
return sub.replace(templateUrl);
39+
}
40+
}

0 commit comments

Comments
 (0)