github.com/twilio/twilio-go@v1.20.1/rest/video/v1/rooms_recordings.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 // 28 func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { 29 path := "/v1/Rooms/{RoomSid}/Recordings/{Sid}" 30 path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) 31 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 32 33 data := url.Values{} 34 headers := make(map[string]interface{}) 35 36 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 37 if err != nil { 38 return err 39 } 40 41 defer resp.Body.Close() 42 43 return nil 44 } 45 46 // 47 func (c *ApiService) FetchRoomRecording(RoomSid string, Sid string) (*VideoV1RoomRecording, error) { 48 path := "/v1/Rooms/{RoomSid}/Recordings/{Sid}" 49 path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) 50 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 51 52 data := url.Values{} 53 headers := make(map[string]interface{}) 54 55 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 56 if err != nil { 57 return nil, err 58 } 59 60 defer resp.Body.Close() 61 62 ps := &VideoV1RoomRecording{} 63 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 64 return nil, err 65 } 66 67 return ps, err 68 } 69 70 // Optional parameters for the method 'ListRoomRecording' 71 type ListRoomRecordingParams struct { 72 // Read only the recordings with this status. Can be: `processing`, `completed`, or `deleted`. 73 Status *string `json:"Status,omitempty"` 74 // Read only the recordings that have this `source_sid`. 75 SourceSid *string `json:"SourceSid,omitempty"` 76 // Read only recordings that started on or after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime with time zone. 77 DateCreatedAfter *time.Time `json:"DateCreatedAfter,omitempty"` 78 // Read only Recordings that started before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime with time zone. 79 DateCreatedBefore *time.Time `json:"DateCreatedBefore,omitempty"` 80 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 81 PageSize *int `json:"PageSize,omitempty"` 82 // Max number of records to return. 83 Limit *int `json:"limit,omitempty"` 84 } 85 86 func (params *ListRoomRecordingParams) SetStatus(Status string) *ListRoomRecordingParams { 87 params.Status = &Status 88 return params 89 } 90 func (params *ListRoomRecordingParams) SetSourceSid(SourceSid string) *ListRoomRecordingParams { 91 params.SourceSid = &SourceSid 92 return params 93 } 94 func (params *ListRoomRecordingParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *ListRoomRecordingParams { 95 params.DateCreatedAfter = &DateCreatedAfter 96 return params 97 } 98 func (params *ListRoomRecordingParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *ListRoomRecordingParams { 99 params.DateCreatedBefore = &DateCreatedBefore 100 return params 101 } 102 func (params *ListRoomRecordingParams) SetPageSize(PageSize int) *ListRoomRecordingParams { 103 params.PageSize = &PageSize 104 return params 105 } 106 func (params *ListRoomRecordingParams) SetLimit(Limit int) *ListRoomRecordingParams { 107 params.Limit = &Limit 108 return params 109 } 110 111 // Retrieve a single page of RoomRecording records from the API. Request is executed immediately. 112 func (c *ApiService) PageRoomRecording(RoomSid string, params *ListRoomRecordingParams, pageToken, pageNumber string) (*ListRoomRecordingResponse, error) { 113 path := "/v1/Rooms/{RoomSid}/Recordings" 114 115 path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) 116 117 data := url.Values{} 118 headers := make(map[string]interface{}) 119 120 if params != nil && params.Status != nil { 121 data.Set("Status", *params.Status) 122 } 123 if params != nil && params.SourceSid != nil { 124 data.Set("SourceSid", *params.SourceSid) 125 } 126 if params != nil && params.DateCreatedAfter != nil { 127 data.Set("DateCreatedAfter", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) 128 } 129 if params != nil && params.DateCreatedBefore != nil { 130 data.Set("DateCreatedBefore", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) 131 } 132 if params != nil && params.PageSize != nil { 133 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 134 } 135 136 if pageToken != "" { 137 data.Set("PageToken", pageToken) 138 } 139 if pageNumber != "" { 140 data.Set("Page", pageNumber) 141 } 142 143 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 144 if err != nil { 145 return nil, err 146 } 147 148 defer resp.Body.Close() 149 150 ps := &ListRoomRecordingResponse{} 151 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 152 return nil, err 153 } 154 155 return ps, err 156 } 157 158 // Lists RoomRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 159 func (c *ApiService) ListRoomRecording(RoomSid string, params *ListRoomRecordingParams) ([]VideoV1RoomRecording, error) { 160 response, errors := c.StreamRoomRecording(RoomSid, params) 161 162 records := make([]VideoV1RoomRecording, 0) 163 for record := range response { 164 records = append(records, record) 165 } 166 167 if err := <-errors; err != nil { 168 return nil, err 169 } 170 171 return records, nil 172 } 173 174 // Streams RoomRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 175 func (c *ApiService) StreamRoomRecording(RoomSid string, params *ListRoomRecordingParams) (chan VideoV1RoomRecording, chan error) { 176 if params == nil { 177 params = &ListRoomRecordingParams{} 178 } 179 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 180 181 recordChannel := make(chan VideoV1RoomRecording, 1) 182 errorChannel := make(chan error, 1) 183 184 response, err := c.PageRoomRecording(RoomSid, params, "", "") 185 if err != nil { 186 errorChannel <- err 187 close(recordChannel) 188 close(errorChannel) 189 } else { 190 go c.streamRoomRecording(response, params, recordChannel, errorChannel) 191 } 192 193 return recordChannel, errorChannel 194 } 195 196 func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, params *ListRoomRecordingParams, recordChannel chan VideoV1RoomRecording, errorChannel chan error) { 197 curRecord := 1 198 199 for response != nil { 200 responseRecords := response.Recordings 201 for item := range responseRecords { 202 recordChannel <- responseRecords[item] 203 curRecord += 1 204 if params.Limit != nil && *params.Limit < curRecord { 205 close(recordChannel) 206 close(errorChannel) 207 return 208 } 209 } 210 211 record, err := client.GetNext(c.baseURL, response, c.getNextListRoomRecordingResponse) 212 if err != nil { 213 errorChannel <- err 214 break 215 } else if record == nil { 216 break 217 } 218 219 response = record.(*ListRoomRecordingResponse) 220 } 221 222 close(recordChannel) 223 close(errorChannel) 224 } 225 226 func (c *ApiService) getNextListRoomRecordingResponse(nextPageUrl string) (interface{}, error) { 227 if nextPageUrl == "" { 228 return nil, nil 229 } 230 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 231 if err != nil { 232 return nil, err 233 } 234 235 defer resp.Body.Close() 236 237 ps := &ListRoomRecordingResponse{} 238 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 239 return nil, err 240 } 241 return ps, nil 242 }