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

Add list and count videos by folder on CMS #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions lib/Brightcove/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,32 @@ public function __construct(Client $client, $account) {
$this->client = $client;
$this->account = $account;
}

/**
* Formats search terms.
*
* @return string
* Basic search tearms formatted (e.g ?q=tag:example)
*/
protected function formatSearchTerms($search = NULL, $sort = NULL, $limit = NULL, $offset = NULL) {
$query = '';
if ($search) {
$query .= '&q=' . urlencode($search);
}
if ($sort) {
$query .= "&sort={$sort}";
}
if ($limit) {
$query .= "&limit={$limit}";
}
if ($offset) {
$query .= "&offset={$offset}";
}
if (strlen($query) > 0) {
$query = '?' . substr($query, 1);
}

return $query;
}

}
48 changes: 31 additions & 17 deletions lib/Brightcove/API/CMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,11 @@ protected function cmsRequest($method, $endpoint, $result, $is_array = FALSE, $p
/**
* Lists video objects with the given restrictions.
*
* @return Video[]
* @return Brightcove\Object\Video[]
* Video objects.
*/
public function listVideos($search = NULL, $sort = NULL, $limit = NULL, $offset = NULL) {
$query = '';
if ($search) {
$query .= '&q=' . urlencode($search);
}
if ($sort) {
$query .= "&sort={$sort}";
}
if ($limit) {
$query .= "&limit={$limit}";
}
if ($offset) {
$query .= "&offset={$offset}";
}
if (strlen($query) > 0) {
$query = '?' . substr($query, 1);
}
$query = $this->formatSearchTerms($search, $sort, $limit, $offset);
return $this->cmsRequest('GET', "/videos{$query}", Video::class, TRUE);
}

Expand All @@ -59,6 +45,34 @@ public function countVideos($search = NULL) {
return NULL;
}

/**
* Lists video objects in a folder with the given restrictions.
*
* @return Brightcove\Object\Video[]
* Video objects in a folder.
*/
public function listVideosInFolder($folder_id, $search = NULL, $sort = NULL, $limit = NULL, $offset = NULL) {
$query = $this->formatSearchTerms($search, $sort, $limit, $offset);
return $this->cmsRequest('GET', "/folders/{$folder_id}/videos{$query}", Video::class, TRUE);
}

/**
* Returns the amount of a searched folder video's result.
*
* @param int $folder_id
* Folder ID.
*
* @return int|null
* Amount of a searched folder video's result.
*/
public function countVideosInFolder($folder_id) {
$result = $this->cmsRequest('GET', "/folders/{$folder_id}", NULL);
if ($result && !empty($result['video_count'])) {
return $result['video_count'];
}
return NULL;
}

/**
* Gets the images for a single video.
*
Expand Down