/** * Request token. * * You don't have to run this function for use other service. * When create \keika299\ConohaAPI\Conoha object without token, try this and get token automatically. * See https://www.conoha.jp/docs/identity-post_tokens.html * * @return mixed * @throws \keika299\ConohaAPI\Common\Exceptions\IConohaAPIException */ public function getToken() { $request = new Request(); $request->setMethod('POST')->setBaseURI($this->baseURI)->setURI('/v2.0/tokens')->setAccept('application/json')->setJson($this->getTokenRequestArray()); $response = $request->exec(); return $response->getJson(); }
/** * Request token. * * You don't have to run this function for use other service. * When create \keika299\ConohaAPI\Conoha object without token, try this and get token automatically. * See https://www.conoha.jp/docs/identity-post_tokens.html * * @return mixed * @throws \keika299\ConohaAPI\Common\Exceptions\IConohaAPIException */ public function getToken() { $requestArray = ["auth" => ["passwordCredentials" => ["username" => $this->client->getUsername(), "password" => $this->client->getUserPassword()]]]; if ($this->client->getTenantID() !== null) { $requestArray["auth"]["tenantId"] = $this->client->getTenantID(); } $request = new Request(); $request->setMethod('POST')->setBaseURI($this->baseURI)->setURI('/v2.0/tokens')->setAccept('application/json')->setJson($requestArray); $response = $request->exec(); return $response->getJson(); }
/** * Get object storage size. * * $options is data range and data mode. * 'start_date_raw' is start date UNIX time. * 'end_date_raw' is end date UNIX time. * 'mode' is data mode. It can be select average, max, and min. * * See https://www.conoha.jp/docs/account-get_objectstorage_size_rrd.html * * @param array $options * @return mixed * @throws \keika299\ConohaAPI\Common\Exceptions\IConohaAPIException */ public function getObjectStorageSize($options = array()) { $optionQuery = isset($options['start_date_raw']) ? '?offset=' . $options['start_date_raw'] : ''; $optionQuery = isset($options['end_date_raw']) ? $optionQuery == '' ? '?end_date_raw=' . $options['end_date_raw'] : $optionQuery . '&end_date_raw=' . $options['end_date_raw'] : $optionQuery; $optionQuery = isset($options['mode']) ? $optionQuery == '' ? '?mode=' . $options['mode'] : $optionQuery . '&mode=' . $options['mode'] : $optionQuery; $request = new Request(); $request->setMethod('GET')->setBaseURI($this->baseURI)->setURI('/v1/' . $this->client->getTenantId() . '/object-storage/rrd/size' . $optionQuery)->setAccept('application/json')->setToken($this->client->getToken()); $response = $request->exec(); return $response->getJson(); }
public function testSetToken() { $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Network\\Request', $this->request->setToken('sample00d88246078f2bexample788f7')); }
/** * Refresh token and retry request. * * @param Request $request * @return Response */ public function requestWithUpdatedToken(Request $request) { $this->client->updateToken(); $request->setToken($this->client->getToken()); return $request->exec(); }
/** * Refresh token and retry request. * * @param Request $request * @return Response */ public function requestWithUpdatedToken(Request $request) { $this->token->refreshToken(); $request->setToken($this->token->getToken()); return $request->exec(); }