Skip to content

Commit a702b6e

Browse files
committed
API-2194 add client credentials sample
1 parent 93264b6 commit a702b6e

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.bynder.sdk.sample;
2+
3+
import com.bynder.sdk.configuration.Configuration;
4+
import com.bynder.sdk.configuration.HttpConnectionSettings;
5+
import com.bynder.sdk.configuration.OAuthSettings;
6+
import com.bynder.sdk.model.Brand;
7+
import com.bynder.sdk.model.Media;
8+
import com.bynder.sdk.model.MediaType;
9+
import com.bynder.sdk.query.MediaQuery;
10+
import com.bynder.sdk.query.OrderBy;
11+
import com.bynder.sdk.service.BynderClient;
12+
import com.bynder.sdk.service.asset.AssetService;
13+
import com.bynder.sdk.service.oauth.OAuthService;
14+
import com.bynder.sdk.util.Utils;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
17+
import java.io.IOException;
18+
import java.net.URISyntaxException;
19+
import java.net.URL;
20+
import java.util.Arrays;
21+
import java.util.List;
22+
import java.util.Properties;
23+
24+
public class OAuthClientCredentialsSample {
25+
private static final Logger LOG = LoggerFactory.getLogger(MediaSample.class);
26+
27+
public static void main(final String[] args) throws IOException, URISyntaxException {
28+
/**
29+
* Loads app.properties file under src/main/resources
30+
*/
31+
Properties appProperties = Utils.loadConfig("app");
32+
33+
// Initialize BynderClient with OAuth
34+
OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), null);
35+
BynderClient client = BynderClient.Builder.create(
36+
new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
37+
.setOAuthSettings(oAuthSettings)
38+
.setHttpConnectionSettings(new HttpConnectionSettings()).build());
39+
List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
40+
"asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
41+
"meta.assetbank:write", "meta.workflow:read");
42+
43+
// Initialize OAuthService
44+
OAuthService oauthService = client.getOAuthService();
45+
46+
// use client credentials
47+
oauthService.getAccessTokenClientCredentials(scopes).blockingSingle();
48+
49+
// Initialize asset service
50+
AssetService assetService = client.getAssetService();
51+
52+
// Call the API to request for brands
53+
List<Brand> brands = assetService.getBrands().blockingSingle().body();
54+
if (brands != null && !brands.isEmpty()) {
55+
for (Brand brand : brands) {
56+
LOG.info("Brand ID: " + brand.getId());
57+
LOG.info("Brand Name: " + brand.getName());
58+
LOG.info("Brand Description: " + brand.getDescription());
59+
}
60+
}
61+
62+
// Call the API to request for media assets
63+
MediaQuery mediaQuery = new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
64+
List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
65+
if (mediaList != null && !mediaList.isEmpty()) {
66+
for (Media media : mediaList) {
67+
LOG.info("Media ID: " + media.getId());
68+
LOG.info("Media Name: " + media.getName());
69+
}
70+
}
71+
72+
System.exit(0);
73+
}
74+
}

0 commit comments

Comments
 (0)