Skip to content
Open
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
19 changes: 19 additions & 0 deletions lib/ApiClient/AbstractApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,25 @@ public function getVideo(int $videoManagerId, string $videoId, ?VideoRequestPara
return $this->deserialize($response->getBody()->getContents(), Video::class);
}

public function getPlays(int $videoManagerId, string $videoId): int
{
$options = [
self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
'videoIds' => [
$videoId
]
];

$response = $this->makeRequest('GET', 'analytics/videos', $options);

$payload = json_decode($response->getBody()->getContents(), true);

return array_key_exists('videos', $payload) && !empty($payload['videos'])
? $payload['videos'][0]['plays']
: 0
;
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/Interfaces/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function deleteVideo(int $videoManagerId, string $videoId): void;

public function getVideo(int $videoManagerId, string $videoId, ?VideoRequestParameters $parameters = null): Video;

public function getPlays(int $videoManagerId, string $videoId): int;

public function getCount(int $videoManagerId, ?VideosRequestParameters $parameters = null): int;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace MovingImage\Test\Client\VMPro\ApiClient\Methods;

use MovingImage\Client\VMPro\Entity\Video;
use MovingImage\Test\Fixtures\Fixture;
use MovingImage\TestCase\ApiClientTestCase;

class GetPlaysTest extends ApiClientTestCase
{
public function testGetPlays()
{
$id = '74WGsUCJ3QJMjN8-LeYFpm';
$httpClient = $this->createMockGuzzleClient(200, [], Fixture::getApiResponse('getPlays'));

$client = $this->createApiClient($httpClient, $this->createSerializer());
$plays = $client->getPlays(1, $id);

self::assertSame(1, $plays);
}

public function testGetPlaysVideoDoesNotExist()
{
$id = '74WGsUCJ3QJMjN8-LeYFpm';
$httpClient = $this->createMockGuzzleClient(200, [], Fixture::getApiResponse('getPlaysEmpty'));

$client = $this->createApiClient($httpClient, $this->createSerializer());
$plays = $client->getPlays(1, $id);

self::assertSame(0, $plays);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"videos": [
{
"id": "74WGsUCJ3QJMjN8-LeYFpm",
"title": "title",
"description": "description",
"createdDate": "2023-04-11T13:17:18.755Z",
"modifiedDate": "2023-04-11T13:17:18.755Z",
"duration": 0,
"uploadedFile": "string",
"published": true,
"channels": [
{
"id": 0,
"name": "string"
}
],
"groups": [
{
"id": 0,
"name": "string"
}
],
"metadata": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
},
"plays": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"videos": []
}