github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_recordings_add_on_results.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 'DeleteRecordingAddOnResult' 27 type DeleteRecordingAddOnResultParams struct { 28 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording AddOnResult resources to delete. 29 PathAccountSid *string `json:"PathAccountSid,omitempty"` 30 } 31 32 func (params *DeleteRecordingAddOnResultParams) SetPathAccountSid(PathAccountSid string) *DeleteRecordingAddOnResultParams { 33 params.PathAccountSid = &PathAccountSid 34 return params 35 } 36 37 // Delete a result and purge all associated Payloads 38 func (c *ApiService) DeleteRecordingAddOnResult(ReferenceSid string, Sid string, params *DeleteRecordingAddOnResultParams) error { 39 path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{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, "{"+"ReferenceSid"+"}", ReferenceSid, -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 'FetchRecordingAddOnResult' 62 type FetchRecordingAddOnResultParams struct { 63 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording AddOnResult resource to fetch. 64 PathAccountSid *string `json:"PathAccountSid,omitempty"` 65 } 66 67 func (params *FetchRecordingAddOnResultParams) SetPathAccountSid(PathAccountSid string) *FetchRecordingAddOnResultParams { 68 params.PathAccountSid = &PathAccountSid 69 return params 70 } 71 72 // Fetch an instance of an AddOnResult 73 func (c *ApiService) FetchRecordingAddOnResult(ReferenceSid string, Sid string, params *FetchRecordingAddOnResultParams) (*ApiV2010RecordingAddOnResult, error) { 74 path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{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, "{"+"ReferenceSid"+"}", ReferenceSid, -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 := &ApiV2010RecordingAddOnResult{} 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 'ListRecordingAddOnResult' 102 type ListRecordingAddOnResultParams struct { 103 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Recording AddOnResult resources to read. 104 PathAccountSid *string `json:"PathAccountSid,omitempty"` 105 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 106 PageSize *int `json:"PageSize,omitempty"` 107 // Max number of records to return. 108 Limit *int `json:"limit,omitempty"` 109 } 110 111 func (params *ListRecordingAddOnResultParams) SetPathAccountSid(PathAccountSid string) *ListRecordingAddOnResultParams { 112 params.PathAccountSid = &PathAccountSid 113 return params 114 } 115 func (params *ListRecordingAddOnResultParams) SetPageSize(PageSize int) *ListRecordingAddOnResultParams { 116 params.PageSize = &PageSize 117 return params 118 } 119 func (params *ListRecordingAddOnResultParams) SetLimit(Limit int) *ListRecordingAddOnResultParams { 120 params.Limit = &Limit 121 return params 122 } 123 124 // Retrieve a single page of RecordingAddOnResult records from the API. Request is executed immediately. 125 func (c *ApiService) PageRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams, pageToken, pageNumber string) (*ListRecordingAddOnResultResponse, error) { 126 path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json" 127 128 if params != nil && params.PathAccountSid != nil { 129 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 130 } else { 131 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 132 } 133 path = strings.Replace(path, "{"+"ReferenceSid"+"}", ReferenceSid, -1) 134 135 data := url.Values{} 136 headers := make(map[string]interface{}) 137 138 if params != nil && params.PageSize != nil { 139 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 140 } 141 142 if pageToken != "" { 143 data.Set("PageToken", pageToken) 144 } 145 if pageNumber != "" { 146 data.Set("Page", pageNumber) 147 } 148 149 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 150 if err != nil { 151 return nil, err 152 } 153 154 defer resp.Body.Close() 155 156 ps := &ListRecordingAddOnResultResponse{} 157 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 158 return nil, err 159 } 160 161 return ps, err 162 } 163 164 // Lists RecordingAddOnResult records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 165 func (c *ApiService) ListRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams) ([]ApiV2010RecordingAddOnResult, error) { 166 response, errors := c.StreamRecordingAddOnResult(ReferenceSid, params) 167 168 records := make([]ApiV2010RecordingAddOnResult, 0) 169 for record := range response { 170 records = append(records, record) 171 } 172 173 if err := <-errors; err != nil { 174 return nil, err 175 } 176 177 return records, nil 178 } 179 180 // Streams RecordingAddOnResult records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 181 func (c *ApiService) StreamRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams) (chan ApiV2010RecordingAddOnResult, chan error) { 182 if params == nil { 183 params = &ListRecordingAddOnResultParams{} 184 } 185 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 186 187 recordChannel := make(chan ApiV2010RecordingAddOnResult, 1) 188 errorChannel := make(chan error, 1) 189 190 response, err := c.PageRecordingAddOnResult(ReferenceSid, params, "", "") 191 if err != nil { 192 errorChannel <- err 193 close(recordChannel) 194 close(errorChannel) 195 } else { 196 go c.streamRecordingAddOnResult(response, params, recordChannel, errorChannel) 197 } 198 199 return recordChannel, errorChannel 200 } 201 202 func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResultResponse, params *ListRecordingAddOnResultParams, recordChannel chan ApiV2010RecordingAddOnResult, errorChannel chan error) { 203 curRecord := 1 204 205 for response != nil { 206 responseRecords := response.AddOnResults 207 for item := range responseRecords { 208 recordChannel <- responseRecords[item] 209 curRecord += 1 210 if params.Limit != nil && *params.Limit < curRecord { 211 close(recordChannel) 212 close(errorChannel) 213 return 214 } 215 } 216 217 record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingAddOnResultResponse) 218 if err != nil { 219 errorChannel <- err 220 break 221 } else if record == nil { 222 break 223 } 224 225 response = record.(*ListRecordingAddOnResultResponse) 226 } 227 228 close(recordChannel) 229 close(errorChannel) 230 } 231 232 func (c *ApiService) getNextListRecordingAddOnResultResponse(nextPageUrl string) (interface{}, error) { 233 if nextPageUrl == "" { 234 return nil, nil 235 } 236 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 237 if err != nil { 238 return nil, err 239 } 240 241 defer resp.Body.Close() 242 243 ps := &ListRecordingAddOnResultResponse{} 244 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 245 return nil, err 246 } 247 return ps, nil 248 }