Skip to content

Commit

Permalink
Support $version parameter in LinksApi (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
silasjoisten authored Oct 14, 2024
1 parent 516c817 commit fcf9b26
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/LinksApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace SensioLabs\Storyblok\Api;

use SensioLabs\Storyblok\Api\Domain\Value\Dto\Version;
use SensioLabs\Storyblok\Api\Domain\Value\Id;
use SensioLabs\Storyblok\Api\Domain\Value\Total;
use SensioLabs\Storyblok\Api\Request\LinksRequest;
Expand All @@ -25,18 +26,27 @@
final class LinksApi implements LinksApiInterface
{
private const string ENDPOINT = '/v2/cdn/links';
private Version $version;

/**
* @param 'draft'|'published' $version
*/
public function __construct(
private StoryblokClientInterface $client,
string $version = 'published', // we inject a string here, because Symfony DI does not support enums
) {
$this->version = Version::from($version);
}

public function all(?LinksRequest $request = null): LinksResponse
{
$request ??= new LinksRequest();

$response = $this->client->request('GET', self::ENDPOINT, [
'query' => $request->toArray(),
'query' => [
...$request->toArray(),
'version' => null !== $request->version ? $request->version->value : $this->version->value,
],
]);

return new LinksResponse(
Expand All @@ -54,6 +64,7 @@ public function byParent(Id $parentId, ?LinksRequest $request = null): LinksResp
'query' => [
...$request->toArray(),
'with_parent' => $parentId->value,
'version' => null !== $request->version ? $request->version->value : $this->version->value,
],
]);

Expand All @@ -72,6 +83,7 @@ public function roots(?LinksRequest $request = null): LinksResponse
'query' => [
...$request->toArray(),
'with_parent' => 0,
'version' => null !== $request->version ? $request->version->value : $this->version->value,
],
]);

Expand Down

0 comments on commit fcf9b26

Please sign in to comment.