-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1824 [BE][PHP SDK] Implement Sample Files for Functionality Testi…
…ng (#66) * API-1824 setup sample files PHP sdk * API-1824 media sample methods, add uploads sample method call * API-1824 list asset ids within collection, sample collections * API-1824 asset usage sample * API-1824 metaproperty changes, options/dependencies for sample file * API-1824 dockerize bynder php sdk to run sample files * API-1824 add additional download url method calls, add makefile/docker files, add README for instructions * API-1824 use var_dump for BrandsSample.php * API-1824 cleanup * API-1824 use correct file path to sample image * API-1824 update README for docker build
- Loading branch information
1 parent
f2ed9dd
commit f7c7185
Showing
13 changed files
with
849 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ docker-compose* | |
.vscode | ||
README.md | ||
LICENSE | ||
**/sample |
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,8 @@ | ||
FROM composer:latest | ||
|
||
WORKDIR /app | ||
|
||
COPY composer.json ./ | ||
RUN composer install | ||
|
||
COPY . . |
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,10 @@ | ||
run-php-sdk-docker: | ||
docker-compose up -d | ||
|
||
stop-php-sdk-docker: | ||
docker-compose down | ||
|
||
# make execute-php-sdk-sample sample-file-name=BrandsSample.php | ||
# executes command in running container | ||
execute-php-sdk-sample: | ||
docker-compose exec bynder-php-sdk php /app/sample/$(sample-file-name) |
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,10 @@ | ||
version: '3.9' | ||
|
||
services: | ||
bynder-php-sdk: | ||
container_name: bynder-php-sdk | ||
build: | ||
dockerfile: Dockerfile.dev | ||
command: sh -c "tail -f /dev/null" | ||
volumes: | ||
- .:/app |
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 @@ | ||
<?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(); | ||
|
||
// Get Brands. Returns a Promise. | ||
$brandsListPromise = $assetBankManager->getBrands(); | ||
// Wait for the promise to be resolved. | ||
$brandsList = $brandsListPromise->wait(); | ||
|
||
if (!empty($brandsList)) { | ||
foreach ($brandsList as $brand) { | ||
echo("Brand ID: " . $brand['id'] . "\n"); | ||
var_dump($brand); | ||
} | ||
} | ||
} catch (Exception $e) { | ||
var_dump($e); | ||
} | ||
?> | ||
|
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,74 @@ | ||
<?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', | ||
'collection:read', | ||
'collection:write' | ||
]) . "\n\n"; | ||
|
||
$code = readline('Enter code: '); | ||
|
||
if ($code == null) { | ||
echo("Failed to get access token"); | ||
exit; | ||
} | ||
|
||
$token = $bynder->getAccessToken($code); | ||
} | ||
|
||
$assetBankManager = $bynder->getAssetBankManager(); | ||
|
||
// Get Collections List. | ||
// optional filter | ||
$collectionQueryFilter = [ | ||
'count' => true, | ||
'limit' => 20 | ||
]; | ||
$collectionListPromise = $assetBankManager->getCollections($collectionQueryFilter); | ||
$collectionsList = $collectionListPromise->wait(); | ||
|
||
// print collection list, each collection result | ||
if (!empty($collectionsList) && !empty($collectionsList['collections'])) { | ||
foreach ($collectionsList['collections'] as $collection) { | ||
echo("Collection ID: " . $collection['id'] . "\n"); | ||
var_dump($collection); | ||
} | ||
} | ||
|
||
// get collection assets for a collection | ||
$collectionsAssetPromise = $assetBankManager->getCollectionAssets($GET_COLLECTION_ASSETS_ID); | ||
$collectionAssets = $collectionsAssetPromise->wait(); | ||
|
||
if (!empty($collectionAssets)) { | ||
echo("Collection Asset IDs for ID: " . $GET_COLLECTION_ASSETS_ID); | ||
var_dump($collectionAssets); | ||
} | ||
|
||
} catch (Exception $e) { | ||
var_dump($e); | ||
} | ||
?> |
Oops, something went wrong.