-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from gettyimages/add_sbi_functionality
Add SearchByImage functionality
- Loading branch information
Showing
8 changed files
with
563 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env php | ||
|
||
<?php | ||
require '../vendor/autoload.php'; | ||
use GettyImages\Api\GettyImages_Client; | ||
|
||
$apiKey = "API_KEY"; | ||
$apiSecret = "API_SECRET"; | ||
$user = "USER"; | ||
$password = "PASSWORD"; | ||
|
||
$client = GettyImages_Client::getClientWithResourceOwnerCredentials("$apiKey", "$apiSecret", "$user", "$password"); | ||
|
||
//Upload image to bucket and search: | ||
$destFilename = "testimage.jpg"; | ||
$sourceFilepath = "filepath/to/testimage.jpg"; | ||
|
||
$uploadedImageResponse = $client->SearchImagesCreativeByImage()->addToBucketAndSearch($destFilename, $sourceFilepath)->execute(); | ||
|
||
echo $uploadedImageResponse; | ||
|
||
//Search by GettyImages asset id: | ||
$assetId = "1194409229"; | ||
|
||
$assetIdResponse = $client->SearchImagesCreativeByImage()->withAssetId($assetId)->execute(); | ||
|
||
echo $assetIdResponse; |
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,110 @@ | ||
<?php | ||
|
||
namespace GettyImages\Api\Request\Search { | ||
|
||
use GettyImages\Api\Request\FluentRequest; | ||
use GettyImages\Api\Request\WebHelper; | ||
use Exception; | ||
|
||
class SearchImagesCreativeByImage extends FluentRequest { | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
protected $route = "search/images/creative/by-image"; | ||
|
||
protected function getRoute() { | ||
return $this->route; | ||
} | ||
|
||
protected function getMethod() { | ||
return "get"; | ||
} | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
private function addToBucket(string $destFilename, string $sourceFilepath) | ||
{ | ||
$route = 'search/by-image/uploads/'.$destFilename; | ||
$fileUrl = $this->endpointUri."/".$route; | ||
self::executeFileUpload($route, $sourceFilepath); | ||
return $fileUrl; | ||
} | ||
|
||
public function addToBucketAndSearch(string $destFilename, string $sourceFilepath) | ||
{ | ||
$url = self::addToBucket($destFilename, $sourceFilepath); | ||
return self::withImageUrl($url); | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withImageUrl(string $url) { | ||
$this->requestDetails["image_url"] = $url; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withAssetId(string $assetId) { | ||
$this->requestDetails["asset_id"] = $assetId; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Will set the search request to only return the fields provided. | ||
* | ||
* @param array $fields An array of field names to include in the response. | ||
* this list isn't exclusive, default fields are always returned. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withFields(array $fields) { | ||
$this->addArrayOfValuesToRequestDetails("fields", $fields); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withPage(int $pageNum) { | ||
$this->requestDetails["page"] = $pageNum; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageSize | ||
* @return $this | ||
*/ | ||
public function withPageSize(int $pageSize) { | ||
$this->requestDetails["page_size"] = $pageSize; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $productTypes An array of product types by which to filter. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withProductTypes(array $productTypes) { | ||
$this->addArrayOfValuesToRequestDetails("product_types", $productTypes); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $acceptLanguage Provide a header to specify the language of result values. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withAcceptLanguage(string $acceptLanguage) { | ||
$this->addHeader("Accept-Language", $acceptLanguage); | ||
return $this; | ||
} | ||
} | ||
} |
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,110 @@ | ||
<?php | ||
|
||
namespace GettyImages\Api\Request\Search { | ||
|
||
use GettyImages\Api\Request\FluentRequest; | ||
use GettyImages\Api\Request\WebHelper; | ||
use Exception; | ||
|
||
class SearchVideosCreativeByImage extends FluentRequest { | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
protected $route = "search/videos/creative/by-image"; | ||
|
||
protected function getRoute() { | ||
return $this->route; | ||
} | ||
|
||
protected function getMethod() { | ||
return "get"; | ||
} | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
private function addToBucket(string $destFilename, string $sourceFilepath) | ||
{ | ||
$route = 'search/by-image/uploads/'.$destFilename; | ||
$fileUrl = $this->endpointUri."/".$route; | ||
self::executeFileUpload($route, $sourceFilepath); | ||
return $fileUrl; | ||
} | ||
|
||
public function addToBucketAndSearch(string $destFilename, string $sourceFilepath) | ||
{ | ||
$url = self::addToBucket($destFilename, $sourceFilepath); | ||
return self::withImageUrl($url); | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withImageUrl(string $url) { | ||
$this->requestDetails["image_url"] = $url; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withAssetId(string $assetId) { | ||
$this->requestDetails["asset_id"] = $assetId; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Will set the search request to only return the fields provided. | ||
* | ||
* @param array $fields An array of field names to include in the response. | ||
* this list isn't exclusive, default fields are always returned. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withFields(array $fields) { | ||
$this->addArrayOfValuesToRequestDetails("fields", $fields); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageNum | ||
* @return $this | ||
*/ | ||
public function withPage(int $pageNum) { | ||
$this->requestDetails["page"] = $pageNum; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param int $pageSize | ||
* @return $this | ||
*/ | ||
public function withPageSize(int $pageSize) { | ||
$this->requestDetails["page_size"] = $pageSize; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $productTypes An array of product types by which to filter. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withProductTypes(array $productTypes) { | ||
$this->addArrayOfValuesToRequestDetails("product_types", $productTypes); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $acceptLanguage Provide a header to specify the language of result values. | ||
* @throws Exception | ||
* @return $this | ||
*/ | ||
public function withAcceptLanguage(string $acceptLanguage) { | ||
$this->addHeader("Accept-Language", $acceptLanguage); | ||
return $this; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.