From 70e6752cd58b304f5ca32aeea53626501b00c23a Mon Sep 17 00:00:00 2001 From: nickedwards Date: Tue, 20 Sep 2016 15:12:50 +0100 Subject: [PATCH 1/2] ability to add remote poster and thumbnails to a video --- lib/Brightcove/API/CMS.php | 72 +++++++++++++++++++++++ lib/Brightcove/Object/Video/Poster.php | 53 +++++++++++++++++ lib/Brightcove/Object/Video/Thumbnail.php | 53 +++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 lib/Brightcove/Object/Video/Poster.php create mode 100644 lib/Brightcove/Object/Video/Thumbnail.php diff --git a/lib/Brightcove/API/CMS.php b/lib/Brightcove/API/CMS.php index 8a580d7..6f3ae94 100644 --- a/lib/Brightcove/API/CMS.php +++ b/lib/Brightcove/API/CMS.php @@ -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; @@ -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 */ diff --git a/lib/Brightcove/Object/Video/Poster.php b/lib/Brightcove/Object/Video/Poster.php new file mode 100644 index 0000000..bdaf70b --- /dev/null +++ b/lib/Brightcove/Object/Video/Poster.php @@ -0,0 +1,53 @@ +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; + } +} \ No newline at end of file diff --git a/lib/Brightcove/Object/Video/Thumbnail.php b/lib/Brightcove/Object/Video/Thumbnail.php new file mode 100644 index 0000000..03f3935 --- /dev/null +++ b/lib/Brightcove/Object/Video/Thumbnail.php @@ -0,0 +1,53 @@ +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; + } +} \ No newline at end of file From 8c2f83dc85607ee3ac027c0a56faea07de84a031 Mon Sep 17 00:00:00 2001 From: nickedwards Date: Fri, 21 Oct 2016 13:46:04 +0100 Subject: [PATCH 2/2] Allow null values to be sent through the API. This is required for API functionality e.g. for schedule start_date and end_date --- lib/Brightcove/Object/ObjectBase.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Brightcove/Object/ObjectBase.php b/lib/Brightcove/Object/ObjectBase.php index 45dc526..cb05589 100644 --- a/lib/Brightcove/Object/ObjectBase.php +++ b/lib/Brightcove/Object/ObjectBase.php @@ -56,7 +56,7 @@ protected function canonicalFieldName($name) { public function postJSON() { $data = []; foreach ($this as $field => $val) { - if ($field === 'changedFields' || $field === 'fieldAliases' || $val === NULL) { + if ($field === 'changedFields' || $field === 'fieldAliases') { continue; } $field = $this->canonicalFieldName($field); @@ -84,9 +84,6 @@ public function patchJSON() { $data = []; foreach ($this->changedFields as $field) { $val = $this->{$field}; - if ($val === NULL) { - continue; - } $field = $this->canonicalFieldName($field);