Skip to content

Commit

Permalink
Implement Stream API Get Video Play Data get endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ToshY committed Apr 8, 2024
1 parent aa1bca0 commit 63849f7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
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

0 comments on commit 63849f7

Please sign in to comment.