-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57290a5
commit 701dcf0
Showing
12 changed files
with
185 additions
and
18 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,63 @@ | ||
<?php | ||
/** | ||
* This file is part of the Cloudinary PHP package. | ||
* | ||
* (c) Cloudinary | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cloudinary\Api\Admin; | ||
|
||
use Cloudinary\Api\ApiClient; | ||
use Cloudinary\Api\ApiResponse; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
|
||
/** | ||
* Represents Analysis API methods. | ||
* | ||
* @property ApiClient $apiV2Client Defined in AdminApi class. | ||
* | ||
* @api | ||
*/ | ||
trait AnalysisTrait | ||
{ | ||
/** | ||
* Analyzes an asset with the requested analysis type. | ||
* | ||
* @param string $inputType The type of input for the asset to analyze ('uri'). | ||
* @param string $analysisType The type of analysis to run ('google_tagging', 'captioning', 'fashion'). | ||
* @param string $uri The URI of the asset to analyze. | ||
* | ||
* @return ApiResponse | ||
* | ||
* @see AdminApi::analyzeAsync() | ||
* | ||
* @see https://cloudinary.com/documentation/media_analyzer_api_reference | ||
*/ | ||
public function analyze($inputType, $analysisType, $uri = null) | ||
{ | ||
return $this->analyzeAsync($inputType, $analysisType, $uri)->wait(); | ||
} | ||
|
||
/** | ||
* Analyzes an asset with the requested analysis type asynchronously. | ||
* | ||
* @param string $inputType The type of input for the asset to analyze ('uri'). | ||
* @param string $analysisType The type of analysis to run ('google_tagging', 'captioning', 'fashion'). | ||
* @param string $uri The URI of the asset to analyze. | ||
* | ||
* @return PromiseInterface | ||
* | ||
* @see https://cloudinary.com/documentation/media_analyzer_api_reference | ||
*/ | ||
public function analyzeAsync($inputType, $analysisType, $uri = null) | ||
{ | ||
$endPoint = [ApiEndPoint::ANALYSIS, 'analyze']; | ||
|
||
$params = ['input_type' => $inputType, 'analysis_type' => $analysisType, 'uri' => $uri]; | ||
|
||
return $this->apiV2Client->postJsonAsync($endPoint, $params); | ||
} | ||
} |
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
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
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
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
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,50 @@ | ||
<?php | ||
/** | ||
* This file is part of the Cloudinary PHP package. | ||
* | ||
* (c) Cloudinary | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cloudinary\Test\Unit\Admin; | ||
|
||
use Cloudinary\Api\Exception\ApiError; | ||
use Cloudinary\Configuration\Configuration; | ||
use Cloudinary\Test\Helpers\MockAdminApi; | ||
use Cloudinary\Test\Helpers\RequestAssertionsTrait; | ||
use Cloudinary\Test\Integration\IntegrationTestCase; | ||
use Cloudinary\Test\Unit\Asset\AssetTestCase; | ||
use Cloudinary\Test\Unit\UnitTestCase; | ||
|
||
/** | ||
* Class AnalysisTest | ||
*/ | ||
final class AnalysisTest extends UnitTestCase | ||
{ | ||
use RequestAssertionsTrait; | ||
|
||
/** | ||
* Test analyze. | ||
*/ | ||
public function testAnalyze() | ||
{ | ||
$mockAdminApi = new MockAdminApi(); | ||
$mockAdminApi->analyze("uri", "captioning", "https://res.cloudinary.com/demo/image/upload/dog"); | ||
|
||
$lastRequest = $mockAdminApi->getV2MockHandler()->getLastRequest(); | ||
$apiV2Configuration = new Configuration(); | ||
$apiV2Configuration->api->apiVersion = '2'; | ||
|
||
self::assertRequestUrl($lastRequest, '/analysis/analyze', "", $apiV2Configuration); | ||
self::assertRequestJsonBodySubset( | ||
$lastRequest, | ||
[ | ||
"input_type"=> "uri", | ||
"analysis_type"=> "captioning", | ||
"uri"=> "https://res.cloudinary.com/demo/image/upload/dog", | ||
] | ||
); | ||
} | ||
} |