github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_sip_credential_lists.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 'CreateSipCredentialList' 27 type CreateSipCredentialListParams struct { 28 // The unique id of the Account that is responsible for this resource. 29 PathAccountSid *string `json:"PathAccountSid,omitempty"` 30 // A human readable descriptive text that describes the CredentialList, up to 64 characters long. 31 FriendlyName *string `json:"FriendlyName,omitempty"` 32 } 33 34 func (params *CreateSipCredentialListParams) SetPathAccountSid(PathAccountSid string) *CreateSipCredentialListParams { 35 params.PathAccountSid = &PathAccountSid 36 return params 37 } 38 func (params *CreateSipCredentialListParams) SetFriendlyName(FriendlyName string) *CreateSipCredentialListParams { 39 params.FriendlyName = &FriendlyName 40 return params 41 } 42 43 // Create a Credential List 44 func (c *ApiService) CreateSipCredentialList(params *CreateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { 45 path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json" 46 if params != nil && params.PathAccountSid != nil { 47 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 48 } else { 49 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 50 } 51 52 data := url.Values{} 53 headers := make(map[string]interface{}) 54 55 if params != nil && params.FriendlyName != nil { 56 data.Set("FriendlyName", *params.FriendlyName) 57 } 58 59 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 60 if err != nil { 61 return nil, err 62 } 63 64 defer resp.Body.Close() 65 66 ps := &ApiV2010SipCredentialList{} 67 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 68 return nil, err 69 } 70 71 return ps, err 72 } 73 74 // Optional parameters for the method 'DeleteSipCredentialList' 75 type DeleteSipCredentialListParams struct { 76 // The unique id of the Account that is responsible for this resource. 77 PathAccountSid *string `json:"PathAccountSid,omitempty"` 78 } 79 80 func (params *DeleteSipCredentialListParams) SetPathAccountSid(PathAccountSid string) *DeleteSipCredentialListParams { 81 params.PathAccountSid = &PathAccountSid 82 return params 83 } 84 85 // Delete a Credential List 86 func (c *ApiService) DeleteSipCredentialList(Sid string, params *DeleteSipCredentialListParams) error { 87 path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" 88 if params != nil && params.PathAccountSid != nil { 89 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 90 } else { 91 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 92 } 93 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 94 95 data := url.Values{} 96 headers := make(map[string]interface{}) 97 98 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 99 if err != nil { 100 return err 101 } 102 103 defer resp.Body.Close() 104 105 return nil 106 } 107 108 // Optional parameters for the method 'FetchSipCredentialList' 109 type FetchSipCredentialListParams struct { 110 // The unique id of the Account that is responsible for this resource. 111 PathAccountSid *string `json:"PathAccountSid,omitempty"` 112 } 113 114 func (params *FetchSipCredentialListParams) SetPathAccountSid(PathAccountSid string) *FetchSipCredentialListParams { 115 params.PathAccountSid = &PathAccountSid 116 return params 117 } 118 119 // Get a Credential List 120 func (c *ApiService) FetchSipCredentialList(Sid string, params *FetchSipCredentialListParams) (*ApiV2010SipCredentialList, error) { 121 path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" 122 if params != nil && params.PathAccountSid != nil { 123 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 124 } else { 125 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 126 } 127 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 128 129 data := url.Values{} 130 headers := make(map[string]interface{}) 131 132 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 133 if err != nil { 134 return nil, err 135 } 136 137 defer resp.Body.Close() 138 139 ps := &ApiV2010SipCredentialList{} 140 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 141 return nil, err 142 } 143 144 return ps, err 145 } 146 147 // Optional parameters for the method 'ListSipCredentialList' 148 type ListSipCredentialListParams struct { 149 // The unique id of the Account that is responsible for this resource. 150 PathAccountSid *string `json:"PathAccountSid,omitempty"` 151 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 152 PageSize *int `json:"PageSize,omitempty"` 153 // Max number of records to return. 154 Limit *int `json:"limit,omitempty"` 155 } 156 157 func (params *ListSipCredentialListParams) SetPathAccountSid(PathAccountSid string) *ListSipCredentialListParams { 158 params.PathAccountSid = &PathAccountSid 159 return params 160 } 161 func (params *ListSipCredentialListParams) SetPageSize(PageSize int) *ListSipCredentialListParams { 162 params.PageSize = &PageSize 163 return params 164 } 165 func (params *ListSipCredentialListParams) SetLimit(Limit int) *ListSipCredentialListParams { 166 params.Limit = &Limit 167 return params 168 } 169 170 // Retrieve a single page of SipCredentialList records from the API. Request is executed immediately. 171 func (c *ApiService) PageSipCredentialList(params *ListSipCredentialListParams, pageToken, pageNumber string) (*ListSipCredentialListResponse, error) { 172 path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json" 173 174 if params != nil && params.PathAccountSid != nil { 175 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 176 } else { 177 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 178 } 179 180 data := url.Values{} 181 headers := make(map[string]interface{}) 182 183 if params != nil && params.PageSize != nil { 184 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 185 } 186 187 if pageToken != "" { 188 data.Set("PageToken", pageToken) 189 } 190 if pageNumber != "" { 191 data.Set("Page", pageNumber) 192 } 193 194 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 195 if err != nil { 196 return nil, err 197 } 198 199 defer resp.Body.Close() 200 201 ps := &ListSipCredentialListResponse{} 202 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 203 return nil, err 204 } 205 206 return ps, err 207 } 208 209 // Lists SipCredentialList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 210 func (c *ApiService) ListSipCredentialList(params *ListSipCredentialListParams) ([]ApiV2010SipCredentialList, error) { 211 response, errors := c.StreamSipCredentialList(params) 212 213 records := make([]ApiV2010SipCredentialList, 0) 214 for record := range response { 215 records = append(records, record) 216 } 217 218 if err := <-errors; err != nil { 219 return nil, err 220 } 221 222 return records, nil 223 } 224 225 // Streams SipCredentialList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 226 func (c *ApiService) StreamSipCredentialList(params *ListSipCredentialListParams) (chan ApiV2010SipCredentialList, chan error) { 227 if params == nil { 228 params = &ListSipCredentialListParams{} 229 } 230 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 231 232 recordChannel := make(chan ApiV2010SipCredentialList, 1) 233 errorChannel := make(chan error, 1) 234 235 response, err := c.PageSipCredentialList(params, "", "") 236 if err != nil { 237 errorChannel <- err 238 close(recordChannel) 239 close(errorChannel) 240 } else { 241 go c.streamSipCredentialList(response, params, recordChannel, errorChannel) 242 } 243 244 return recordChannel, errorChannel 245 } 246 247 func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResponse, params *ListSipCredentialListParams, recordChannel chan ApiV2010SipCredentialList, errorChannel chan error) { 248 curRecord := 1 249 250 for response != nil { 251 responseRecords := response.CredentialLists 252 for item := range responseRecords { 253 recordChannel <- responseRecords[item] 254 curRecord += 1 255 if params.Limit != nil && *params.Limit < curRecord { 256 close(recordChannel) 257 close(errorChannel) 258 return 259 } 260 } 261 262 record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialListResponse) 263 if err != nil { 264 errorChannel <- err 265 break 266 } else if record == nil { 267 break 268 } 269 270 response = record.(*ListSipCredentialListResponse) 271 } 272 273 close(recordChannel) 274 close(errorChannel) 275 } 276 277 func (c *ApiService) getNextListSipCredentialListResponse(nextPageUrl string) (interface{}, error) { 278 if nextPageUrl == "" { 279 return nil, nil 280 } 281 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 282 if err != nil { 283 return nil, err 284 } 285 286 defer resp.Body.Close() 287 288 ps := &ListSipCredentialListResponse{} 289 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 290 return nil, err 291 } 292 return ps, nil 293 } 294 295 // Optional parameters for the method 'UpdateSipCredentialList' 296 type UpdateSipCredentialListParams struct { 297 // The unique id of the Account that is responsible for this resource. 298 PathAccountSid *string `json:"PathAccountSid,omitempty"` 299 // A human readable descriptive text for a CredentialList, up to 64 characters long. 300 FriendlyName *string `json:"FriendlyName,omitempty"` 301 } 302 303 func (params *UpdateSipCredentialListParams) SetPathAccountSid(PathAccountSid string) *UpdateSipCredentialListParams { 304 params.PathAccountSid = &PathAccountSid 305 return params 306 } 307 func (params *UpdateSipCredentialListParams) SetFriendlyName(FriendlyName string) *UpdateSipCredentialListParams { 308 params.FriendlyName = &FriendlyName 309 return params 310 } 311 312 // Update a Credential List 313 func (c *ApiService) UpdateSipCredentialList(Sid string, params *UpdateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { 314 path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" 315 if params != nil && params.PathAccountSid != nil { 316 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 317 } else { 318 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 319 } 320 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 321 322 data := url.Values{} 323 headers := make(map[string]interface{}) 324 325 if params != nil && params.FriendlyName != nil { 326 data.Set("FriendlyName", *params.FriendlyName) 327 } 328 329 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 330 if err != nil { 331 return nil, err 332 } 333 334 defer resp.Body.Close() 335 336 ps := &ApiV2010SipCredentialList{} 337 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 338 return nil, err 339 } 340 341 return ps, err 342 }