github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_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 "time" 23 24 "github.com/twilio/twilio-go/client" 25 ) 26 27 // Optional parameters for the method 'DeleteRecording' 28 type DeleteRecordingParams struct { 29 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording resources to delete. 30 PathAccountSid *string `json:"PathAccountSid,omitempty"` 31 } 32 33 func (params *DeleteRecordingParams) SetPathAccountSid(PathAccountSid string) *DeleteRecordingParams { 34 params.PathAccountSid = &PathAccountSid 35 return params 36 } 37 38 // Delete a recording from your account 39 func (c *ApiService) DeleteRecording(Sid string, params *DeleteRecordingParams) error { 40 path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json" 41 if params != nil && params.PathAccountSid != nil { 42 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 43 } else { 44 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 45 } 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 'FetchRecording' 62 type FetchRecordingParams struct { 63 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording resource to fetch. 64 PathAccountSid *string `json:"PathAccountSid,omitempty"` 65 // A boolean parameter indicating whether to retrieve soft deleted recordings or not. Recordings metadata are kept after deletion for a retention period of 40 days. 66 IncludeSoftDeleted *bool `json:"IncludeSoftDeleted,omitempty"` 67 } 68 69 func (params *FetchRecordingParams) SetPathAccountSid(PathAccountSid string) *FetchRecordingParams { 70 params.PathAccountSid = &PathAccountSid 71 return params 72 } 73 func (params *FetchRecordingParams) SetIncludeSoftDeleted(IncludeSoftDeleted bool) *FetchRecordingParams { 74 params.IncludeSoftDeleted = &IncludeSoftDeleted 75 return params 76 } 77 78 // Fetch an instance of a recording 79 func (c *ApiService) FetchRecording(Sid string, params *FetchRecordingParams) (*ApiV2010Recording, error) { 80 path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json" 81 if params != nil && params.PathAccountSid != nil { 82 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 83 } else { 84 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 85 } 86 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 87 88 data := url.Values{} 89 headers := make(map[string]interface{}) 90 91 if params != nil && params.IncludeSoftDeleted != nil { 92 data.Set("IncludeSoftDeleted", fmt.Sprint(*params.IncludeSoftDeleted)) 93 } 94 95 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 96 if err != nil { 97 return nil, err 98 } 99 100 defer resp.Body.Close() 101 102 ps := &ApiV2010Recording{} 103 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 104 return nil, err 105 } 106 107 return ps, err 108 } 109 110 // Optional parameters for the method 'ListRecording' 111 type ListRecordingParams struct { 112 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording resources to read. 113 PathAccountSid *string `json:"PathAccountSid,omitempty"` 114 // Only include recordings that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read recordings that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read recordings that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read recordings that were created on or after midnight of this date. 115 DateCreated *time.Time `json:"DateCreated,omitempty"` 116 // Only include recordings that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read recordings that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read recordings that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read recordings that were created on or after midnight of this date. 117 DateCreatedBefore *time.Time `json:"DateCreated<,omitempty"` 118 // Only include recordings that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read recordings that were created on this date. You can also specify an inequality, such as `DateCreated<=YYYY-MM-DD`, to read recordings that were created on or before midnight of this date, and `DateCreated>=YYYY-MM-DD` to read recordings that were created on or after midnight of this date. 119 DateCreatedAfter *time.Time `json:"DateCreated>,omitempty"` 120 // The [Call](https://www.twilio.com/docs/voice/api/call-resource) SID of the resources to read. 121 CallSid *string `json:"CallSid,omitempty"` 122 // The Conference SID that identifies the conference associated with the recording to read. 123 ConferenceSid *string `json:"ConferenceSid,omitempty"` 124 // A boolean parameter indicating whether to retrieve soft deleted recordings or not. Recordings metadata are kept after deletion for a retention period of 40 days. 125 IncludeSoftDeleted *bool `json:"IncludeSoftDeleted,omitempty"` 126 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 127 PageSize *int `json:"PageSize,omitempty"` 128 // Max number of records to return. 129 Limit *int `json:"limit,omitempty"` 130 } 131 132 func (params *ListRecordingParams) SetPathAccountSid(PathAccountSid string) *ListRecordingParams { 133 params.PathAccountSid = &PathAccountSid 134 return params 135 } 136 func (params *ListRecordingParams) SetDateCreated(DateCreated time.Time) *ListRecordingParams { 137 params.DateCreated = &DateCreated 138 return params 139 } 140 func (params *ListRecordingParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *ListRecordingParams { 141 params.DateCreatedBefore = &DateCreatedBefore 142 return params 143 } 144 func (params *ListRecordingParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *ListRecordingParams { 145 params.DateCreatedAfter = &DateCreatedAfter 146 return params 147 } 148 func (params *ListRecordingParams) SetCallSid(CallSid string) *ListRecordingParams { 149 params.CallSid = &CallSid 150 return params 151 } 152 func (params *ListRecordingParams) SetConferenceSid(ConferenceSid string) *ListRecordingParams { 153 params.ConferenceSid = &ConferenceSid 154 return params 155 } 156 func (params *ListRecordingParams) SetIncludeSoftDeleted(IncludeSoftDeleted bool) *ListRecordingParams { 157 params.IncludeSoftDeleted = &IncludeSoftDeleted 158 return params 159 } 160 func (params *ListRecordingParams) SetPageSize(PageSize int) *ListRecordingParams { 161 params.PageSize = &PageSize 162 return params 163 } 164 func (params *ListRecordingParams) SetLimit(Limit int) *ListRecordingParams { 165 params.Limit = &Limit 166 return params 167 } 168 169 // Retrieve a single page of Recording records from the API. Request is executed immediately. 170 func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { 171 path := "/2010-04-01/Accounts/{AccountSid}/Recordings.json" 172 173 if params != nil && params.PathAccountSid != nil { 174 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 175 } else { 176 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 177 } 178 179 data := url.Values{} 180 headers := make(map[string]interface{}) 181 182 if params != nil && params.DateCreated != nil { 183 data.Set("DateCreated", fmt.Sprint((*params.DateCreated).Format(time.RFC3339))) 184 } 185 if params != nil && params.DateCreatedBefore != nil { 186 data.Set("DateCreated<", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) 187 } 188 if params != nil && params.DateCreatedAfter != nil { 189 data.Set("DateCreated>", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) 190 } 191 if params != nil && params.CallSid != nil { 192 data.Set("CallSid", *params.CallSid) 193 } 194 if params != nil && params.ConferenceSid != nil { 195 data.Set("ConferenceSid", *params.ConferenceSid) 196 } 197 if params != nil && params.IncludeSoftDeleted != nil { 198 data.Set("IncludeSoftDeleted", fmt.Sprint(*params.IncludeSoftDeleted)) 199 } 200 if params != nil && params.PageSize != nil { 201 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 202 } 203 204 if pageToken != "" { 205 data.Set("PageToken", pageToken) 206 } 207 if pageNumber != "" { 208 data.Set("Page", pageNumber) 209 } 210 211 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 212 if err != nil { 213 return nil, err 214 } 215 216 defer resp.Body.Close() 217 218 ps := &ListRecordingResponse{} 219 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 220 return nil, err 221 } 222 223 return ps, err 224 } 225 226 // Lists Recording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 227 func (c *ApiService) ListRecording(params *ListRecordingParams) ([]ApiV2010Recording, error) { 228 response, errors := c.StreamRecording(params) 229 230 records := make([]ApiV2010Recording, 0) 231 for record := range response { 232 records = append(records, record) 233 } 234 235 if err := <-errors; err != nil { 236 return nil, err 237 } 238 239 return records, nil 240 } 241 242 // Streams Recording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 243 func (c *ApiService) StreamRecording(params *ListRecordingParams) (chan ApiV2010Recording, chan error) { 244 if params == nil { 245 params = &ListRecordingParams{} 246 } 247 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 248 249 recordChannel := make(chan ApiV2010Recording, 1) 250 errorChannel := make(chan error, 1) 251 252 response, err := c.PageRecording(params, "", "") 253 if err != nil { 254 errorChannel <- err 255 close(recordChannel) 256 close(errorChannel) 257 } else { 258 go c.streamRecording(response, params, recordChannel, errorChannel) 259 } 260 261 return recordChannel, errorChannel 262 } 263 264 func (c *ApiService) streamRecording(response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan ApiV2010Recording, errorChannel chan error) { 265 curRecord := 1 266 267 for response != nil { 268 responseRecords := response.Recordings 269 for item := range responseRecords { 270 recordChannel <- responseRecords[item] 271 curRecord += 1 272 if params.Limit != nil && *params.Limit < curRecord { 273 close(recordChannel) 274 close(errorChannel) 275 return 276 } 277 } 278 279 record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingResponse) 280 if err != nil { 281 errorChannel <- err 282 break 283 } else if record == nil { 284 break 285 } 286 287 response = record.(*ListRecordingResponse) 288 } 289 290 close(recordChannel) 291 close(errorChannel) 292 } 293 294 func (c *ApiService) getNextListRecordingResponse(nextPageUrl string) (interface{}, error) { 295 if nextPageUrl == "" { 296 return nil, nil 297 } 298 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 299 if err != nil { 300 return nil, err 301 } 302 303 defer resp.Body.Close() 304 305 ps := &ListRecordingResponse{} 306 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 307 return nil, err 308 } 309 return ps, nil 310 }