github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_conferences_recordings.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Api 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 23 "github.com/twilio/twilio-go/client" 24 ) 25 26 // Optional parameters for the method 'DeleteConferenceRecording' 27 type DeleteConferenceRecordingParams struct { 28 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference Recording resources to delete. 29 PathAccountSid *string `json:"PathAccountSid,omitempty"` 30 } 31 32 func (params *DeleteConferenceRecordingParams) SetPathAccountSid(PathAccountSid string) *DeleteConferenceRecordingParams { 33 params.PathAccountSid = &PathAccountSid 34 return params 35 } 36 37 // Delete a recording from your account 38 func (c *ApiService) DeleteConferenceRecording(ConferenceSid string, Sid string, params *DeleteConferenceRecordingParams) error { 39 path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" 40 if params != nil && params.PathAccountSid != nil { 41 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 42 } else { 43 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 44 } 45 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 46 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 47 48 data := url.Values{} 49 headers := make(map[string]interface{}) 50 51 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 52 if err != nil { 53 return err 54 } 55 56 defer resp.Body.Close() 57 58 return nil 59 } 60 61 // Optional parameters for the method 'FetchConferenceRecording' 62 type FetchConferenceRecordingParams struct { 63 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference Recording resource to fetch. 64 PathAccountSid *string `json:"PathAccountSid,omitempty"` 65 } 66 67 func (params *FetchConferenceRecordingParams) SetPathAccountSid(PathAccountSid string) *FetchConferenceRecordingParams { 68 params.PathAccountSid = &PathAccountSid 69 return params 70 } 71 72 // Fetch an instance of a recording for a call 73 func (c *ApiService) FetchConferenceRecording(ConferenceSid string, Sid string, params *FetchConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { 74 path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" 75 if params != nil && params.PathAccountSid != nil { 76 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 77 } else { 78 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 79 } 80 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 81 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 82 83 data := url.Values{} 84 headers := make(map[string]interface{}) 85 86 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 87 if err != nil { 88 return nil, err 89 } 90 91 defer resp.Body.Close() 92 93 ps := &ApiV2010ConferenceRecording{} 94 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 95 return nil, err 96 } 97 98 return ps, err 99 } 100 101 // Optional parameters for the method 'ListConferenceRecording' 102 type ListConferenceRecordingParams struct { 103 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference Recording resources to read. 104 PathAccountSid *string `json:"PathAccountSid,omitempty"` 105 // The `date_created` value, specified as `YYYY-MM-DD`, of the resources to read. You can also specify inequality: `DateCreated<=YYYY-MM-DD` will return recordings generated at or before midnight on a given date, and `DateCreated>=YYYY-MM-DD` returns recordings generated at or after midnight on a date. 106 DateCreated *string `json:"DateCreated,omitempty"` 107 // The `date_created` value, specified as `YYYY-MM-DD`, of the resources to read. You can also specify inequality: `DateCreated<=YYYY-MM-DD` will return recordings generated at or before midnight on a given date, and `DateCreated>=YYYY-MM-DD` returns recordings generated at or after midnight on a date. 108 DateCreatedBefore *string `json:"DateCreated<,omitempty"` 109 // The `date_created` value, specified as `YYYY-MM-DD`, of the resources to read. You can also specify inequality: `DateCreated<=YYYY-MM-DD` will return recordings generated at or before midnight on a given date, and `DateCreated>=YYYY-MM-DD` returns recordings generated at or after midnight on a date. 110 DateCreatedAfter *string `json:"DateCreated>,omitempty"` 111 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 112 PageSize *int `json:"PageSize,omitempty"` 113 // Max number of records to return. 114 Limit *int `json:"limit,omitempty"` 115 } 116 117 func (params *ListConferenceRecordingParams) SetPathAccountSid(PathAccountSid string) *ListConferenceRecordingParams { 118 params.PathAccountSid = &PathAccountSid 119 return params 120 } 121 func (params *ListConferenceRecordingParams) SetDateCreated(DateCreated string) *ListConferenceRecordingParams { 122 params.DateCreated = &DateCreated 123 return params 124 } 125 func (params *ListConferenceRecordingParams) SetDateCreatedBefore(DateCreatedBefore string) *ListConferenceRecordingParams { 126 params.DateCreatedBefore = &DateCreatedBefore 127 return params 128 } 129 func (params *ListConferenceRecordingParams) SetDateCreatedAfter(DateCreatedAfter string) *ListConferenceRecordingParams { 130 params.DateCreatedAfter = &DateCreatedAfter 131 return params 132 } 133 func (params *ListConferenceRecordingParams) SetPageSize(PageSize int) *ListConferenceRecordingParams { 134 params.PageSize = &PageSize 135 return params 136 } 137 func (params *ListConferenceRecordingParams) SetLimit(Limit int) *ListConferenceRecordingParams { 138 params.Limit = &Limit 139 return params 140 } 141 142 // Retrieve a single page of ConferenceRecording records from the API. Request is executed immediately. 143 func (c *ApiService) PageConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams, pageToken, pageNumber string) (*ListConferenceRecordingResponse, error) { 144 path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json" 145 146 if params != nil && params.PathAccountSid != nil { 147 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 148 } else { 149 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 150 } 151 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 152 153 data := url.Values{} 154 headers := make(map[string]interface{}) 155 156 if params != nil && params.DateCreated != nil { 157 data.Set("DateCreated", fmt.Sprint(*params.DateCreated)) 158 } 159 if params != nil && params.DateCreatedBefore != nil { 160 data.Set("DateCreated<", fmt.Sprint(*params.DateCreatedBefore)) 161 } 162 if params != nil && params.DateCreatedAfter != nil { 163 data.Set("DateCreated>", fmt.Sprint(*params.DateCreatedAfter)) 164 } 165 if params != nil && params.PageSize != nil { 166 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 167 } 168 169 if pageToken != "" { 170 data.Set("PageToken", pageToken) 171 } 172 if pageNumber != "" { 173 data.Set("Page", pageNumber) 174 } 175 176 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 177 if err != nil { 178 return nil, err 179 } 180 181 defer resp.Body.Close() 182 183 ps := &ListConferenceRecordingResponse{} 184 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 185 return nil, err 186 } 187 188 return ps, err 189 } 190 191 // Lists ConferenceRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 192 func (c *ApiService) ListConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams) ([]ApiV2010ConferenceRecording, error) { 193 response, errors := c.StreamConferenceRecording(ConferenceSid, params) 194 195 records := make([]ApiV2010ConferenceRecording, 0) 196 for record := range response { 197 records = append(records, record) 198 } 199 200 if err := <-errors; err != nil { 201 return nil, err 202 } 203 204 return records, nil 205 } 206 207 // Streams ConferenceRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 208 func (c *ApiService) StreamConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams) (chan ApiV2010ConferenceRecording, chan error) { 209 if params == nil { 210 params = &ListConferenceRecordingParams{} 211 } 212 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 213 214 recordChannel := make(chan ApiV2010ConferenceRecording, 1) 215 errorChannel := make(chan error, 1) 216 217 response, err := c.PageConferenceRecording(ConferenceSid, params, "", "") 218 if err != nil { 219 errorChannel <- err 220 close(recordChannel) 221 close(errorChannel) 222 } else { 223 go c.streamConferenceRecording(response, params, recordChannel, errorChannel) 224 } 225 226 return recordChannel, errorChannel 227 } 228 229 func (c *ApiService) streamConferenceRecording(response *ListConferenceRecordingResponse, params *ListConferenceRecordingParams, recordChannel chan ApiV2010ConferenceRecording, errorChannel chan error) { 230 curRecord := 1 231 232 for response != nil { 233 responseRecords := response.Recordings 234 for item := range responseRecords { 235 recordChannel <- responseRecords[item] 236 curRecord += 1 237 if params.Limit != nil && *params.Limit < curRecord { 238 close(recordChannel) 239 close(errorChannel) 240 return 241 } 242 } 243 244 record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceRecordingResponse) 245 if err != nil { 246 errorChannel <- err 247 break 248 } else if record == nil { 249 break 250 } 251 252 response = record.(*ListConferenceRecordingResponse) 253 } 254 255 close(recordChannel) 256 close(errorChannel) 257 } 258 259 func (c *ApiService) getNextListConferenceRecordingResponse(nextPageUrl string) (interface{}, error) { 260 if nextPageUrl == "" { 261 return nil, nil 262 } 263 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 264 if err != nil { 265 return nil, err 266 } 267 268 defer resp.Body.Close() 269 270 ps := &ListConferenceRecordingResponse{} 271 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 272 return nil, err 273 } 274 return ps, nil 275 } 276 277 // Optional parameters for the method 'UpdateConferenceRecording' 278 type UpdateConferenceRecordingParams struct { 279 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Conference Recording resource to update. 280 PathAccountSid *string `json:"PathAccountSid,omitempty"` 281 // 282 Status *string `json:"Status,omitempty"` 283 // Whether to record during a pause. Can be: `skip` or `silence` and the default is `silence`. `skip` does not record during the pause period, while `silence` will replace the actual audio of the call with silence during the pause period. This parameter only applies when setting `status` is set to `paused`. 284 PauseBehavior *string `json:"PauseBehavior,omitempty"` 285 } 286 287 func (params *UpdateConferenceRecordingParams) SetPathAccountSid(PathAccountSid string) *UpdateConferenceRecordingParams { 288 params.PathAccountSid = &PathAccountSid 289 return params 290 } 291 func (params *UpdateConferenceRecordingParams) SetStatus(Status string) *UpdateConferenceRecordingParams { 292 params.Status = &Status 293 return params 294 } 295 func (params *UpdateConferenceRecordingParams) SetPauseBehavior(PauseBehavior string) *UpdateConferenceRecordingParams { 296 params.PauseBehavior = &PauseBehavior 297 return params 298 } 299 300 // Changes the status of the recording to paused, stopped, or in-progress. Note: To use `Twilio.CURRENT`, pass it as recording sid. 301 func (c *ApiService) UpdateConferenceRecording(ConferenceSid string, Sid string, params *UpdateConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { 302 path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" 303 if params != nil && params.PathAccountSid != nil { 304 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 305 } else { 306 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 307 } 308 path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) 309 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 310 311 data := url.Values{} 312 headers := make(map[string]interface{}) 313 314 if params != nil && params.Status != nil { 315 data.Set("Status", *params.Status) 316 } 317 if params != nil && params.PauseBehavior != nil { 318 data.Set("PauseBehavior", *params.PauseBehavior) 319 } 320 321 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 322 if err != nil { 323 return nil, err 324 } 325 326 defer resp.Body.Close() 327 328 ps := &ApiV2010ConferenceRecording{} 329 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 330 return nil, err 331 } 332 333 return ps, err 334 }