diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e625c..4914222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Core/SourceImage.php b/src/Core/SourceImage.php index e01377c..fc3ef64 100644 --- a/src/Core/SourceImage.php +++ b/src/Core/SourceImage.php @@ -90,6 +90,11 @@ class SourceImage */ public $protected; + /** + * @var bool + */ + public $locked; + /** * Constructor. * @@ -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( @@ -125,7 +131,8 @@ public function __construct( \DateTime $created, $link, $shortHash = null, - $protected = false + $protected = false, + $locked = false ) { $this->organization = $organization; $this->binaryHash = $binaryHash; @@ -146,6 +153,7 @@ public function __construct( } $this->shortHash = $shortHash; $this->protected = $protected; + $this->locked = $locked; } /** @@ -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'] ); } diff --git a/src/Image.php b/src/Image.php index ab88d3e..4af2763 100644 --- a/src/Image.php +++ b/src/Image.php @@ -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; @@ -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 diff --git a/tests/Core/SourceImageTest.php b/tests/Core/SourceImageTest.php index d0d3836..14a0cb0 100644 --- a/tests/Core/SourceImageTest.php +++ b/tests/Core/SourceImageTest.php @@ -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) {