From 4c36104970c3b1d21c1955345c8ec67e0cdeb252 Mon Sep 17 00:00:00 2001 From: szekelyzol Date: Wed, 13 Nov 2024 14:02:05 +0000 Subject: [PATCH] Add new webhooks --- docs/Api/WebhooksApi.md | 12 ++++++---- docs/Model/WebhooksCreationPayload.md | 2 +- src/Model/Webhook.php | 32 +++++++++++++++++++++++++ src/Model/WebhooksCreationPayload.php | 34 ++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/docs/Api/WebhooksApi.md b/docs/Api/WebhooksApi.md index fe64ddc..8c8b95b 100644 --- a/docs/Api/WebhooksApi.md +++ b/docs/Api/WebhooksApi.md @@ -16,13 +16,17 @@ Method | Description | HTTP request Webhooks can push notifications to your server, rather than polling api.video for changes. We currently offer four events: -* ```video.encoding.quality.completed``` Occurs when a new video is uploaded into your account, it will be encoded into several different HLS and mp4 qualities. When each version is encoded, your webhook will get a notification. It will look like ```{ "type": "video.encoding.quality.completed", "emittedAt": "2021-01-29T16:46:25.217+01:00", "videoId": "viXXXXXXXX", "encoding": "hls", "quality": "720p"} ```. This request says that the 720p HLS encoding was completed. +* `video.encoding.quality.completed` Occurs when a new video is uploaded into your account, it will be encoded into several different HLS and mp4 qualities. When each version is encoded, your webhook will get a notification. It will look like ```{ "type": "video.encoding.quality.completed", "emittedAt": "2021-01-29T16:46:25.217+01:00", "videoId": "viXXXXXXXX", "encoding": "hls", "quality": "720p"} ```. This request says that the 720p HLS encoding was completed. -* ```live-stream.broadcast.started``` When a live stream begins broadcasting, the broadcasting parameter changes from false to true, and this webhook fires. +* `live-stream.broadcast.started` When a live stream begins broadcasting, the broadcasting parameter changes from false to true, and this webhook fires. -* ```live-stream.broadcast.ended``` This event fires when a live stream has finished broadcasting. +* `live-stream.broadcast.ended` This event fires when a live stream has finished broadcasting. -* ```video.source.recorded``` This event occurs when a live stream is recorded and submitted for encoding. +* `video.source.recorded` This event occurs when a live stream is recorded and submitted for encoding. + +* `video.caption.generated` This event occurs when an automatic caption has been generated. + +* `video.summary.generated` This event occurs when an automatic summary has been generated. ### Arguments diff --git a/docs/Model/WebhooksCreationPayload.md b/docs/Model/WebhooksCreationPayload.md index 0b160af..b40964a 100644 --- a/docs/Model/WebhooksCreationPayload.md +++ b/docs/Model/WebhooksCreationPayload.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**events** | **string[]** | A list of the webhooks that you are subscribing to. There are Currently four webhook options: * ```video.encoding.quality.completed``` Occurs when a new video is uploaded into your account, it will be encoded into several different HLS and mp4 qualities. When each version is encoded, your webhook will get a notification. It will look like ```{ \\\"type\\\": \\\"video.encoding.quality.completed\\\", \\\"emittedAt\\\": \\\"2021-01-29T16:46:25.217+01:00\\\", \\\"videoId\\\": \\\"viXXXXXXXX\\\", \\\"encoding\\\": \\\"hls\\\", \\\"quality\\\": \\\"720p\\\"} ```. This request says that the 720p HLS encoding was completed. * ```live-stream.broadcast.started``` When a live stream begins broadcasting, the broadcasting parameter changes from false to true, and this webhook fires. * ```live-stream.broadcast.ended``` This event fires when a live stream has finished broadcasting. * ```video.source.recorded``` Occurs when a live stream is recorded and submitted for encoding. | +**events** | **string[]** | An array of webhook events that you want to subscribe to. | **url** | **string** | The the url to which HTTP notifications are sent. It could be any http or https URL. | [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/src/Model/Webhook.php b/src/Model/Webhook.php index 34b944a..9cf73df 100644 --- a/src/Model/Webhook.php +++ b/src/Model/Webhook.php @@ -76,6 +76,29 @@ public static function getDefinition(): ModelDefinition ); } + const EVENTS_LIVE_STREAM_BROADCAST_STARTED = 'live-stream.broadcast.started'; + const EVENTS_LIVE_STREAM_BROADCAST_ENDED = 'live-stream.broadcast.ended'; + const EVENTS_VIDEO_SOURCE_RECORDED = 'video.source.recorded'; + const EVENTS_VIDEO_ENCODING_QUALITY_COMPLETED = 'video.encoding.quality.completed'; + const EVENTS_VIDEO_CAPTION_GENERATED = 'video.caption.generated'; + const EVENTS_VIDEO_SUMMARY_GENERATED = 'video.summary.generated'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getEventsAllowableValues() + { + return [ + self::EVENTS_LIVE_STREAM_BROADCAST_STARTED, + self::EVENTS_LIVE_STREAM_BROADCAST_ENDED, + self::EVENTS_VIDEO_SOURCE_RECORDED, + self::EVENTS_VIDEO_ENCODING_QUALITY_COMPLETED, + self::EVENTS_VIDEO_CAPTION_GENERATED, + self::EVENTS_VIDEO_SUMMARY_GENERATED, + ]; + } /** * Associative array for storing property values @@ -190,6 +213,15 @@ public function getEvents() */ public function setEvents($events) { + $allowedValues = $this->getEventsAllowableValues(); + if (!is_null($events) && array_diff($events, $allowedValues)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value for 'events', must be one of '%s'", + implode("', '", $allowedValues) + ) + ); + } $this->container['events'] = $events; return $this; diff --git a/src/Model/WebhooksCreationPayload.php b/src/Model/WebhooksCreationPayload.php index eb026b9..6a26ce8 100644 --- a/src/Model/WebhooksCreationPayload.php +++ b/src/Model/WebhooksCreationPayload.php @@ -58,6 +58,29 @@ public static function getDefinition(): ModelDefinition ); } + const EVENTS_LIVE_STREAM_BROADCAST_STARTED = 'live-stream.broadcast.started'; + const EVENTS_LIVE_STREAM_BROADCAST_ENDED = 'live-stream.broadcast.ended'; + const EVENTS_VIDEO_SOURCE_RECORDED = 'video.source.recorded'; + const EVENTS_VIDEO_ENCODING_QUALITY_COMPLETED = 'video.encoding.quality.completed'; + const EVENTS_VIDEO_CAPTION_GENERATED = 'video.caption.generated'; + const EVENTS_VIDEO_SUMMARY_GENERATED = 'video.summary.generated'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getEventsAllowableValues() + { + return [ + self::EVENTS_LIVE_STREAM_BROADCAST_STARTED, + self::EVENTS_LIVE_STREAM_BROADCAST_ENDED, + self::EVENTS_VIDEO_SOURCE_RECORDED, + self::EVENTS_VIDEO_ENCODING_QUALITY_COMPLETED, + self::EVENTS_VIDEO_CAPTION_GENERATED, + self::EVENTS_VIDEO_SUMMARY_GENERATED, + ]; + } /** * Associative array for storing property values @@ -121,12 +144,21 @@ public function getEvents() /** * Sets events * - * @param string[] $events A list of the webhooks that you are subscribing to. There are Currently four webhook options: * ```video.encoding.quality.completed``` Occurs when a new video is uploaded into your account, it will be encoded into several different HLS and mp4 qualities. When each version is encoded, your webhook will get a notification. It will look like ```{ \\\"type\\\": \\\"video.encoding.quality.completed\\\", \\\"emittedAt\\\": \\\"2021-01-29T16:46:25.217+01:00\\\", \\\"videoId\\\": \\\"viXXXXXXXX\\\", \\\"encoding\\\": \\\"hls\\\", \\\"quality\\\": \\\"720p\\\"} ```. This request says that the 720p HLS encoding was completed. * ```live-stream.broadcast.started``` When a live stream begins broadcasting, the broadcasting parameter changes from false to true, and this webhook fires. * ```live-stream.broadcast.ended``` This event fires when a live stream has finished broadcasting. * ```video.source.recorded``` Occurs when a live stream is recorded and submitted for encoding. + * @param string[] $events An array of webhook events that you want to subscribe to. * * @return self */ public function setEvents($events) { + $allowedValues = $this->getEventsAllowableValues(); + if (array_diff($events, $allowedValues)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value for 'events', must be one of '%s'", + implode("', '", $allowedValues) + ) + ); + } $this->container['events'] = $events; return $this;