/** * Refresh this AccessToken */ public function refresh() { $grant = new ClientCredentialsGrantRequest($this->clientId, $this->clientSecret, $this->scopes); $tokens = $grant->getTokens(); $this->accessToken = $tokens->{"access_token"}; $this->expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"}); }
/** * Get an AccessToken for use when communicating with the Zara 4 API service. * * @return ReissuableAccessToken */ public function acquireAccessToken() { $grant = new ClientCredentialsGrantRequest($this->clientId, $this->clientSecret, $this->scopes); $tokens = $grant->getTokens(); $accessToken = $tokens->{"access_token"}; $expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"}); return new ReissuableAccessToken($this->clientId, $this->clientSecret, $accessToken, $expiresAt, $this->scopes); }
/** * Refresh this AccessToken */ public function refresh() { $grant = new RefreshTokenGrant($this->clientId, $this->clientSecret, $this->refreshToken); $tokens = $grant->getTokens(); $this->accessToken = $tokens->{"access_token"}; $this->expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"}); $this->refreshToken = $tokens->{"refresh_token"}; }
/** * Get an AccessToken for use when communicating with the Zara 4 API service. * * @return RefreshableAccessToken */ public function acquireAccessToken() { $grant = new PasswordGrant($this->clientId, $this->clientSecret, $this->username, $this->password, $this->scopes); $tokens = $grant->getTokens(); $accessToken = $tokens->{"access_token"}; $refreshToken = $tokens->{"refresh_token"}; $expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"}); return new RefreshableAccessToken($this->clientId, $this->clientSecret, $accessToken, $expiresAt, $refreshToken); }
public static function cumulativeUsageForCurrentBillingUsage($accessToken) { $url = Util::url("/v1/usage/image-processing/cumulative-count/current-billing-period"); $data = ["query" => ["access_token" => $accessToken]]; $responseData = Util::get($url, $data); $personalDayData = (array) $responseData->{"day-data"}; ksort($personalDayData); $response = ["quota" => $responseData->{"quota"}, "personal-day-data" => $personalDayData]; // // Add team data // if (isset($responseData->{"team-day-data"})) { $teamDayData = (array) $responseData->{"team-day-data"}; ksort($teamDayData); $response["team-day-data"] = $teamDayData; } return $response; }
/** * @param Request $imageProcessingRequest * @return array */ public function processImageRaw(Request $imageProcessingRequest) { $url = Util::url("/v1/image-processing/request"); // // Construct data containing url to be processed and params. // $data = ["body" => []]; if ($this->accessToken) { $data["body"]["access_token"] = $this->accessToken->token(); } $params = $imageProcessingRequest->generateFormData(); foreach ($params as $key => $value) { $data["body"][$key] = $value; } // // NOTE: This will be ignored for all API credentials (except trusted applications) to prevent ip hoaxing // if ($this->forwardForIp) { $data["headers"] = ["Z4-Connecting-IP" => $this->forwardForIp]; } return Util::post($url, $data); }
/** * @return array */ public function getTokens() { return Util::post(Util::url("/oauth/access_token"), ["body" => $this->data()]); }