Skip to content

Commit d9e1f30

Browse files
Add Connect Usage API and token scope (#215)
* Add a new usage resource with a list method to retrieve Connect usage records for a given time window. * `CreateTokenOpts` now supports: - `expiresIn`: set a custom TTL in seconds (max 4 hours) - `scope`: restrict token permissions with space-separated scopes (defaults to `connect:*`)
1 parent 01f7891 commit d9e1f30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1002
-62
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Add the dependency in your `pom.xml` file:
4040
<dependency>
4141
<groupId>com.pipedream</groupId>
4242
<artifactId>pipedream</artifactId>
43-
<version>1.1.5</version>
43+
<version>1.1.6</version>
4444
</dependency>
4545
```
4646

@@ -119,7 +119,7 @@ try{
119119

120120
### Custom Client
121121

122-
This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one.
122+
This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one.
123123
However, you can pass your own client like so:
124124

125125
```java

build.gradle

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

5050
group = 'com.pipedream'
5151

52-
version = '1.1.5'
52+
version = '1.1.6'
5353

5454
jar {
5555
dependsOn(":generatePomFileForMavenPublication")
@@ -80,7 +80,7 @@ publishing {
8080
maven(MavenPublication) {
8181
groupId = 'com.pipedream'
8282
artifactId = 'pipedream'
83-
version = '1.1.5'
83+
version = '1.1.6'
8484
from components.java
8585
pom {
8686
name = 'pipedream'

src/main/java/com/pipedream/api/AsyncBaseClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.pipedream.api.resources.proxy.AsyncProxyClient;
1818
import com.pipedream.api.resources.tokens.AsyncTokensClient;
1919
import com.pipedream.api.resources.triggers.AsyncTriggersClient;
20+
import com.pipedream.api.resources.usage.AsyncUsageClient;
2021
import com.pipedream.api.resources.users.AsyncUsersClient;
2122
import java.util.function.Supplier;
2223

@@ -47,6 +48,8 @@ public class AsyncBaseClient {
4748

4849
protected final Supplier<AsyncTokensClient> tokensClient;
4950

51+
protected final Supplier<AsyncUsageClient> usageClient;
52+
5053
protected final Supplier<AsyncOauthTokensClient> oauthTokensClient;
5154

5255
public AsyncBaseClient(ClientOptions clientOptions) {
@@ -63,6 +66,7 @@ public AsyncBaseClient(ClientOptions clientOptions) {
6366
this.fileStashClient = Suppliers.memoize(() -> new AsyncFileStashClient(clientOptions));
6467
this.proxyClient = Suppliers.memoize(() -> new AsyncProxyClient(clientOptions));
6568
this.tokensClient = Suppliers.memoize(() -> new AsyncTokensClient(clientOptions));
69+
this.usageClient = Suppliers.memoize(() -> new AsyncUsageClient(clientOptions));
6670
this.oauthTokensClient = Suppliers.memoize(() -> new AsyncOauthTokensClient(clientOptions));
6771
}
6872

@@ -114,6 +118,10 @@ public AsyncTokensClient tokens() {
114118
return this.tokensClient.get();
115119
}
116120

121+
public AsyncUsageClient usage() {
122+
return this.usageClient.get();
123+
}
124+
117125
public AsyncOauthTokensClient oauthTokens() {
118126
return this.oauthTokensClient.get();
119127
}

src/main/java/com/pipedream/api/BaseClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.pipedream.api.resources.proxy.ProxyClient;
1818
import com.pipedream.api.resources.tokens.TokensClient;
1919
import com.pipedream.api.resources.triggers.TriggersClient;
20+
import com.pipedream.api.resources.usage.UsageClient;
2021
import com.pipedream.api.resources.users.UsersClient;
2122
import java.util.function.Supplier;
2223

@@ -47,6 +48,8 @@ public class BaseClient {
4748

4849
protected final Supplier<TokensClient> tokensClient;
4950

51+
protected final Supplier<UsageClient> usageClient;
52+
5053
protected final Supplier<OauthTokensClient> oauthTokensClient;
5154

5255
public BaseClient(ClientOptions clientOptions) {
@@ -63,6 +66,7 @@ public BaseClient(ClientOptions clientOptions) {
6366
this.fileStashClient = Suppliers.memoize(() -> new FileStashClient(clientOptions));
6467
this.proxyClient = Suppliers.memoize(() -> new ProxyClient(clientOptions));
6568
this.tokensClient = Suppliers.memoize(() -> new TokensClient(clientOptions));
69+
this.usageClient = Suppliers.memoize(() -> new UsageClient(clientOptions));
6670
this.oauthTokensClient = Suppliers.memoize(() -> new OauthTokensClient(clientOptions));
6771
}
6872

@@ -114,6 +118,10 @@ public TokensClient tokens() {
114118
return this.tokensClient.get();
115119
}
116120

121+
public UsageClient usage() {
122+
return this.usageClient.get();
123+
}
124+
117125
public OauthTokensClient oauthTokens() {
118126
return this.oauthTokensClient.get();
119127
}

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.1.5");
38+
put("User-Agent", "com.pipedream:pipedream/1.1.6");
3939
put("X-Fern-Language", "JAVA");
4040
put("X-Fern-SDK-Name", "com.pipedream.fern:api-sdk");
41-
put("X-Fern-SDK-Version", "1.1.5");
41+
put("X-Fern-SDK-Version", "1.1.6");
4242
}
4343
});
4444
this.headerSuppliers = headerSuppliers;

src/main/java/com/pipedream/api/resources/oauthtokens/requests/CreateOAuthTokenOpts.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String getClientSecret() {
5353
}
5454

5555
/**
56-
* @return Optional space-separated scopes for the access token. Defaults to '*'.
56+
* @return Optional space-separated scopes for the access token. Defaults to <code>*</code>.
5757
*/
5858
@JsonProperty("scope")
5959
public Optional<String> getScope() {
@@ -103,7 +103,7 @@ public interface _FinalStage {
103103
CreateOAuthTokenOpts build();
104104

105105
/**
106-
* <p>Optional space-separated scopes for the access token. Defaults to '*'.</p>
106+
* <p>Optional space-separated scopes for the access token. Defaults to <code>*</code>.</p>
107107
*/
108108
_FinalStage scope(Optional<String> scope);
109109

@@ -146,7 +146,7 @@ public _FinalStage clientSecret(@NotNull String clientSecret) {
146146
}
147147

148148
/**
149-
* <p>Optional space-separated scopes for the access token. Defaults to '*'.</p>
149+
* <p>Optional space-separated scopes for the access token. Defaults to <code>*</code>.</p>
150150
* @return Reference to {@code this} so that method calls can be chained together.
151151
*/
152152
@java.lang.Override
@@ -156,7 +156,7 @@ public _FinalStage scope(String scope) {
156156
}
157157

158158
/**
159-
* <p>Optional space-separated scopes for the access token. Defaults to '*'.</p>
159+
* <p>Optional space-separated scopes for the access token. Defaults to <code>*</code>.</p>
160160
*/
161161
@java.lang.Override
162162
@JsonSetter(value = "scope", nulls = Nulls.SKIP)

src/main/java/com/pipedream/api/resources/tokens/requests/CreateTokenOpts.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public final class CreateTokenOpts {
2626

2727
private final Optional<String> errorRedirectUri;
2828

29+
private final Optional<Integer> expiresIn;
30+
2931
private final String externalUserId;
3032

33+
private final Optional<String> scope;
34+
3135
private final Optional<String> successRedirectUri;
3236

3337
private final Optional<String> webhookUri;
@@ -37,13 +41,17 @@ public final class CreateTokenOpts {
3741
private CreateTokenOpts(
3842
Optional<List<String>> allowedOrigins,
3943
Optional<String> errorRedirectUri,
44+
Optional<Integer> expiresIn,
4045
String externalUserId,
46+
Optional<String> scope,
4147
Optional<String> successRedirectUri,
4248
Optional<String> webhookUri,
4349
Map<String, Object> additionalProperties) {
4450
this.allowedOrigins = allowedOrigins;
4551
this.errorRedirectUri = errorRedirectUri;
52+
this.expiresIn = expiresIn;
4653
this.externalUserId = externalUserId;
54+
this.scope = scope;
4755
this.successRedirectUri = successRedirectUri;
4856
this.webhookUri = webhookUri;
4957
this.additionalProperties = additionalProperties;
@@ -65,6 +73,14 @@ public Optional<String> getErrorRedirectUri() {
6573
return errorRedirectUri;
6674
}
6775

76+
/**
77+
* @return Token TTL in seconds (max 14400 = 4 hours). Defaults to 4 hours if not specified.
78+
*/
79+
@JsonProperty("expires_in")
80+
public Optional<Integer> getExpiresIn() {
81+
return expiresIn;
82+
}
83+
6884
/**
6985
* @return Your end user ID, for whom you're creating the token
7086
*/
@@ -73,6 +89,14 @@ public String getExternalUserId() {
7389
return externalUserId;
7490
}
7591

92+
/**
93+
* @return Space-separated scopes to restrict token permissions. Defaults to 'connect:*' if not specified. See https://pipedream.com/docs/connect/api-reference/authentication#connect-token-scopes for more information.
94+
*/
95+
@JsonProperty("scope")
96+
public Optional<String> getScope() {
97+
return scope;
98+
}
99+
76100
/**
77101
* @return URI to redirect to on success
78102
*/
@@ -103,7 +127,9 @@ public Map<String, Object> getAdditionalProperties() {
103127
private boolean equalTo(CreateTokenOpts other) {
104128
return allowedOrigins.equals(other.allowedOrigins)
105129
&& errorRedirectUri.equals(other.errorRedirectUri)
130+
&& expiresIn.equals(other.expiresIn)
106131
&& externalUserId.equals(other.externalUserId)
132+
&& scope.equals(other.scope)
107133
&& successRedirectUri.equals(other.successRedirectUri)
108134
&& webhookUri.equals(other.webhookUri);
109135
}
@@ -113,7 +139,9 @@ public int hashCode() {
113139
return Objects.hash(
114140
this.allowedOrigins,
115141
this.errorRedirectUri,
142+
this.expiresIn,
116143
this.externalUserId,
144+
this.scope,
117145
this.successRedirectUri,
118146
this.webhookUri);
119147
}
@@ -153,6 +181,20 @@ public interface _FinalStage {
153181

154182
_FinalStage errorRedirectUri(String errorRedirectUri);
155183

184+
/**
185+
* <p>Token TTL in seconds (max 14400 = 4 hours). Defaults to 4 hours if not specified.</p>
186+
*/
187+
_FinalStage expiresIn(Optional<Integer> expiresIn);
188+
189+
_FinalStage expiresIn(Integer expiresIn);
190+
191+
/**
192+
* <p>Space-separated scopes to restrict token permissions. Defaults to 'connect:*' if not specified. See https://pipedream.com/docs/connect/api-reference/authentication#connect-token-scopes for more information.</p>
193+
*/
194+
_FinalStage scope(Optional<String> scope);
195+
196+
_FinalStage scope(String scope);
197+
156198
/**
157199
* <p>URI to redirect to on success</p>
158200
*/
@@ -176,6 +218,10 @@ public static final class Builder implements ExternalUserIdStage, _FinalStage {
176218

177219
private Optional<String> successRedirectUri = Optional.empty();
178220

221+
private Optional<String> scope = Optional.empty();
222+
223+
private Optional<Integer> expiresIn = Optional.empty();
224+
179225
private Optional<String> errorRedirectUri = Optional.empty();
180226

181227
private Optional<List<String>> allowedOrigins = Optional.empty();
@@ -189,7 +235,9 @@ private Builder() {}
189235
public Builder from(CreateTokenOpts other) {
190236
allowedOrigins(other.getAllowedOrigins());
191237
errorRedirectUri(other.getErrorRedirectUri());
238+
expiresIn(other.getExpiresIn());
192239
externalUserId(other.getExternalUserId());
240+
scope(other.getScope());
193241
successRedirectUri(other.getSuccessRedirectUri());
194242
webhookUri(other.getWebhookUri());
195243
return this;
@@ -247,6 +295,46 @@ public _FinalStage successRedirectUri(Optional<String> successRedirectUri) {
247295
return this;
248296
}
249297

298+
/**
299+
* <p>Space-separated scopes to restrict token permissions. Defaults to 'connect:*' if not specified. See https://pipedream.com/docs/connect/api-reference/authentication#connect-token-scopes for more information.</p>
300+
* @return Reference to {@code this} so that method calls can be chained together.
301+
*/
302+
@java.lang.Override
303+
public _FinalStage scope(String scope) {
304+
this.scope = Optional.ofNullable(scope);
305+
return this;
306+
}
307+
308+
/**
309+
* <p>Space-separated scopes to restrict token permissions. Defaults to 'connect:*' if not specified. See https://pipedream.com/docs/connect/api-reference/authentication#connect-token-scopes for more information.</p>
310+
*/
311+
@java.lang.Override
312+
@JsonSetter(value = "scope", nulls = Nulls.SKIP)
313+
public _FinalStage scope(Optional<String> scope) {
314+
this.scope = scope;
315+
return this;
316+
}
317+
318+
/**
319+
* <p>Token TTL in seconds (max 14400 = 4 hours). Defaults to 4 hours if not specified.</p>
320+
* @return Reference to {@code this} so that method calls can be chained together.
321+
*/
322+
@java.lang.Override
323+
public _FinalStage expiresIn(Integer expiresIn) {
324+
this.expiresIn = Optional.ofNullable(expiresIn);
325+
return this;
326+
}
327+
328+
/**
329+
* <p>Token TTL in seconds (max 14400 = 4 hours). Defaults to 4 hours if not specified.</p>
330+
*/
331+
@java.lang.Override
332+
@JsonSetter(value = "expires_in", nulls = Nulls.SKIP)
333+
public _FinalStage expiresIn(Optional<Integer> expiresIn) {
334+
this.expiresIn = expiresIn;
335+
return this;
336+
}
337+
250338
/**
251339
* <p>URI to redirect to on error</p>
252340
* @return Reference to {@code this} so that method calls can be chained together.
@@ -292,7 +380,9 @@ public CreateTokenOpts build() {
292380
return new CreateTokenOpts(
293381
allowedOrigins,
294382
errorRedirectUri,
383+
expiresIn,
295384
externalUserId,
385+
scope,
296386
successRedirectUri,
297387
webhookUri,
298388
additionalProperties);

0 commit comments

Comments
 (0)