コード例 #1
0
ファイル: DownloadVideo.php プロジェクト: bSushil/gettyimages
 public function execute()
 {
     $assetId = $this->requestDetails["id"];
     unset($this->requestDetails["id"]);
     $this->requestDetails["auto_download"] = "false";
     $endpointUrl = $this->endpointUri . "/" . $this->getRoute() . "/" . $assetId;
     $credentialHeaders = array(CURLOPT_HTTPHEADER => array("Api-Key: " . $this->credentials->getApiKey(), "Authorization: " . $this->credentials->getAuthorizationHeaderValue()));
     $response = WebHelper::postWithNoBody($endpointUrl, $this->requestDetails, $credentialHeaders);
     if ($response["http_code"] != 200 && $response["http_code"] != 303) {
         throw new \Exception("Non 200/303 status code returned: '" . $response["http_code"] . "'\nBody: " . $response["body"] . "\nCurl Error: " . $response["curl_error"]);
     }
     if ($response["http_code"] == 303) {
         $parsedHeaderArray = explode("\r\n", $response["header"]);
         foreach ($parsedHeaderArray as $headerValue) {
             $headerValueToLookup = "Location: ";
             $headerLookupLen = strlen($headerValueToLookup);
             if (substr($headerValue, 0, $headerLookupLen) === $headerValueToLookup) {
                 $videoDownloadUrl = substr($headerValue, $headerLookupLen);
                 return $videoDownloadUrl;
             }
         }
     } else {
         return $response['body'];
     }
     return $response;
 }
コード例 #2
0
ファイル: Search.php プロジェクト: bSushil/gettyimages
 /**
  *    Realizes the search request. Causes the request to go out and get processed
  *
  *
  * @throws \Exception
  * @return string Json package of the search results
  */
 public function execute()
 {
     $endpointUrl = $this->endpointUri . "/" . $this->getRoute();
     if (!$this->credentials->getAuthorizationHeaderValue()) {
         $authHeader = array(CURLOPT_HTTPHEADER => array("Api-Key:" . $this->credentials->getApiKey()));
     } else {
         $authHeader = array(CURLOPT_HTTPHEADER => array("Api-Key:" . $this->credentials->getApiKey(), "Authorization: " . $this->credentials->getAuthorizationHeaderValue()));
     }
     $response = WebHelper::getJsonWebRequest($endpointUrl, $this->requestDetails, $authHeader);
     if ($response["http_code"] != 200) {
         throw new \Exception("Non 200 status code returned: " . $response["http_code"] . "\nBody: " . $response["body"]);
     }
     return $response["body"];
 }
コード例 #3
0
ファイル: Credentials.php プロジェクト: bSushil/gettyimages
 /**
  * Handles getting a client credential response
  *
  * @param string $userKey Mashery API Key
  * @param string $userSecret Mashery API Secret
  * @return string Full oauth2 response object in json format
  */
 public function getOauth2ClientCredentials($userKey, $userSecret)
 {
     $request = array("client_id" => $userKey, "client_secret" => $userSecret, "grant_type" => "client_credentials");
     $response = WebHelper::postFormEncodedWebRequest($this->endpointUri, $request);
     return $response;
 }