-
Notifications
You must be signed in to change notification settings - Fork 22
/
sample.php
188 lines (157 loc) · 4.84 KB
/
sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
require_once('vendor/autoload.php');
use Bynder\Api\BynderClient;
use Bynder\Api\Impl\OAuth2;
use Bynder\Api\Impl\PermanentTokens;
define('BYNDER_INTEGRATION_ID', '');
// When using OAuth2
$bynderDomain = 'portal.getbynder.com';
$redirectUri = '';
$clientId = '';
$clientSecret = '';
$token = null;
/* If we have a token stored
$token = new \League\OAuth2\Client\Token\AccessToken([
'access_token' => '',
'refresh_token' => '',
'expires' => 123456789
]);
*/
$bynder = new BynderClient(new Oauth2\Configuration(
$bynderDomain,
$redirectUri,
$clientId,
$clientSecret,
$token,
['timeout' => 5] // Guzzle HTTP request options
));
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) {
exit;
}
$token = $bynder->getAccessToken($code);
var_dump($token);
}
// When using permanent tokens
$bynderDomain = 'portal.getbynder.com';
$token = '';
$configuration = new PermanentTokens\Configuration(
$bynderDomain,
$token,
['timeout' => 5] // Guzzle HTTP request options
);
$bynder = new BynderClient($configuration);
// Example calls
try {
$currentUser = $bynder->getCurrentUser()->wait();
var_dump($currentUser);
if(isset($currentUser['profileId'])) {
$roles = $bynder->getSecurityProfile($currentUser['profileId'])->wait();
}
$assetBankManager = $bynder->getAssetBankManager();
// Get Brands. Returns a Promise.
$brandsListPromise = $assetBankManager->getBrands();
// Wait for the promise to be resolved.
$brandsList = $brandsListPromise->wait();
var_dump($brandsList);
// Get Media Items list.
// Optional filter.
$query = [
'count' => true,
'limit' => 2,
'type' => 'image',
'versions' => 1
];
$mediaListPromise = $assetBankManager->getMediaList($query);
$mediaList = $mediaListPromise->wait();
var_dump($mediaList);
// Get specific Media Item info.
$mediaId = array_pop($mediaList['media'])['id'];
$mediaItemPromise = $assetBankManager->getMediaInfo($mediaId, $query);
$mediaItem = $mediaItemPromise->wait();
var_dump($mediaItem);
// Get Metaproperties.
$metapropertiesListPromise = $assetBankManager->getMetaproperties();
$metapropertiesList = $metapropertiesListPromise->wait();
var_dump($metapropertiesList);
// Get Tags.
$tagsListPromise = $assetBankManager->getTags();
$tagsList = $tagsListPromise->wait();
var_dump($tagsList);
// Get SmartFilters.
$smartFilterListPromise = $assetBankManager->getSmartfilters();
$smartFilterList = $smartFilterListPromise->wait();
var_dump($smartFilterList);
// Upload a file and create an Asset.
$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);
if(BYNDER_INTEGRATION_ID == '') {
return;
}
// Create Asset usage.
$usageCreatePromise = $assetBankManager->createUsage(
[
'integration_id' => BYNDER_INTEGRATION_ID,
'asset_id' => $mediaId,
'timestamp' => date(DateTime::ISO8601),
'uri' => '/posts/1',
'additional' => 'Testing usage tracking'
]
);
$usageCreated = $usageCreatePromise->wait();
var_dump($usageCreated);
// Create another Asset usage.
$usageCreatePromise = $assetBankManager->createUsage(
[
'integration_id' => BYNDER_INTEGRATION_ID,
'asset_id' => $mediaId,
'timestamp' => date(DateTime::ISO8601),
'uri' => '/posts/2',
'additional' => 'Testing usage tracking'
]
);
$usageCreated = $usageCreatePromise->wait();
var_dump($usageCreated);
// Retrieve Asset usage.
$retrieveUsages = $assetBankManager->getUsage(
[
'asset_id' => $mediaId
]
)->wait();
var_dump($retrieveUsages);
// Delete Asset usage and retrieve again.
$deleteUSages = $assetBankManager->deleteUSage(
[
'integration_id' => BYNDER_INTEGRATION_ID,
'asset_id' => $mediaId,
'uri' => '/posts/2'
]
)->wait();
$retrieveUsages = $assetBankManager->getUsage(
[
'asset_id' => $mediaId
]
)->wait();
var_dump($retrieveUsages);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}