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

Ability to add remote poster and thumbnails to a video #19

Open
wants to merge 2 commits 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
72 changes: 72 additions & 0 deletions lib/Brightcove/API/CMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Brightcove\Object\Video\Video;
use Brightcove\Object\Video\Source;
use Brightcove\Object\Video\Images;
use Brightcove\Object\Video\Poster;
use Brightcove\Object\Video\Thumbnail;
use Brightcove\Object\Playlist;
use Brightcove\Object\CustomFields;

Expand Down Expand Up @@ -114,6 +116,76 @@ public function deleteVideo($video_id) {
return $this->cmsRequest('DELETE', "/videos/{$video_id}", NULL);
}

/**
* Gets the data for a single poster by issuing a GET request.
*
* @return Video $video
*/
public function getPoster($video_id) {
return $this->cmsRequest('GET', "/videos/{$video_id}/assets/poster", Poster::class);
}

/**
* Creates a new poster object.
*
* @return Poster $poster
*/
public function createPoster($video_id, Poster $poster) {
return $this->cmsRequest('POST', "/videos/{$video_id}/assets/poster", Poster::class, FALSE, $poster);
}

/**
* Updates a poster object with an HTTP PATCH request.
*
* @return Poster $poster
*/
public function updatePoster($video_id, Poster $poster) {
$poster->fieldUnchanged('id');
return $this->cmsRequest('PATCH', "/videos/{$video_id}/assets/poster/{$poster->getId()}", Poster::class, FALSE, $poster);
}

/**
* Deletes a poster object.
*/
public function deletePoster($video_id, $poster_id) {
return $this->cmsRequest('DELETE', "/videos/{$video_id}/assets/poster/{$poster_id}", NULL);
}

/**
* Gets the data for a single thumbnail by issuing a GET request.
*
* @return Video $video
*/
public function getThumbnail($video_id) {
return $this->cmsRequest('GET', "/videos/{$video_id}/assets/thumbnail", Thumbnail::class);
}

/**
* Creates a new thumbnail object.
*
* @return Poster $thumbnail
*/
public function createThumbnail($video_id, Thumbnail $thumbnail) {
return $this->cmsRequest('POST', "/videos/{$video_id}/assets/thumbnail", Thumbnail::class, FALSE, $thumbnail);
}

/**
* Updates a thumbnail object with an HTTP PATCH request.
*
* @return Poster $thumbnail
*/
public function updateThumbnail($video_id, Thumbnail $thumbnail) {
$poster->fieldUnchanged('id');
return $this->cmsRequest('PATCH', "/videos/{$video_id}/assets/thumbnail/{$thumbnail->getId()}", Thumbnail::class, FALSE, $thumbnail);
}

/**
* Deletes a thumbnail object.
*/
public function deleteThumbnail($video_id, $thumbnail_id) {
return $this->cmsRequest('DELETE', "/videos/{$video_id}/assets/thumbnail/{$thumbnail_id}", NULL);
}

/**
* @return int
*/
Expand Down
5 changes: 1 addition & 4 deletions lib/Brightcove/Object/ObjectBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function canonicalFieldName($name) {
public function postJSON() {
$data = [];
foreach ($this as $field => $val) {
if ($field === 'changedFields' || $field === 'fieldAliases' || $val === NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check removed?

if ($field === 'changedFields' || $field === 'fieldAliases') {
continue;
}
$field = $this->canonicalFieldName($field);
Expand Down Expand Up @@ -84,9 +84,6 @@ public function patchJSON() {
$data = [];
foreach ($this->changedFields as $field) {
$val = $this->{$field};
if ($val === NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check removed?

continue;
}

$field = $this->canonicalFieldName($field);

Expand Down
53 changes: 53 additions & 0 deletions lib/Brightcove/Object/Video/Poster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Brightcove\Object\Video;

use Brightcove\Object\ObjectBase;

/**
* Poster image
*/
class Poster extends ObjectBase {
protected $id;
protected $remote_url;

public function applyJSON(array $json) {
parent::applyJSON($json);
$this->applyProperty($json, 'id');
$this->applyProperty($json, 'remote_url');
}

/**
* @return string
*/
public function getId() {
return $this->id;
}

/**
* @param string $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
$this->fieldChanged('id');
return $this;
}

/**
* @return string
*/
public function getRemoteUrl() {
return $this->remote_url;
}

/**
* @param string $remote_url
* @return $this
*/
public function setRemoteUrl($remote_url) {
$this->remote_url = $remote_url;
$this->fieldChanged('remote_url');
return $this;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

53 changes: 53 additions & 0 deletions lib/Brightcove/Object/Video/Thumbnail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Brightcove\Object\Video;

use Brightcove\Object\ObjectBase;

/**
* Thumbnail image
*/
class Thumbnail extends ObjectBase {
protected $id;
protected $remote_url;

public function applyJSON(array $json) {
parent::applyJSON($json);
$this->applyProperty($json, 'id');
$this->applyProperty($json, 'remote_url');
}

/**
* @return string
*/
public function getId() {
return $this->id;
}

/**
* @param string $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
$this->fieldChanged('id');
return $this;
}

/**
* @return string
*/
public function getRemoteUrl() {
return $this->remote_url;
}

/**
* @param string $remote_url
* @return $this
*/
public function setRemoteUrl($remote_url) {
$this->remote_url = $remote_url;
$this->fieldChanged('remote_url');
return $this;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.