Skip to content

Commit

Permalink
API-1822 add upload sample, smart filters sample, usage sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ahongbynder committed Nov 28, 2023
1 parent 5a3e48d commit c7bb558
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/bynder/sdk/sample/BrandsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept

// Call the API to request for brands
List<Brand> brands = assetService.getBrands().blockingSingle().body();
LOG.info("brands");
for (Brand brand : brands) {
LOG.info(brand.getName());
LOG.info(brand.getDescription());
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/bynder/sdk/sample/CollectionsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// Initialize collection service
CollectionService collectionService = client.getCollectionService();

// get collections
CollectionQuery collectionQuery = new CollectionQuery();
// get collections with limit and page
CollectionQuery collectionQuery = new CollectionQuery().setLimit(10).setPage(1);
List<Collection> collections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
Expand All @@ -49,12 +50,18 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept
// add collection
CollectionCreateQuery createCollectionQuery = new CollectionCreateQuery("New Collection 1234");
collectionService.createCollection(createCollectionQuery).blockingSingle();
//

// get collections with added collection
List<Collection> updatedCollections = collectionService.getCollections(collectionQuery).blockingSingle().body();
for (Collection collectionResult : collections) {
LOG.info("collection: ");
LOG.info(collectionResult.getId());
LOG.info(collectionResult.getName());
LOG.info(collectionResult.getDescription());
}

// TODO addMediaToCollection
// TODO removeMediaFromCollection
// TODO shareCollection
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/bynder/sdk/sample/SmartFiltersSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.model.Smartfilter;
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 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 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();

List<Smartfilter> smartFilters = assetService.getSmartfilters().blockingSingle().body();
for (Smartfilter smartFilter : smartFilters) {
LOG.info(smartFilter.getId());
// smart filter metaproperties
List<String> smartFilterMetaproperties = smartFilter.getMetaproperties();
if (!smartFilterMetaproperties.isEmpty()) {
LOG.info("smart filter metaproperty ids:");
for (String metaproperty : smartFilterMetaproperties) {
LOG.info(metaproperty);
}
}

// labels
Map<String, String> smartFilterLabels = smartFilter.getLabels();
for (Map.Entry<String, String> entry : smartFilterLabels.entrySet()) {
LOG.info("smart filter label: ");
LOG.info(entry.getKey() + " " + entry.getValue());
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/bynder/sdk/sample/TagsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public static void main(final String[] args) throws URISyntaxException, IOExcept

AssetService assetService = client.getAssetService();

// get tags
// get tags and media count for each tag
List<Tag> assetTags = assetService.getTags().blockingSingle().body();
for (Tag assetTag : assetTags) {
LOG.info(assetTag.getId());
LOG.info(assetTag.getTag());
LOG.info(String.valueOf(assetTag.getMediaCount()));
}
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/bynder/sdk/sample/UploadSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bynder.sdk.sample;

import com.bynder.sdk.configuration.Configuration;
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.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 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 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();

// Upload a file
// Call the API to request for brands
String brandId = "";
List<Brand> brands = assetService.getBrands().blockingSingle().body();
if (!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 specify in this manner
uploadQuery.setFileName("testasset.png");
SaveMediaResponse saveMediaResponse = assetService.uploadFile(uploadQuery).blockingSingle();
LOG.info(saveMediaResponse.getMediaId());
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/bynder/sdk/sample/UsageSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.bynder.sdk.model;

import com.bynder.sdk.configuration.Configuration;
import com.bynder.sdk.model.Usage;
import com.bynder.sdk.query.UsageQuery;
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.lang.Integer;
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 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 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();

UsageQuery usageQuery= new UsageQuery();
List<Usage> assetUsages = assetService.getUsage(usageQuery).blockingSingle().body();

// TODO use asset usage
for (Usage assetUsage : assetUsages) {
LOG.info(assetUsage.getAssetId());
}
}
}

0 comments on commit c7bb558

Please sign in to comment.