Skip to content

Commit

Permalink
API-1822 setup sample files for java sdk api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ahongbynder committed Nov 27, 2023
1 parent 64acb65 commit 5a3e48d
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/com/bynder/sdk/sample/BrandsSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bynder.sdk.sample;

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

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.List;
import java.util.Properties;

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 a permanent token
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());

// Initialize asset service
AssetService assetService = client.getAssetService();

// Call the API to request for brands
List<Brand> brands = assetService.getBrands().blockingSingle().body();
for (Brand brand : brands) {
LOG.info(brand.getName());
LOG.info(brand.getDescription());
}
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/bynder/sdk/sample/CollectionsSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.model.Collection;
import com.bynder.sdk.service.BynderClient;
import com.bynder.sdk.service.collection.CollectionService;
import com.bynder.sdk.query.collection.CollectionQuery;
import com.bynder.sdk.query.collection.CollectionCreateQuery;
import com.bynder.sdk.util.Utils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

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

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 a permanent token
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());

// Initialize collection service
CollectionService collectionService = client.getCollectionService();

// get collections
CollectionQuery collectionQuery = new CollectionQuery();
List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
}

// add collection
CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery("New Collection 1234");
collectionService.createCollection(createCollectionQuery).blockingSingle();
//
List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
}
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/bynder/sdk/sample/MediaSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
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.service.BynderClient;
import com.bynder.sdk.service.asset.AssetService;
import com.bynder.sdk.util.Utils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import java.util.List;
import java.util.Properties;

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 a permanent token
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());

// Initialize asset service
AssetService assetService = client.getAssetService();

// Call the API to request for media assets
MediaQuery mediaQuery = new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
for (Media media : mediaList) {
LOG.info(media.getId());
LOG.info(media.getName());
}

if (!mediaList.isEmpty()) {
// get media info for single asset
String mediaId = mediaList.get(0).getId();
MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaId);
Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
LOG.info("get media info result: ");
LOG.info(foundMedia.getId());
LOG.info(foundMedia.getName());

// modify name of asset
MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaId).setName("New Name");
assetService.modifyMedia(modifyQuery).blockingSingle();

Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
LOG.info("get updated media info result: ");
LOG.info(updatedFoundMedia.getId());
LOG.info(updatedFoundMedia.getName());
}
}
}
Empty file.
Empty file.
43 changes: 43 additions & 0 deletions src/main/java/com/bynder/sdk/sample/TagsSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.bynder.sdk.sample;

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

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

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

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 a permanent token
BynderClient client = BynderClient.Builder.create(
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
.setPermanentToken(appProperties.getProperty("PERMANENT_TOKEN")).build());

AssetService assetService = client.getAssetService();

// get tags
List<Tag> assetTags = assetService.getTags().blockingSingle().body();
for (Tag assetTag : assetTags) {
LOG.info(assetTag.getId());
LOG.info(assetTag.getTag());
}
}
}
Empty file.
Empty file.

0 comments on commit 5a3e48d

Please sign in to comment.