diff --git a/README.md b/README.md index 88fd451..ffb8612 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,166 @@ Response> tagsResponse = assetService.getTags().blockingSingle(); // Get media (request with query) Response> mediaResponse = assetService.getMediaList(new MediaQuery().setType(MediaType.IMAGE).setLimit(100).setPage(1)).blockingSingle(); ``` + +### Sample Files Functionality Testing + +Classes within `sample` contain code to execute corresponding functionalities. The purpose is to demonstrate how methods +are called and provide a convenient method to execute functions. + +Within `src/main/resources` create an `app.properties` file. This file will be referenced from sample files. + +Make sure all values are populated correctly before running sample files. + +Example `app.properties` file content: + +```java +# permanent token if using permanent token auth +PERMANENT_TOKEN= +# portal url +BASE_URL=https://portal.bynder.com +# OAuth info +REDIRECT_URI=https://google.com +CLIENT_ID= +CLIENT_SECRET= +# media id for info +MEDIA_ID_FOR_INFO=5B8357A7-5DEB-4BC7-9CFBDEE1ECE120A9 +# media id for renaming +MEDIA_ID_FOR_RENAME=5B8357A7-5DEB-4BC7-9CFBDEE1ECE120A9 +# media id for removal +MEDIA_ID_FOR_REMOVAL=946A1800-6298-4201-AEB8F2830B07400E +# collection id to get info for +GET_COLLECTION_INFO_ID=615F03BB-D986-4786-B2C085D2F0718230 +# collection id to share +SHARE_COLLECTION_ID=615F03BB-D986-4786-B2C085D2F0718230 +# recipient to receive shared collection +COLLECTION_SHARE_RECIPIENT=recipient@mail.com +# media id to add to collection +ADD_MEDIA_TO_COLLECTION_MEDIA_ID=C078E8EE-C13A-4DA5-86EC8D6F335364EB +# collection id for media to be added to +ADD_MEDIA_TO_COLLECTION_COLLECTION_ID=615F03BB-D986-4786-B2C085D2F0718230 +# collection id to remove asset from +REMOVE_FROM_COLLECTION_ID=615F03BB-D986-4786-B2C085D2F0718230 +# media id to remove from collection +REMOVE_MEDIA_ID_FROM_COLLECTION=C078E8EE-C13A-4DA5-86EC8D6F335364EB +# media id used for creating asset usage +MEDIA_ID_FOR_ASSET_USAGE=C078E8EE-C13A-4DA5-86EC8D6F335364EB +# integration id used for asset usage +INTEGRATION_ID_FOR_ASSET_USAGE=0191a303-9d99-433e-ada4-d244f37e1d7d +``` +Within each sample file, OAuth credentials are read in from `app.properties`. +This will prompt the browser to open to retrieve an access code and then redirected to the redirect URI. +Access code is then provided to terminal prompt to retrieve an access token for API calls afterward. + + +#### Maven + +Make sure `mvn` CLI is installed. + +From root directory, dependencies can be installed from `pom.xml` using command: +```bash +mvn clean install -Dgpg.skip -Dmaven.javadoc.skip +``` + +#### Brands Sample + +Execute `BrandsSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.BrandsSample +``` + +Methods Used: +* getBrands() + +#### Collections Sample + +Execute `CollectionsSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.CollectionsSample +``` + +Methods Used: +* getCollections(collectionQuery) +* getCollectionInfo(collectionInfoQuery) +* createCollection(createCollectionQuery) +* shareCollection(collectionShareQuery) +* addMediaToCollection(collectionAddMediaQuery) +* getCollectionMediaIds(addMediaCollectionInfoQuery) +* removeMediaFromCollection(collectionRemoveMediaQuery) + +#### Media Sample + +Execute `MediaSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.MediaSample +``` + +Methods Used: + +* getMediaList(mediaQuery) +* getMediaInfo(mediaInfoQuery) +* getMediaDownloadUrl(mediaDownloadQuery) +* modifyMedia(modifyQuery) +* getMediaInfo(mediaInfoQueryRename) +* deleteMedia(mediaDeleteQuery) +* getDerivatives() + +#### Metaproperties Sample + +Execute `MetapropertiesSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.MetapropertiesSample +``` + +Methods Used: +* getMetaproperties(metapropertyQuery) + +#### Smart Filters Sample + +Execute `SmartFiltersSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.SmartFiltersSample +``` + +Methods Used: +* getSmartfilters() +* smartFilter.getMetaproperties() +* smartFilter.getLabels() + +#### Tags Sample + +Execute `TagsSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.TagsSample +``` + +Methods Used: +* getTags() + +#### Upload Sample + +Execute `UploadSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.UploadSample +``` + +Methods Used: +* uploadFile(uploadQuery) + +#### Usage Sample + +Execute `UsageSample.java` file with command + +```bash +mvn compile exec:java -Dexec.mainClass=com.bynder.sdk.sample.UsageSample +``` +Methods Used: +* createUsage(usageCreateQuery) +* getUsage(usageQuery) +* deleteUsage(usageDeleteQuery) diff --git a/src/main/java/com/bynder/sdk/sample/BrandsSample.java b/src/main/java/com/bynder/sdk/sample/BrandsSample.java new file mode 100644 index 0000000..2015dd8 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/BrandsSample.java @@ -0,0 +1,78 @@ +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; + + +public class BrandsSample { + private static final Logger LOG = LoggerFactory.getLogger(BrandsSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // Call the API to request for brands + List brands = assetService.getBrands().blockingSingle().body(); + if (brands != null && !brands.isEmpty()) { + for (Brand brand : brands) { + LOG.info("Brand ID: " + brand.getId()); + LOG.info("Brand Name: " + brand.getName()); + LOG.info("Brand Description: " + brand.getDescription()); + } + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/CollectionsSample.java b/src/main/java/com/bynder/sdk/sample/CollectionsSample.java new file mode 100644 index 0000000..5d94c00 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/CollectionsSample.java @@ -0,0 +1,156 @@ +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CollectionsSample { + private static final Logger LOG = LoggerFactory.getLogger(CollectionsSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // get collections with limit + CollectionQuery collectionQuery = new CollectionQuery().setLimit(20); + List collections = collectionService.getCollections(collectionQuery).blockingSingle().body(); + if (collections != null && !collections.isEmpty()) { + for (Collection collectionResult : collections) { + LOG.info("Collection ID: " + collectionResult.getId()); + LOG.info("Collection Name: " + collectionResult.getName()); + LOG.info("Collection Description: " + collectionResult.getDescription()); + LOG.info("Collection Media Count: " + collectionResult.getMediaCount()); + LOG.info("Collection Date Created: " + collectionResult.getDateCreated()); + } + } + + // get collection info + String collectionInfoId = appProperties.getProperty("GET_COLLECTION_INFO_ID"); + CollectionInfoQuery collectionInfoQuery = new CollectionInfoQuery(collectionInfoId); + Collection collectionInfo = collectionService.getCollectionInfo(collectionInfoQuery).blockingSingle().body(); + if (collectionInfo != null) { + LOG.info("Collection Info Name: " + collectionInfo.getName()); + LOG.info("Collection Info Description: " + collectionInfo.getDescription()); + } + + // create collection + Random random = new Random(); + int randomInt = random.nextInt(100); + String newCollectionName = "New Collection" + randomInt; + LOG.info("new collection name: " + newCollectionName); + CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery(newCollectionName); + collectionService.createCollection(createCollectionQuery).blockingSingle(); + + // get collections with added collection + List updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body(); + if (updatedCollections != null && !updatedCollections.isEmpty()) { + for (Collection collectionResult : updatedCollections) { + LOG.info("Collection ID: " + collectionResult.getId()); + LOG.info("Collection Name: " + collectionResult.getName()); + LOG.info("Collection Description: " + collectionResult.getDescription()); + LOG.info("Collection Media Count: " + collectionResult.getMediaCount()); + LOG.info("Collection Date Created: " + collectionResult.getDateCreated()); + } + } + + // share collection to recipients + String shareCollectionId = appProperties.getProperty("SHARE_COLLECTION_ID"); + LOG.info("sharing collection id: " + shareCollectionId); + String collectionShareRecipient = appProperties.getProperty("COLLECTION_SHARE_RECIPIENT"); + String[] shareCollectionRecipients = new String[] {collectionShareRecipient}; + + // allow recipient to view, login required false, send email with message "test" + CollectionShareQuery collectionShareQuery = new CollectionShareQuery(shareCollectionId, shareCollectionRecipients, CollectionRecipientRight.VIEW) + .setLoginRequired(false) + .setSendMail(true) + .setMessage("test"); + collectionService.shareCollection(collectionShareQuery).blockingSingle(); + + // addMediaToCollection + String addMediaToCollectionId = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_COLLECTION_ID"); + String mediaIdToAdd = appProperties.getProperty("ADD_MEDIA_TO_COLLECTION_MEDIA_ID"); + String[] addMediaIds = new String[] {mediaIdToAdd}; + + LOG.info("adding media ids: " + mediaIdToAdd); + CollectionAddMediaQuery collectionAddMediaQuery = new CollectionAddMediaQuery(addMediaToCollectionId, addMediaIds); + collectionService.addMediaToCollection(collectionAddMediaQuery).blockingSingle(); + + + // get info about collection that had media added + CollectionInfoQuery addMediaCollectionInfoQuery = new CollectionInfoQuery(addMediaToCollectionId); + List mediaIdsFromCollection = collectionService.getCollectionMediaIds(addMediaCollectionInfoQuery).blockingSingle().body(); + if (mediaIdsFromCollection != null && !mediaIdsFromCollection.isEmpty()) { + for (String mediaId : mediaIdsFromCollection) { + LOG.info("media id: " + mediaId); + } + } + + // removeMediaFromCollection + String removeFromCollectionId = appProperties.getProperty("REMOVE_FROM_COLLECTION_ID"); + String mediaIdToRemove = appProperties.getProperty("REMOVE_MEDIA_ID_FROM_COLLECTION"); + String[] removeMediaIds = new String[] {mediaIdToRemove}; + LOG.info("removing media ids: " + mediaIdToRemove); + CollectionRemoveMediaQuery collectionRemoveMediaQuery = new CollectionRemoveMediaQuery(removeFromCollectionId, removeMediaIds); + collectionService.removeMediaFromCollection(collectionRemoveMediaQuery); + + // get updated media ids from collection after removal + CollectionInfoQuery removeMediaCollectionInfoQuery = new CollectionInfoQuery(removeFromCollectionId); + List mediaIdsFromCollectionAfterRemoval = collectionService.getCollectionMediaIds(removeMediaCollectionInfoQuery).blockingSingle().body(); + if (mediaIdsFromCollectionAfterRemoval != null && !mediaIdsFromCollectionAfterRemoval.isEmpty()) { + for (String mediaId : mediaIdsFromCollectionAfterRemoval) { + LOG.info("media id: " + mediaId); + } + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/MediaSample.java b/src/main/java/com/bynder/sdk/sample/MediaSample.java new file mode 100644 index 0000000..b11ae73 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/MediaSample.java @@ -0,0 +1,131 @@ +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.Derivative; +import com.bynder.sdk.model.DownloadUrl; +import com.bynder.sdk.model.Media; +import com.bynder.sdk.model.MediaType; + +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; + +public class MediaSample { + private static final Logger LOG = LoggerFactory.getLogger(MediaSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // get derivatives + List derivatives = client.getDerivatives().blockingSingle().body(); + if (derivatives != null && !derivatives.isEmpty()) { + for (Derivative derivative : derivatives) { + LOG.info("Derivative Prefix: " + derivative.getPrefix()); + } + } + + // Call the API to request for media assets + MediaQuery mediaQuery = new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1); + List mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body(); + if (mediaList != null && !mediaList.isEmpty()) { + for (Media media : mediaList) { + LOG.info("Media ID: " + media.getId()); + LOG.info("Media Name: " + media.getName()); + } + } + + // get media info for single asset + String mediaIdInfo = appProperties.getProperty("MEDIA_ID_FOR_INFO"); + MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaIdInfo); + Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body(); + if (foundMedia != null) { + LOG.info("get media info result: "); + LOG.info("Media ID: " + foundMedia.getId()); + LOG.info("Media Name: " + foundMedia.getName()); + 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) + .setName("New Name Updated") + .setDescription("Test Updated Description"); + assetService.modifyMedia(modifyQuery).blockingSingle(); + + MediaInfoQuery mediaInfoQueryRename = new MediaInfoQuery(mediaIdForRename); + Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQueryRename).blockingSingle().body(); + if (updatedFoundMedia != null) { + LOG.info("get updated media info result: "); + LOG.info(updatedFoundMedia.getId()); + LOG.info(updatedFoundMedia.getName()); + LOG.info(updatedFoundMedia.getDescription()); + } + + // remove media + String mediaToRemove = appProperties.getProperty("MEDIA_ID_FOR_REMOVAL"); + MediaDeleteQuery mediaDeleteQuery = new MediaDeleteQuery(mediaToRemove); + LOG.info("Removing media id: " + mediaToRemove); + assetService.deleteMedia(mediaDeleteQuery).blockingSingle(); + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/MetapropertiesSample.java b/src/main/java/com/bynder/sdk/sample/MetapropertiesSample.java new file mode 100644 index 0000000..257b859 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/MetapropertiesSample.java @@ -0,0 +1,92 @@ +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; + +public class MetapropertiesSample { + private static final Logger LOG = LoggerFactory.getLogger(MetapropertiesSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // get metaproperties + MetapropertyQuery metapropertyQuery = new MetapropertyQuery(); + + Map metapropertiesMap = assetService.getMetaproperties(metapropertyQuery).blockingSingle().body(); + + if (metapropertiesMap != null) { + for (Map.Entry metapropertyEntry : metapropertiesMap.entrySet()) { + LOG.info("current metaproperty"); + LOG.info("Key: " + metapropertyEntry.getKey()); + Metaproperty currentMetaproperty = metapropertyEntry.getValue(); + + LOG.info("ID: " + currentMetaproperty.getId()); + LOG.info("Name: " + currentMetaproperty.getName()); + LOG.info("Label: " + currentMetaproperty.getLabel()); + LOG.info("Type: " + currentMetaproperty.getType()); + List metapropertyOptionList = currentMetaproperty.getOptions(); + + // metaproperty options if found + if (metapropertyOptionList != null && !metapropertyOptionList.isEmpty()) { + for (MetapropertyOption metapropertyOption : metapropertyOptionList) { + LOG.info("Metaproperty Option ID: " + metapropertyOption.getId()); + LOG.info("Metaproperty Option Label: " + metapropertyOption.getLabel()); + LOG.info("Metaproperty Name: " + metapropertyOption.getName()); + } + } + } + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java b/src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java new file mode 100644 index 0000000..c60294f --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java @@ -0,0 +1,86 @@ +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SmartFiltersSample { + private static final Logger LOG = LoggerFactory.getLogger(SmartFiltersSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + List smartFilters = assetService.getSmartfilters().blockingSingle().body(); + if (smartFilters != null && !smartFilters.isEmpty()) { + for (Smartfilter smartFilter : smartFilters) { + LOG.info("Smart Filter ID: " + smartFilter.getId()); + // smart filter metaproperties + List smartFilterMetaproperties = smartFilter.getMetaproperties(); + if (!smartFilterMetaproperties.isEmpty()) { + LOG.info("smart filter metaproperty ids:"); + for (String metaproperty : smartFilterMetaproperties) { + LOG.info("Smart Filter Metaproperty ID: " + metaproperty); + } + } + + // smart filter labels + Map smartFilterLabels = smartFilter.getLabels(); + for (Map.Entry entry : smartFilterLabels.entrySet()) { + LOG.info("smart filter label: " + entry.getKey() + " " + entry.getValue()); + } + } + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/TagsSample.java b/src/main/java/com/bynder/sdk/sample/TagsSample.java new file mode 100644 index 0000000..3e01163 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/TagsSample.java @@ -0,0 +1,74 @@ +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TagsSample { + private static final Logger LOG = LoggerFactory.getLogger(TagsSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // get tags and media count for each tag + List assetTags = assetService.getTags().blockingSingle().body(); + if (assetTags != null && !assetTags.isEmpty()) { + for (Tag assetTag : assetTags) { + LOG.info("Asset Tag ID: " + assetTag.getId()); + LOG.info("Asset Tag: " + assetTag.getTag()); + LOG.info("Asset Tag Media Count: " + assetTag.getMediaCount()); + } + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/UploadSample.java b/src/main/java/com/bynder/sdk/sample/UploadSample.java new file mode 100644 index 0000000..e23bf57 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/UploadSample.java @@ -0,0 +1,85 @@ +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.model.upload.SaveMediaResponse; +import com.bynder.sdk.query.upload.UploadQuery; +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UploadSample { + private static final Logger LOG = LoggerFactory.getLogger(UploadSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // Upload a file + // Call the API to request for brands + String brandId = ""; + List brands = assetService.getBrands().blockingSingle().body(); + if (brands != null && !brands.isEmpty()) { + brandId = brands.get(0).getId(); + } + + String filePath = "src/main/java/com/bynder/sdk/sample/testasset.png"; + LOG.info(filePath); + UploadQuery uploadQuery = new UploadQuery(filePath, brandId); + // Add the filename you want to specify in this manner + uploadQuery.setFileName("testasset.png"); + SaveMediaResponse saveMediaResponse = assetService.uploadFile(uploadQuery).blockingSingle(); + if (saveMediaResponse.getSuccess()) { + LOG.info("Asset Uploaded Successfully: " + saveMediaResponse.getMediaId()); + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/UsageSample.java b/src/main/java/com/bynder/sdk/sample/UsageSample.java new file mode 100644 index 0000000..1150692 --- /dev/null +++ b/src/main/java/com/bynder/sdk/sample/UsageSample.java @@ -0,0 +1,98 @@ +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.Usage; +import com.bynder.sdk.query.UsageCreateQuery; +import com.bynder.sdk.query.UsageDeleteQuery; +import com.bynder.sdk.query.UsageQuery; +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; +public class UsageSample { + private static final Logger LOG = LoggerFactory.getLogger(UsageSample.class); + + public static void main(final String[] args) throws URISyntaxException, IOException { + /** + * Loads app.properties file under src/main/resources + */ + Properties appProperties = Utils.loadConfig("app"); + + // 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"))) + .setOAuthSettings(oAuthSettings) + .setHttpConnectionSettings(new HttpConnectionSettings()).build()); + List 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(); + + // Initialize asset service + AssetService assetService = client.getAssetService(); + + // create usage + String mediaIdForAssetUsage = appProperties.getProperty("MEDIA_ID_FOR_ASSET_USAGE"); + String integrationIdForAssetUsage = appProperties.getProperty("INTEGRATION_ID_FOR_ASSET_USAGE"); + + UsageCreateQuery usageCreateQuery = new UsageCreateQuery(integrationIdForAssetUsage, mediaIdForAssetUsage); + Usage createdAssetUsage = assetService.createUsage(usageCreateQuery).blockingSingle().body(); + if (createdAssetUsage != null) { + LOG.info("Asset Usage ID: " + createdAssetUsage.getId()); + LOG.info("Asset Usage Asset ID: " + createdAssetUsage.getAssetId()); + } + + // get asset usages + UsageQuery usageQuery= new UsageQuery().setAssetId(mediaIdForAssetUsage); + List assetUsages = assetService.getUsage(usageQuery).blockingSingle().body(); + + if (assetUsages != null && !assetUsages.isEmpty()) { + String deleteAssetUsageId = ""; + for (Usage assetUsage : assetUsages) { + LOG.info("Asset Usage ID: " + assetUsage.getId()); + deleteAssetUsageId = assetUsage.getAssetId(); + LOG.info(assetUsage.getAssetId()); + } + + // delete asset usage + UsageDeleteQuery usageDeleteQuery = new UsageDeleteQuery(integrationIdForAssetUsage, deleteAssetUsageId); + LOG.info("Deleting asset usage id: " + deleteAssetUsageId); + assetService.deleteUsage(usageDeleteQuery); + } + System.exit(0); + } +} diff --git a/src/main/java/com/bynder/sdk/sample/testasset.png b/src/main/java/com/bynder/sdk/sample/testasset.png new file mode 100644 index 0000000..9da5cdd Binary files /dev/null and b/src/main/java/com/bynder/sdk/sample/testasset.png differ