Skip to content

Commit

Permalink
add locked sourceimages support
Browse files Browse the repository at this point in the history
  • Loading branch information
chregu committed Aug 16, 2022
1 parent 399e180 commit bcabd53
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ This project tries to follow [Semantic Versioning](http://semver.org/) since the

This document mainly describes API changes important to users of this library.

# 1.18.2 - 2022-06-24
## 1.19.0 - 2022-08-16

* Add support for locked sourceimages via `\Rokka\Client\Image::setProtected`.
See [the API Docs](https://api.rokka.io/doc/#/sourceimages/putSourceImageOptionsLocked) for details

## 1.18.2 - 2022-06-24

* Allow firebase/php-jwt 5.0

# 1.18.1 - 2022-06-24
## 1.18.1 - 2022-06-24

* Add mimetype attribute to SourceImage object.

# 1.18.0 - 2022-05-31
## 1.18.0 - 2022-05-31

* Remove support for PHP 7.1
* Add support for PHP 8.1
Expand Down
13 changes: 11 additions & 2 deletions src/Core/SourceImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class SourceImage
*/
public $protected;

/**
* @var bool
*/
public $locked;

/**
* Constructor.
*
Expand All @@ -107,6 +112,7 @@ class SourceImage
* @param string $link Link to the image
* @param string $shortHash The short hash
* @param bool $protected Is image protected
* @param bool $locked Is image locked
* @param mixed $mimetype
*/
public function __construct(
Expand All @@ -125,7 +131,8 @@ public function __construct(
\DateTime $created,
$link,
$shortHash = null,
$protected = false
$protected = false,
$locked = false
) {
$this->organization = $organization;
$this->binaryHash = $binaryHash;
Expand All @@ -146,6 +153,7 @@ public function __construct(
}
$this->shortHash = $shortHash;
$this->protected = $protected;
$this->locked = $locked;
}

/**
Expand Down Expand Up @@ -194,7 +202,8 @@ public static function createFromDecodedJsonResponse(array $data): self
new \DateTime($data['created']),
$data['link'],
$data['short_hash'],
$data['protected']
$data['protected'],
$data['locked']
);
}

Expand Down
35 changes: 33 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,6 @@ public function setDynamicMetadata($dynamicMetadata, $hash, $organization = '',
*/
public function setProtected($protected, $hash, $organization = '', $options = [])
{
$count = 0;
$response = null;
$callOptions = [];
$callOptions['json'] = $protected;

Expand All @@ -713,6 +711,39 @@ public function setProtected($protected, $hash, $organization = '', $options = [
return $this->extractHashFromLocationHeader($response->getHeader('Location'));
}

/**
* (Un)sets locked status to a SourceImage.
*
* @param bool $locked set the image to locked or no
* Or an array with more than one of those
* @param string $hash The Image hash
* @param string $organization Optional organization name
*
* @throws GuzzleException
* @throws \RuntimeException
*/
public function setLocked($locked, $hash, $organization = ''): SourceImage
{
$callOptions = [];
$callOptions['json'] = $locked;

$path = implode('/', [
self::SOURCEIMAGE_RESOURCE,
$this->getOrganizationName($organization),
$hash,
'options',
'locked',
]);

$response = $this->call('PUT', $path, $callOptions);
if (!($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) {
throw new \LogicException($response->getBody()->getContents(), $response->getStatusCode());
}
$content = $response->getBody()->getContents();

return SourceImage::createFromJsonResponse($content);
}

/**
* @param string $hash
* @param string|null $organization
Expand Down
1 change: 1 addition & 0 deletions tests/Core/SourceImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function createFromJsonDataProvider()
'created' => $image->created->format("Y-m-d\TH:i:s.uP"),
'link' => $image->link,
'protected' => $image->protected,
'locked' => $image->locked,
];

foreach ($image->dynamicMetadata as $name => $meta) {
Expand Down

0 comments on commit bcabd53

Please sign in to comment.