Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9a8590

Browse files
Add support for assetsByAssetIds Admin API
1 parent 47f7983 commit b9a8590

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/Api/Admin/AssetsTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ public function assetsByIds($publicIds, $options = [])
181181
return $this->apiClient->get($uri, $params);
182182
}
183183

184+
/**
185+
* Lists assets with the specified asset IDs.
186+
*
187+
* @param string|array $assetIds The requested asset IDs.
188+
* @param array $options The optional parameters. See the
189+
* <a href=https://cloudinary.com/documentation/admin_api#get_resources target="_blank"> Admin API</a> documentation.
190+
*
191+
* @return ApiResponse
192+
*
193+
* @see https://cloudinary.com/documentation/admin_api#get_resources
194+
*/
195+
public function assetsByAssetIds($assetIds, $options = [])
196+
{
197+
$uri = [ApiEndPoint::ASSETS, 'by_asset_ids'];
198+
199+
$params = ArrayUtils::whitelist($options, ['public_ids', 'tags', 'moderations', 'context']);
200+
$params['asset_ids'] = $assetIds;
201+
202+
return $this->apiClient->get($uri, $params);
203+
}
204+
184205
/**
185206
* Returns the details of the specified asset and all its derived assets.
186207
*

tests/Integration/Admin/Assets/ListAssetsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,40 @@ public function testListUploadedAssetsByIds()
225225
self::assertCount(2, $result['resources']);
226226
}
227227

228+
/**
229+
* Get a single uploaded asset with a given Asset ID passed as a string.
230+
*/
231+
public function testListUploadedAssetsByAssetId()
232+
{
233+
$result = self::$adminApi->assetsByAssetIds(self::getTestAssetAssetId(self::$UNIQUE_PREFIX));
234+
235+
self::assertValidAsset(
236+
$result['resources'][0],
237+
[
238+
'public_id' => self::getTestAssetPublicId(self::$UNIQUE_PREFIX),
239+
AssetType::KEY => AssetType::IMAGE,
240+
]
241+
);
242+
self::assertCount(1, $result['resources']);
243+
}
244+
245+
/**
246+
* Get uploaded assets matching the Asset IDs passed as an array.
247+
*/
248+
public function testListUploadedAssetsByAssetIds()
249+
{
250+
$result = self::$adminApi->assetsByAssetIds(
251+
[
252+
self::getTestAssetAssetId(self::$UNIQUE_PREFIX),
253+
self::getTestAssetAssetId(self::TEST_ASSET)
254+
]
255+
);
256+
257+
self::assertValidAsset($result['resources'][0]);
258+
self::assertValidAsset($result['resources'][1]);
259+
self::assertCount(2, $result['resources']);
260+
}
261+
228262
/**
229263
* Get images by tag.
230264
*/

0 commit comments

Comments
 (0)