Skip to content

Commit

Permalink
API-1822 use OAuth for client, add testasset image for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ahongbynder committed Dec 1, 2023
1 parent d1af2d2 commit 69d3aa1
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 32 deletions.
33 changes: 31 additions & 2 deletions src/main/java/com/bynder/sdk/sample/BrandsSample.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.Brand;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,10 +34,32 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
Properties appProperties = Utils.loadConfig("app");


// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

// Initialize asset service
AssetService assetService = client.getAssetService();
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/com/bynder/sdk/sample/CollectionsSample.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.Collection;
import com.bynder.sdk.query.collection.*;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.collection.CollectionService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.*;
import java.util.List;
import java.util.Properties;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,11 +31,32 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
*/
Properties appProperties = Utils.loadConfig("app");


// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

// Initialize collection service
CollectionService collectionService = client.getCollectionService();
Expand Down
47 changes: 41 additions & 6 deletions src/main/java/com/bynder/sdk/sample/MediaSample.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.DownloadUrl;
import com.bynder.sdk.model.Media;
import com.bynder.sdk.model.MediaType;

import com.bynder.sdk.query.MediaInfoQuery;
import com.bynder.sdk.query.MediaModifyQuery;
import com.bynder.sdk.query.MediaQuery;
import com.bynder.sdk.query.OrderBy;
import com.bynder.sdk.query.*;

import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,10 +37,32 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
*/
Properties appProperties = Utils.loadConfig("app");

// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

// Initialize asset service
AssetService assetService = client.getAssetService();
Expand All @@ -61,6 +88,14 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
LOG.info("Media Brand ID: " + foundMedia.getBrandId());
}

// get media download url
MediaDownloadQuery mediaDownloadQuery = new MediaDownloadQuery(mediaIdInfo);
DownloadUrl mediaDownloadUrl = assetService.getMediaDownloadUrl(mediaDownloadQuery).blockingSingle().body();
if (mediaDownloadUrl != null) {
LOG.info("Media S3 File: " + mediaDownloadUrl.getS3File().getFile());
LOG.info("Media S3 URI: " + mediaDownloadUrl.getS3File().toURI());
}

// modify name of asset
String mediaIdForRename = appProperties.getProperty("MEDIA_ID_FOR_RENAME");
MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaIdForRename)
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/com/bynder/sdk/sample/MetapropertiesSample.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.Metaproperty;
import com.bynder.sdk.model.MetapropertyOption;
import com.bynder.sdk.query.MetapropertyQuery;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class MetapropertiesSample {
private static final Logger LOG = LoggerFactory.getLogger(MetapropertiesSample.class);
Expand All @@ -26,11 +30,32 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
*/
Properties appProperties = Utils.loadConfig("app");

// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

// Initialize asset service
AssetService assetService = client.getAssetService();
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.Smartfilter;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;


import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,10 +31,32 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
*/
Properties appProperties = Utils.loadConfig("app");

// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

// Initialize asset service
AssetService assetService = client.getAssetService();
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/com/bynder/sdk/sample/TagsSample.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.configuration.HttpConnectionSettings;
import com.bynder.sdk.configuration.OAuthSettings;
import com.bynder.sdk.model.Tag;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.service.oauth.OAuthService;
import com.bynder.sdk.util.Utils;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -26,10 +30,33 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
*/
Properties appProperties = Utils.loadConfig("app");

// Initialize BynderClient with a permanent token
// Initialize BynderClient with OAuth
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());
.setOAuthSettings(oAuthSettings)
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
"meta.assetbank:write", "meta.workflow:read", "current.user:read", "current.profile:read",
"admin.profile:read", "admin.user:read", "admin.user:write", "analytics.api:read");

// Initialize OAuthService
OAuthService oauthService = client.getOAuthService();
URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);

// Open browser with authorization URL
Desktop desktop = Desktop.getDesktop();
desktop.browse(authorizationUrl.toURI());

// Ask for the code returned in the redirect URI
System.out.println("Insert the code: ");
Scanner scanner = new Scanner(System.in);
String code = scanner.nextLine();
scanner.close();

// Get the access token
oauthService.getAccessToken(code, scopes).blockingSingle();

AssetService assetService = client.getAssetService();

Expand Down
Loading

0 comments on commit 69d3aa1

Please sign in to comment.