github.com/twilio/twilio-go@v1.20.1/rest/video/v1/composition_hooks.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Video 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "net/url" 21 "strings" 22 "time" 23 24 "github.com/twilio/twilio-go/client" 25 ) 26 27 // Optional parameters for the method 'CreateCompositionHook' 28 type CreateCompositionHookParams struct { 29 // A descriptive string that you create to describe the resource. It can be up to 100 characters long and it must be unique within the account. 30 FriendlyName *string `json:"FriendlyName,omitempty"` 31 // Whether the composition hook is active. When `true`, the composition hook will be triggered for every completed Group Room in the account. When `false`, the composition hook will never be triggered. 32 Enabled *bool `json:"Enabled,omitempty"` 33 // An object that describes the video layout of the composition hook in terms of regions. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 34 VideoLayout *interface{} `json:"VideoLayout,omitempty"` 35 // An array of track names from the same group room to merge into the compositions created by the composition hook. Can include zero or more track names. A composition triggered by the composition hook includes all audio sources specified in `audio_sources` except those specified in `audio_sources_excluded`. The track names in this parameter can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, `student*` includes tracks named `student` as well as `studentTeam`. 36 AudioSources *[]string `json:"AudioSources,omitempty"` 37 // An array of track names to exclude. A composition triggered by the composition hook includes all audio sources specified in `audio_sources` except for those specified in `audio_sources_excluded`. The track names in this parameter can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, `student*` excludes `student` as well as `studentTeam`. This parameter can also be empty. 38 AudioSourcesExcluded *[]string `json:"AudioSourcesExcluded,omitempty"` 39 // A string that describes the columns (width) and rows (height) of the generated composed video in pixels. Defaults to `640x480`. The string's format is `{width}x{height}` where: * 16 <= `{width}` <= 1280 * 16 <= `{height}` <= 1280 * `{width}` * `{height}` <= 921,600 Typical values are: * HD = `1280x720` * PAL = `1024x576` * VGA = `640x480` * CIF = `320x240` Note that the `resolution` imposes an aspect ratio to the resulting composition. When the original video tracks are constrained by the aspect ratio, they are scaled to fit. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 40 Resolution *string `json:"Resolution,omitempty"` 41 // 42 Format *string `json:"Format,omitempty"` 43 // The URL we should call using the `status_callback_method` to send status information to your application on every composition event. If not provided, status callback events will not be dispatched. 44 StatusCallback *string `json:"StatusCallback,omitempty"` 45 // The HTTP method we should use to call `status_callback`. Can be: `POST` or `GET` and the default is `POST`. 46 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 47 // Whether to clip the intervals where there is no active media in the Compositions triggered by the composition hook. The default is `true`. Compositions with `trim` enabled are shorter when the Room is created and no Participant joins for a while as well as if all the Participants leave the room and join later, because those gaps will be removed. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 48 Trim *bool `json:"Trim,omitempty"` 49 } 50 51 func (params *CreateCompositionHookParams) SetFriendlyName(FriendlyName string) *CreateCompositionHookParams { 52 params.FriendlyName = &FriendlyName 53 return params 54 } 55 func (params *CreateCompositionHookParams) SetEnabled(Enabled bool) *CreateCompositionHookParams { 56 params.Enabled = &Enabled 57 return params 58 } 59 func (params *CreateCompositionHookParams) SetVideoLayout(VideoLayout interface{}) *CreateCompositionHookParams { 60 params.VideoLayout = &VideoLayout 61 return params 62 } 63 func (params *CreateCompositionHookParams) SetAudioSources(AudioSources []string) *CreateCompositionHookParams { 64 params.AudioSources = &AudioSources 65 return params 66 } 67 func (params *CreateCompositionHookParams) SetAudioSourcesExcluded(AudioSourcesExcluded []string) *CreateCompositionHookParams { 68 params.AudioSourcesExcluded = &AudioSourcesExcluded 69 return params 70 } 71 func (params *CreateCompositionHookParams) SetResolution(Resolution string) *CreateCompositionHookParams { 72 params.Resolution = &Resolution 73 return params 74 } 75 func (params *CreateCompositionHookParams) SetFormat(Format string) *CreateCompositionHookParams { 76 params.Format = &Format 77 return params 78 } 79 func (params *CreateCompositionHookParams) SetStatusCallback(StatusCallback string) *CreateCompositionHookParams { 80 params.StatusCallback = &StatusCallback 81 return params 82 } 83 func (params *CreateCompositionHookParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateCompositionHookParams { 84 params.StatusCallbackMethod = &StatusCallbackMethod 85 return params 86 } 87 func (params *CreateCompositionHookParams) SetTrim(Trim bool) *CreateCompositionHookParams { 88 params.Trim = &Trim 89 return params 90 } 91 92 // 93 func (c *ApiService) CreateCompositionHook(params *CreateCompositionHookParams) (*VideoV1CompositionHook, error) { 94 path := "/v1/CompositionHooks" 95 96 data := url.Values{} 97 headers := make(map[string]interface{}) 98 99 if params != nil && params.FriendlyName != nil { 100 data.Set("FriendlyName", *params.FriendlyName) 101 } 102 if params != nil && params.Enabled != nil { 103 data.Set("Enabled", fmt.Sprint(*params.Enabled)) 104 } 105 if params != nil && params.VideoLayout != nil { 106 v, err := json.Marshal(params.VideoLayout) 107 108 if err != nil { 109 return nil, err 110 } 111 112 data.Set("VideoLayout", string(v)) 113 } 114 if params != nil && params.AudioSources != nil { 115 for _, item := range *params.AudioSources { 116 data.Add("AudioSources", item) 117 } 118 } 119 if params != nil && params.AudioSourcesExcluded != nil { 120 for _, item := range *params.AudioSourcesExcluded { 121 data.Add("AudioSourcesExcluded", item) 122 } 123 } 124 if params != nil && params.Resolution != nil { 125 data.Set("Resolution", *params.Resolution) 126 } 127 if params != nil && params.Format != nil { 128 data.Set("Format", *params.Format) 129 } 130 if params != nil && params.StatusCallback != nil { 131 data.Set("StatusCallback", *params.StatusCallback) 132 } 133 if params != nil && params.StatusCallbackMethod != nil { 134 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 135 } 136 if params != nil && params.Trim != nil { 137 data.Set("Trim", fmt.Sprint(*params.Trim)) 138 } 139 140 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 141 if err != nil { 142 return nil, err 143 } 144 145 defer resp.Body.Close() 146 147 ps := &VideoV1CompositionHook{} 148 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 149 return nil, err 150 } 151 152 return ps, err 153 } 154 155 // Delete a Recording CompositionHook resource identified by a `CompositionHook SID`. 156 func (c *ApiService) DeleteCompositionHook(Sid string) error { 157 path := "/v1/CompositionHooks/{Sid}" 158 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 159 160 data := url.Values{} 161 headers := make(map[string]interface{}) 162 163 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 164 if err != nil { 165 return err 166 } 167 168 defer resp.Body.Close() 169 170 return nil 171 } 172 173 // Returns a single CompositionHook resource identified by a CompositionHook SID. 174 func (c *ApiService) FetchCompositionHook(Sid string) (*VideoV1CompositionHook, error) { 175 path := "/v1/CompositionHooks/{Sid}" 176 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 177 178 data := url.Values{} 179 headers := make(map[string]interface{}) 180 181 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 182 if err != nil { 183 return nil, err 184 } 185 186 defer resp.Body.Close() 187 188 ps := &VideoV1CompositionHook{} 189 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 190 return nil, err 191 } 192 193 return ps, err 194 } 195 196 // Optional parameters for the method 'ListCompositionHook' 197 type ListCompositionHookParams struct { 198 // Read only CompositionHook resources with an `enabled` value that matches this parameter. 199 Enabled *bool `json:"Enabled,omitempty"` 200 // Read only CompositionHook resources created on or after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime with time zone. 201 DateCreatedAfter *time.Time `json:"DateCreatedAfter,omitempty"` 202 // Read only CompositionHook resources created before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime with time zone. 203 DateCreatedBefore *time.Time `json:"DateCreatedBefore,omitempty"` 204 // Read only CompositionHook resources with friendly names that match this string. The match is not case sensitive and can include asterisk `*` characters as wildcard match. 205 FriendlyName *string `json:"FriendlyName,omitempty"` 206 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 207 PageSize *int `json:"PageSize,omitempty"` 208 // Max number of records to return. 209 Limit *int `json:"limit,omitempty"` 210 } 211 212 func (params *ListCompositionHookParams) SetEnabled(Enabled bool) *ListCompositionHookParams { 213 params.Enabled = &Enabled 214 return params 215 } 216 func (params *ListCompositionHookParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *ListCompositionHookParams { 217 params.DateCreatedAfter = &DateCreatedAfter 218 return params 219 } 220 func (params *ListCompositionHookParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *ListCompositionHookParams { 221 params.DateCreatedBefore = &DateCreatedBefore 222 return params 223 } 224 func (params *ListCompositionHookParams) SetFriendlyName(FriendlyName string) *ListCompositionHookParams { 225 params.FriendlyName = &FriendlyName 226 return params 227 } 228 func (params *ListCompositionHookParams) SetPageSize(PageSize int) *ListCompositionHookParams { 229 params.PageSize = &PageSize 230 return params 231 } 232 func (params *ListCompositionHookParams) SetLimit(Limit int) *ListCompositionHookParams { 233 params.Limit = &Limit 234 return params 235 } 236 237 // Retrieve a single page of CompositionHook records from the API. Request is executed immediately. 238 func (c *ApiService) PageCompositionHook(params *ListCompositionHookParams, pageToken, pageNumber string) (*ListCompositionHookResponse, error) { 239 path := "/v1/CompositionHooks" 240 241 data := url.Values{} 242 headers := make(map[string]interface{}) 243 244 if params != nil && params.Enabled != nil { 245 data.Set("Enabled", fmt.Sprint(*params.Enabled)) 246 } 247 if params != nil && params.DateCreatedAfter != nil { 248 data.Set("DateCreatedAfter", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) 249 } 250 if params != nil && params.DateCreatedBefore != nil { 251 data.Set("DateCreatedBefore", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) 252 } 253 if params != nil && params.FriendlyName != nil { 254 data.Set("FriendlyName", *params.FriendlyName) 255 } 256 if params != nil && params.PageSize != nil { 257 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 258 } 259 260 if pageToken != "" { 261 data.Set("PageToken", pageToken) 262 } 263 if pageNumber != "" { 264 data.Set("Page", pageNumber) 265 } 266 267 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 268 if err != nil { 269 return nil, err 270 } 271 272 defer resp.Body.Close() 273 274 ps := &ListCompositionHookResponse{} 275 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 276 return nil, err 277 } 278 279 return ps, err 280 } 281 282 // Lists CompositionHook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 283 func (c *ApiService) ListCompositionHook(params *ListCompositionHookParams) ([]VideoV1CompositionHook, error) { 284 response, errors := c.StreamCompositionHook(params) 285 286 records := make([]VideoV1CompositionHook, 0) 287 for record := range response { 288 records = append(records, record) 289 } 290 291 if err := <-errors; err != nil { 292 return nil, err 293 } 294 295 return records, nil 296 } 297 298 // Streams CompositionHook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 299 func (c *ApiService) StreamCompositionHook(params *ListCompositionHookParams) (chan VideoV1CompositionHook, chan error) { 300 if params == nil { 301 params = &ListCompositionHookParams{} 302 } 303 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 304 305 recordChannel := make(chan VideoV1CompositionHook, 1) 306 errorChannel := make(chan error, 1) 307 308 response, err := c.PageCompositionHook(params, "", "") 309 if err != nil { 310 errorChannel <- err 311 close(recordChannel) 312 close(errorChannel) 313 } else { 314 go c.streamCompositionHook(response, params, recordChannel, errorChannel) 315 } 316 317 return recordChannel, errorChannel 318 } 319 320 func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse, params *ListCompositionHookParams, recordChannel chan VideoV1CompositionHook, errorChannel chan error) { 321 curRecord := 1 322 323 for response != nil { 324 responseRecords := response.CompositionHooks 325 for item := range responseRecords { 326 recordChannel <- responseRecords[item] 327 curRecord += 1 328 if params.Limit != nil && *params.Limit < curRecord { 329 close(recordChannel) 330 close(errorChannel) 331 return 332 } 333 } 334 335 record, err := client.GetNext(c.baseURL, response, c.getNextListCompositionHookResponse) 336 if err != nil { 337 errorChannel <- err 338 break 339 } else if record == nil { 340 break 341 } 342 343 response = record.(*ListCompositionHookResponse) 344 } 345 346 close(recordChannel) 347 close(errorChannel) 348 } 349 350 func (c *ApiService) getNextListCompositionHookResponse(nextPageUrl string) (interface{}, error) { 351 if nextPageUrl == "" { 352 return nil, nil 353 } 354 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 355 if err != nil { 356 return nil, err 357 } 358 359 defer resp.Body.Close() 360 361 ps := &ListCompositionHookResponse{} 362 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 363 return nil, err 364 } 365 return ps, nil 366 } 367 368 // Optional parameters for the method 'UpdateCompositionHook' 369 type UpdateCompositionHookParams struct { 370 // A descriptive string that you create to describe the resource. It can be up to 100 characters long and it must be unique within the account. 371 FriendlyName *string `json:"FriendlyName,omitempty"` 372 // Whether the composition hook is active. When `true`, the composition hook will be triggered for every completed Group Room in the account. When `false`, the composition hook never triggers. 373 Enabled *bool `json:"Enabled,omitempty"` 374 // A JSON object that describes the video layout of the composition hook in terms of regions. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 375 VideoLayout *interface{} `json:"VideoLayout,omitempty"` 376 // An array of track names from the same group room to merge into the compositions created by the composition hook. Can include zero or more track names. A composition triggered by the composition hook includes all audio sources specified in `audio_sources` except those specified in `audio_sources_excluded`. The track names in this parameter can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, `student*` includes tracks named `student` as well as `studentTeam`. 377 AudioSources *[]string `json:"AudioSources,omitempty"` 378 // An array of track names to exclude. A composition triggered by the composition hook includes all audio sources specified in `audio_sources` except for those specified in `audio_sources_excluded`. The track names in this parameter can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, `student*` excludes `student` as well as `studentTeam`. This parameter can also be empty. 379 AudioSourcesExcluded *[]string `json:"AudioSourcesExcluded,omitempty"` 380 // Whether to clip the intervals where there is no active media in the compositions triggered by the composition hook. The default is `true`. Compositions with `trim` enabled are shorter when the Room is created and no Participant joins for a while as well as if all the Participants leave the room and join later, because those gaps will be removed. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 381 Trim *bool `json:"Trim,omitempty"` 382 // 383 Format *string `json:"Format,omitempty"` 384 // A string that describes the columns (width) and rows (height) of the generated composed video in pixels. Defaults to `640x480`. The string's format is `{width}x{height}` where: * 16 <= `{width}` <= 1280 * 16 <= `{height}` <= 1280 * `{width}` * `{height}` <= 921,600 Typical values are: * HD = `1280x720` * PAL = `1024x576` * VGA = `640x480` * CIF = `320x240` Note that the `resolution` imposes an aspect ratio to the resulting composition. When the original video tracks are constrained by the aspect ratio, they are scaled to fit. See [Specifying Video Layouts](https://www.twilio.com/docs/video/api/compositions-resource#specifying-video-layouts) for more info. 385 Resolution *string `json:"Resolution,omitempty"` 386 // The URL we should call using the `status_callback_method` to send status information to your application on every composition event. If not provided, status callback events will not be dispatched. 387 StatusCallback *string `json:"StatusCallback,omitempty"` 388 // The HTTP method we should use to call `status_callback`. Can be: `POST` or `GET` and the default is `POST`. 389 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 390 } 391 392 func (params *UpdateCompositionHookParams) SetFriendlyName(FriendlyName string) *UpdateCompositionHookParams { 393 params.FriendlyName = &FriendlyName 394 return params 395 } 396 func (params *UpdateCompositionHookParams) SetEnabled(Enabled bool) *UpdateCompositionHookParams { 397 params.Enabled = &Enabled 398 return params 399 } 400 func (params *UpdateCompositionHookParams) SetVideoLayout(VideoLayout interface{}) *UpdateCompositionHookParams { 401 params.VideoLayout = &VideoLayout 402 return params 403 } 404 func (params *UpdateCompositionHookParams) SetAudioSources(AudioSources []string) *UpdateCompositionHookParams { 405 params.AudioSources = &AudioSources 406 return params 407 } 408 func (params *UpdateCompositionHookParams) SetAudioSourcesExcluded(AudioSourcesExcluded []string) *UpdateCompositionHookParams { 409 params.AudioSourcesExcluded = &AudioSourcesExcluded 410 return params 411 } 412 func (params *UpdateCompositionHookParams) SetTrim(Trim bool) *UpdateCompositionHookParams { 413 params.Trim = &Trim 414 return params 415 } 416 func (params *UpdateCompositionHookParams) SetFormat(Format string) *UpdateCompositionHookParams { 417 params.Format = &Format 418 return params 419 } 420 func (params *UpdateCompositionHookParams) SetResolution(Resolution string) *UpdateCompositionHookParams { 421 params.Resolution = &Resolution 422 return params 423 } 424 func (params *UpdateCompositionHookParams) SetStatusCallback(StatusCallback string) *UpdateCompositionHookParams { 425 params.StatusCallback = &StatusCallback 426 return params 427 } 428 func (params *UpdateCompositionHookParams) SetStatusCallbackMethod(StatusCallbackMethod string) *UpdateCompositionHookParams { 429 params.StatusCallbackMethod = &StatusCallbackMethod 430 return params 431 } 432 433 // 434 func (c *ApiService) UpdateCompositionHook(Sid string, params *UpdateCompositionHookParams) (*VideoV1CompositionHook, error) { 435 path := "/v1/CompositionHooks/{Sid}" 436 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 437 438 data := url.Values{} 439 headers := make(map[string]interface{}) 440 441 if params != nil && params.FriendlyName != nil { 442 data.Set("FriendlyName", *params.FriendlyName) 443 } 444 if params != nil && params.Enabled != nil { 445 data.Set("Enabled", fmt.Sprint(*params.Enabled)) 446 } 447 if params != nil && params.VideoLayout != nil { 448 v, err := json.Marshal(params.VideoLayout) 449 450 if err != nil { 451 return nil, err 452 } 453 454 data.Set("VideoLayout", string(v)) 455 } 456 if params != nil && params.AudioSources != nil { 457 for _, item := range *params.AudioSources { 458 data.Add("AudioSources", item) 459 } 460 } 461 if params != nil && params.AudioSourcesExcluded != nil { 462 for _, item := range *params.AudioSourcesExcluded { 463 data.Add("AudioSourcesExcluded", item) 464 } 465 } 466 if params != nil && params.Trim != nil { 467 data.Set("Trim", fmt.Sprint(*params.Trim)) 468 } 469 if params != nil && params.Format != nil { 470 data.Set("Format", *params.Format) 471 } 472 if params != nil && params.Resolution != nil { 473 data.Set("Resolution", *params.Resolution) 474 } 475 if params != nil && params.StatusCallback != nil { 476 data.Set("StatusCallback", *params.StatusCallback) 477 } 478 if params != nil && params.StatusCallbackMethod != nil { 479 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 480 } 481 482 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 483 if err != nil { 484 return nil, err 485 } 486 487 defer resp.Body.Close() 488 489 ps := &VideoV1CompositionHook{} 490 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 491 return nil, err 492 } 493 494 return ps, err 495 }