-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1822 [BE] [SDK] Implement Sample Files for JAVA-SDK Functionality…
… Testing (#114) * API-1822 setup sample files for java sdk api calls * API-1822 add upload sample, smart filters sample, usage sample * API-1822 add metaproperties sample, update logging for samples, setup methods for collection sample * API-1822 update collections sample with share, add media, remove media * API-1822 resolve package name * API-1822 setup asset usage sample * API-1822 use OAuth for client, add testasset image for upload * API-1822 add media removal, add README, add null checks for collections * API-1822 update readme for sample files * API-1822 get derivatives for portal * API-1822 update readme for derivatives method * API-1822 cleanup * API-1822 add System.exit(0) to terminate processes * API-1822 cleanup
- Loading branch information
1 parent
64acb65
commit 4331018
Showing
10 changed files
with
963 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<Brand> 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); | ||
} | ||
} |
Oops, something went wrong.