Skip to content

Commit

Permalink
Add b2_create_key
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxbux committed May 7, 2020
1 parent bd0bba9 commit 97ca301
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,47 @@ public function createBucket(array $options)
return new Bucket($response['bucketId'], $response['bucketName'], $response['bucketType']);
}

/**
*
*/
public function createKey(array $options)
{
if (!isset($options['Capabilities']) || gettype($options['Capabilities']) != 'array' || count($options['Capabilities']) == 0) {
throw new ValidationException('Capabilities is required and must be an array with at least one valid item.');
}

if (!isset($options['KeyName'])) {
throw new ValidationException('KeyName is required');
}

$json = [
'accountId' => $this->accountId,
'capabilities' => $options['Capabilities'],
'keyName' => $options['KeyName'],
];

if (isset($options['ValidDurationInSeconds'])) {
$json['validDurationInSeconds'] = $options['ValidDurationInSeconds'];
}

if (isset($options['BucketId'])) {
$json['bucketId'] = $options['BucketId'];
}

if (isset($options['FileNamePrefix'])) {
$json['namePrefix'] = $options['FileNamePrefix'];
}

$response = $this->client->request('POST', $this->apiUrl.'/b2_create_key', [
'headers' => [
'Authorization' => $this->authToken()
],
'json' => $json,
]);

return $response;
}

/**
* Updates the type attribute of a bucket by the given ID.
*
Expand Down

0 comments on commit 97ca301

Please sign in to comment.