Skip to content

Commit

Permalink
API-1824 media sample methods, add uploads sample method call
Browse files Browse the repository at this point in the history
  • Loading branch information
ahongbynder committed Dec 12, 2023
1 parent ae8d2d9 commit 769e562
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
50 changes: 50 additions & 0 deletions sample/MediaSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@

$assetBankManager = $bynder->getAssetBankManager();

// get derivatives
$derivativesPromise = $assetBankManager->getDerivatives();
$derivativesList = $derivativesPromise->wait();

if (!empty($derivativesList)) {
echo("Derivatives: " . "\n");
var_dump($derivativesList);
}

// Get Media Items list.
// Optional filter.
$query = [
Expand All @@ -58,6 +67,47 @@
}
}

// get info for single media asset
$mediaInfoPromise = $assetBankManager->getMediaInfo($MEDIA_ID_FOR_INFO);
$mediaInfo = $mediaInfoPromise->wait();

if (!empty($mediaInfo)) {
echo("Media Info for ID: " . $mediaInfo['id']);
var_dump($mediaInfo);
}

// get media download url
$mediaDownloadUrlPromise = $assetBankManager->getMediaDownloadLocation($MEDIA_ID_FOR_INFO);
$mediaDownloadUrl = $mediaDownloadUrlPromise->wait();

if (!empty($mediaDownloadUrl)) {
echo("Media Download URL for ID: " . $MEDIA_ID_FOR_INFO);
var_dump($mediaDownloadUrl);
}

// modify name of asset
$renameData = ['name' => 'PHP SDK Test'];
$modifyMediaPromise = $assetBankManager->modifyMedia($MEDIA_ID_FOR_RENAME, $renameData);
$modifyMediaResult = $modifyMediaPromise->wait();

if (!empty($modifyMediaResult)) {
echo("Modify Media for ID: " . $MEDIA_ID_FOR_RENAME);
var_dump($modifyMediaResult);

// get info for modified media asset
$mediaInfoPromise = $assetBankManager->getMediaInfo($MEDIA_ID_FOR_RENAME);
$mediaInfo = $mediaInfoPromise->wait();

if (!empty($mediaInfo)) {
echo("Media Info for ID: " . $mediaInfo['id']);
var_dump($mediaInfo);
}
}

// delete asset
echo("Deleting Media ID: " . $MEDIA_ID_FOR_REMOVAL);
$deleteMediaPromise = $assetBankManager->deleteMedia($MEDIA_ID_FOR_REMOVAL);
$deleteMediaResult = $deleteMediaPromise->wait();
} catch (Exception $e) {
var_dump($e);
}
Expand Down
67 changes: 67 additions & 0 deletions sample/UploadsSample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/sample_config.php');
use Bynder\Api\BynderClient;
use Bynder\Api\Impl\OAuth2;

try {
// instantiate BynderClient to make API requests for portal, client id, client secret with redirect uri
$bynder = new BynderClient(new Oauth2\Configuration(
$bynderDomain,
$redirectUri,
$clientId,
$clientSecret,
$token,
['timeout' => 5] // Guzzle HTTP request options
));

// if no access token, need to use OAuth flow to authorize and get access code, then use code to get token
if ($token === null) {
echo $bynder->getAuthorizationUrl([
'offline',
'current.user:read',
'current.profile:read',
'asset:read',
'asset:write',
'meta.assetbank:read',
'asset.usage:read',
'asset.usage:write',
]) . "\n\n";

$code = readline('Enter code: ');

if ($code == null) {
echo("Failed to get access token");
exit;
}

$token = $bynder->getAccessToken($code);
}

$assetBankManager = $bynder->getAssetBankManager();

// Upload a file and create an Asset.
// Get Brands. Returns a Promise.
$brandsListPromise = $assetBankManager->getBrands();

// Wait for the promise to be resolved.
$brandsList = $brandsListPromise->wait();

// get brand to upload to
if (!empty($brandsList)) {
echo("Updating asset to brand id: " . $brandsList[0]['id']);
$data = [
// Will need to create this file for successful test call
'filePath' => 'image.png',
'brandId' => $brandsList[0]['id'],
'name' => 'Image name',
'description' => 'Image description'
];
$filePromise = $assetBankManager->uploadFileAsync($data);
$fileInfo = $filePromise->wait();
var_dump($fileInfo);
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
?>

0 comments on commit 769e562

Please sign in to comment.