Skip to content

Commit

Permalink
Fix analyze API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed Mar 21, 2024
1 parent c16ba33 commit e4cfcb7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/Api/Admin/AnalysisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ trait AnalysisTrait
* @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.
* @param array $parameters Additional parameters.
*
*
* @return ApiResponse
*
* @see AdminApi::analyzeAsync()
*
* @see https://cloudinary.com/documentation/media_analyzer_api_reference
*/
public function analyze($inputType, $analysisType, $uri = null)
public function analyze($inputType, $analysisType, $uri = null, $parameters = null)
{
return $this->analyzeAsync($inputType, $analysisType, $uri)->wait();
return $this->analyzeAsync($inputType, $analysisType, $uri, $parameters)->wait();
}

/**
Expand All @@ -47,16 +49,17 @@ public function analyze($inputType, $analysisType, $uri = null)
* @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.
* @param array $parameters Additional parameters.
*
* @return PromiseInterface
*
* @see https://cloudinary.com/documentation/media_analyzer_api_reference
*/
public function analyzeAsync($inputType, $analysisType, $uri = null)
public function analyzeAsync($inputType, $analysisType, $uri = null, $parameters = null)
{
$endPoint = [ApiEndPoint::ANALYSIS, 'analyze'];
$endPoint = [ApiEndPoint::ANALYSIS, 'analyze', $inputType];

$params = ['input_type' => $inputType, 'analysis_type' => $analysisType, 'uri' => $uri];
$params = ['analysis_type' => $analysisType, 'uri' => $uri, 'parameters' => $parameters];

return $this->apiV2Client->postJsonAsync($endPoint, $params);
}
Expand Down
22 changes: 12 additions & 10 deletions tests/Unit/Admin/AnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

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;

/**
Expand All @@ -31,19 +28,24 @@ final class AnalysisTest extends UnitTestCase
public function testAnalyze()
{
$mockAdminApi = new MockAdminApi();
$mockAdminApi->analyze("uri", "captioning", "https://res.cloudinary.com/demo/image/upload/dog");
$mockAdminApi->analyze(
"uri",
"captioning",
"https://res.cloudinary.com/demo/image/upload/dog",
["custom" => ["model_name" => "my_model", "model_version" => 1]]
);

$lastRequest = $mockAdminApi->getV2MockHandler()->getLastRequest();
$apiV2Configuration = new Configuration();
$lastRequest = $mockAdminApi->getV2MockHandler()->getLastRequest();
$apiV2Configuration = new Configuration();
$apiV2Configuration->api->apiVersion = '2';

self::assertRequestUrl($lastRequest, '/analysis/analyze', "", $apiV2Configuration);
self::assertRequestUrl($lastRequest, '/analysis/analyze/uri', "", $apiV2Configuration);
self::assertRequestJsonBodySubset(
$lastRequest,
[
"input_type"=> "uri",
"analysis_type"=> "captioning",
"uri"=> "https://res.cloudinary.com/demo/image/upload/dog",
"analysis_type" => "captioning",
"uri" => "https://res.cloudinary.com/demo/image/upload/dog",
"parameters" => ["custom" => ["model_name" => "my_model", "model_version" => 1]]
]
);
}
Expand Down

0 comments on commit e4cfcb7

Please sign in to comment.