Skip to content

Commit

Permalink
Implement Stream API OEmbed get endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ToshY committed Apr 8, 2024
1 parent 1610c8c commit e9e5b13
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/stream-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ $streamApi->deleteCaption(

- The `sourceLanguage` is the [language shortcode](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) for the caption.

#### [Get OEmbed](https://docs.bunny.net/reference/oembed_getoembed)

```php
$streamApi->getOEmbed(
query: [
'url' => 'https://iframe.mediadelivery.net/embed/182595/8a800e53-c949-46d0-8818-af566f032ec1',
'maxWidth' => 1280,
'maxHeight' => 720,
'token' => null,
'expires' => 123,
],
);
```

!!! note

- The `url` is a required query parameter.

## Reference

* [Stream API](https://docs.bunny.net/reference/api-overview)
43 changes: 43 additions & 0 deletions src/Model/API/Stream/OEmbed/GetOEmbed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace ToshY\BunnyNet\Model\API\Stream\OEmbed;

use ToshY\BunnyNet\Enum\Header;
use ToshY\BunnyNet\Enum\Method;
use ToshY\BunnyNet\Enum\Type;
use ToshY\BunnyNet\Model\AbstractParameter;
use ToshY\BunnyNet\Model\EndpointInterface;
use ToshY\BunnyNet\Model\EndpointQueryInterface;

class GetOEmbed implements EndpointInterface, EndpointQueryInterface
{
public function getMethod(): Method
{
return Method::GET;
}

public function getPath(): string
{
return 'OEmbed';
}

public function getHeaders(): array
{
return [
Header::ACCEPT_JSON,
];
}

public function getQuery(): array
{
return [
new AbstractParameter(name: 'url', type: Type::STRING_TYPE, required: true),
new AbstractParameter(name: 'maxWidth', type: Type::INT_TYPE),
new AbstractParameter(name: 'maxHeight', type: Type::INT_TYPE),
new AbstractParameter(name: 'token', type: Type::STRING_TYPE),
new AbstractParameter(name: 'expires', type: Type::INT_TYPE),
];
}
}
24 changes: 24 additions & 0 deletions src/StreamAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\SetThumbnailByBody;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\UpdateVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\UploadVideo;
use ToshY\BunnyNet\Model\API\Stream\OEmbed\GetOEmbed;
use ToshY\BunnyNet\Model\Client\Interface\BunnyClientResponseInterface;
use ToshY\BunnyNet\Validator\ParameterValidator;

Expand Down Expand Up @@ -525,4 +526,27 @@ public function deleteCaption(
parameters: [$libraryId, $videoId, $sourceLanguage],
);
}

/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
* @throws Exception\JSONException
* @throws Exception\InvalidTypeForKeyValueException
* @throws Exception\InvalidTypeForListValueException
* @throws Exception\ParameterIsRequiredException
* @param array<string,mixed> $query
* @return BunnyClientResponseInterface
*/
public function getOEmbed(
array $query,
): BunnyClientResponseInterface {
$endpoint = new GetOEmbed();

ParameterValidator::validate($query, $endpoint->getQuery());

return $this->client->request(
endpoint: $endpoint,
query: $query,
);
}
}

0 comments on commit e9e5b13

Please sign in to comment.