-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1822 add upload sample, smart filters sample, usage sample
- Loading branch information
1 parent
5a3e48d
commit c7bb558
Showing
6 changed files
with
172 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |