Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Stream API Get Video Play Data get endpoint #118

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/stream-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ $streamApi->getVideoHeatmap(
```
A support ticket has been created at bunny.net regarding this issue.

#### [Get Video Play Data](https://docs.bunny.net/reference/video_getvideoplaydata)

```php
$streamApi->getVideoPlayData(
libraryId: 1,
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
query: [
'token' => 'ead85f9a-578b-42b7-985f-9a578b12b776',
'expires' => 3600,
],
);
```

#### [Get Video Statistics](https://docs.bunny.net/reference/video_getvideostatistics)

```php
Expand Down
40 changes: 40 additions & 0 deletions src/Model/API/Stream/ManageVideos/GetVideoPlayData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

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

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 GetVideoPlayData implements EndpointInterface, EndpointQueryInterface
{
public function getMethod(): Method
{
return Method::GET;
}

public function getPath(): string
{
return 'library/%d/videos/%s/play';
}

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

public function getQuery(): array
{
return [
new AbstractParameter(name: 'token', type: Type::STRING_TYPE),
new AbstractParameter(name: 'expires', type: Type::INT_TYPE),
];
}
}
34 changes: 34 additions & 0 deletions src/StreamAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use Psr\Http\Client\ClientExceptionInterface;
use ToshY\BunnyNet\Client\BunnyClient;
use ToshY\BunnyNet\Enum\Host;
use ToshY\BunnyNet\Exception\BunnyClientResponseException;
use ToshY\BunnyNet\Exception\InvalidTypeForKeyValueException;
use ToshY\BunnyNet\Exception\InvalidTypeForListValueException;
use ToshY\BunnyNet\Exception\JSONException;
use ToshY\BunnyNet\Exception\ParameterIsRequiredException;
use ToshY\BunnyNet\Helper\BodyContentHelper;
use ToshY\BunnyNet\Model\API\Stream\ManageCollections\CreateCollection;
use ToshY\BunnyNet\Model\API\Stream\ManageCollections\DeleteCollection;
Expand All @@ -20,6 +25,7 @@
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\FetchVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideoHeatmap;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideoPlayData;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideos;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideoStatistics;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ReEncodeVideo;
Expand Down Expand Up @@ -319,6 +325,34 @@ public function getVideoHeatmap(
);
}

/**
* @throws ClientExceptionInterface
* @throws BunnyClientResponseException
* @throws InvalidTypeForKeyValueException
* @throws InvalidTypeForListValueException
* @throws JSONException
* @throws ParameterIsRequiredException
* @param int $libraryId
* @param string $videoId
* @param array<string,mixed> $query
* @return BunnyClientResponseInterface
*/
public function getVideoPlayData(
int $libraryId,
string $videoId,
array $query = [],
): BunnyClientResponseInterface {
$endpoint = new GetVideoPlayData();

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

return $this->client->request(
endpoint: $endpoint,
parameters: [$libraryId, $videoId],
query: $query,
);
}

/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
Expand Down