github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_connect_apps.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 'DeleteConnectApp' 27 type DeleteConnectAppParams struct { 28 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ConnectApp resource to fetch. 29 PathAccountSid *string `json:"PathAccountSid,omitempty"` 30 } 31 32 func (params *DeleteConnectAppParams) SetPathAccountSid(PathAccountSid string) *DeleteConnectAppParams { 33 params.PathAccountSid = &PathAccountSid 34 return params 35 } 36 37 // Delete an instance of a connect-app 38 func (c *ApiService) DeleteConnectApp(Sid string, params *DeleteConnectAppParams) error { 39 path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{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, "{"+"Sid"+"}", Sid, -1) 46 47 data := url.Values{} 48 headers := make(map[string]interface{}) 49 50 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 51 if err != nil { 52 return err 53 } 54 55 defer resp.Body.Close() 56 57 return nil 58 } 59 60 // Optional parameters for the method 'FetchConnectApp' 61 type FetchConnectAppParams struct { 62 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ConnectApp resource to fetch. 63 PathAccountSid *string `json:"PathAccountSid,omitempty"` 64 } 65 66 func (params *FetchConnectAppParams) SetPathAccountSid(PathAccountSid string) *FetchConnectAppParams { 67 params.PathAccountSid = &PathAccountSid 68 return params 69 } 70 71 // Fetch an instance of a connect-app 72 func (c *ApiService) FetchConnectApp(Sid string, params *FetchConnectAppParams) (*ApiV2010ConnectApp, error) { 73 path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json" 74 if params != nil && params.PathAccountSid != nil { 75 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 76 } else { 77 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 78 } 79 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 80 81 data := url.Values{} 82 headers := make(map[string]interface{}) 83 84 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 85 if err != nil { 86 return nil, err 87 } 88 89 defer resp.Body.Close() 90 91 ps := &ApiV2010ConnectApp{} 92 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 93 return nil, err 94 } 95 96 return ps, err 97 } 98 99 // Optional parameters for the method 'ListConnectApp' 100 type ListConnectAppParams struct { 101 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ConnectApp resources to read. 102 PathAccountSid *string `json:"PathAccountSid,omitempty"` 103 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 104 PageSize *int `json:"PageSize,omitempty"` 105 // Max number of records to return. 106 Limit *int `json:"limit,omitempty"` 107 } 108 109 func (params *ListConnectAppParams) SetPathAccountSid(PathAccountSid string) *ListConnectAppParams { 110 params.PathAccountSid = &PathAccountSid 111 return params 112 } 113 func (params *ListConnectAppParams) SetPageSize(PageSize int) *ListConnectAppParams { 114 params.PageSize = &PageSize 115 return params 116 } 117 func (params *ListConnectAppParams) SetLimit(Limit int) *ListConnectAppParams { 118 params.Limit = &Limit 119 return params 120 } 121 122 // Retrieve a single page of ConnectApp records from the API. Request is executed immediately. 123 func (c *ApiService) PageConnectApp(params *ListConnectAppParams, pageToken, pageNumber string) (*ListConnectAppResponse, error) { 124 path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json" 125 126 if params != nil && params.PathAccountSid != nil { 127 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 128 } else { 129 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 130 } 131 132 data := url.Values{} 133 headers := make(map[string]interface{}) 134 135 if params != nil && params.PageSize != nil { 136 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 137 } 138 139 if pageToken != "" { 140 data.Set("PageToken", pageToken) 141 } 142 if pageNumber != "" { 143 data.Set("Page", pageNumber) 144 } 145 146 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 147 if err != nil { 148 return nil, err 149 } 150 151 defer resp.Body.Close() 152 153 ps := &ListConnectAppResponse{} 154 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 155 return nil, err 156 } 157 158 return ps, err 159 } 160 161 // Lists ConnectApp records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 162 func (c *ApiService) ListConnectApp(params *ListConnectAppParams) ([]ApiV2010ConnectApp, error) { 163 response, errors := c.StreamConnectApp(params) 164 165 records := make([]ApiV2010ConnectApp, 0) 166 for record := range response { 167 records = append(records, record) 168 } 169 170 if err := <-errors; err != nil { 171 return nil, err 172 } 173 174 return records, nil 175 } 176 177 // Streams ConnectApp records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 178 func (c *ApiService) StreamConnectApp(params *ListConnectAppParams) (chan ApiV2010ConnectApp, chan error) { 179 if params == nil { 180 params = &ListConnectAppParams{} 181 } 182 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 183 184 recordChannel := make(chan ApiV2010ConnectApp, 1) 185 errorChannel := make(chan error, 1) 186 187 response, err := c.PageConnectApp(params, "", "") 188 if err != nil { 189 errorChannel <- err 190 close(recordChannel) 191 close(errorChannel) 192 } else { 193 go c.streamConnectApp(response, params, recordChannel, errorChannel) 194 } 195 196 return recordChannel, errorChannel 197 } 198 199 func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params *ListConnectAppParams, recordChannel chan ApiV2010ConnectApp, errorChannel chan error) { 200 curRecord := 1 201 202 for response != nil { 203 responseRecords := response.ConnectApps 204 for item := range responseRecords { 205 recordChannel <- responseRecords[item] 206 curRecord += 1 207 if params.Limit != nil && *params.Limit < curRecord { 208 close(recordChannel) 209 close(errorChannel) 210 return 211 } 212 } 213 214 record, err := client.GetNext(c.baseURL, response, c.getNextListConnectAppResponse) 215 if err != nil { 216 errorChannel <- err 217 break 218 } else if record == nil { 219 break 220 } 221 222 response = record.(*ListConnectAppResponse) 223 } 224 225 close(recordChannel) 226 close(errorChannel) 227 } 228 229 func (c *ApiService) getNextListConnectAppResponse(nextPageUrl string) (interface{}, error) { 230 if nextPageUrl == "" { 231 return nil, nil 232 } 233 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 234 if err != nil { 235 return nil, err 236 } 237 238 defer resp.Body.Close() 239 240 ps := &ListConnectAppResponse{} 241 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 242 return nil, err 243 } 244 return ps, nil 245 } 246 247 // Optional parameters for the method 'UpdateConnectApp' 248 type UpdateConnectAppParams struct { 249 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ConnectApp resources to update. 250 PathAccountSid *string `json:"PathAccountSid,omitempty"` 251 // The URL to redirect the user to after we authenticate the user and obtain authorization to access the Connect App. 252 AuthorizeRedirectUrl *string `json:"AuthorizeRedirectUrl,omitempty"` 253 // The company name to set for the Connect App. 254 CompanyName *string `json:"CompanyName,omitempty"` 255 // The HTTP method to use when calling `deauthorize_callback_url`. 256 DeauthorizeCallbackMethod *string `json:"DeauthorizeCallbackMethod,omitempty"` 257 // The URL to call using the `deauthorize_callback_method` to de-authorize the Connect App. 258 DeauthorizeCallbackUrl *string `json:"DeauthorizeCallbackUrl,omitempty"` 259 // A description of the Connect App. 260 Description *string `json:"Description,omitempty"` 261 // A descriptive string that you create to describe the resource. It can be up to 64 characters long. 262 FriendlyName *string `json:"FriendlyName,omitempty"` 263 // A public URL where users can obtain more information about this Connect App. 264 HomepageUrl *string `json:"HomepageUrl,omitempty"` 265 // A comma-separated list of the permissions you will request from the users of this ConnectApp. Can include: `get-all` and `post-all`. 266 Permissions *[]string `json:"Permissions,omitempty"` 267 } 268 269 func (params *UpdateConnectAppParams) SetPathAccountSid(PathAccountSid string) *UpdateConnectAppParams { 270 params.PathAccountSid = &PathAccountSid 271 return params 272 } 273 func (params *UpdateConnectAppParams) SetAuthorizeRedirectUrl(AuthorizeRedirectUrl string) *UpdateConnectAppParams { 274 params.AuthorizeRedirectUrl = &AuthorizeRedirectUrl 275 return params 276 } 277 func (params *UpdateConnectAppParams) SetCompanyName(CompanyName string) *UpdateConnectAppParams { 278 params.CompanyName = &CompanyName 279 return params 280 } 281 func (params *UpdateConnectAppParams) SetDeauthorizeCallbackMethod(DeauthorizeCallbackMethod string) *UpdateConnectAppParams { 282 params.DeauthorizeCallbackMethod = &DeauthorizeCallbackMethod 283 return params 284 } 285 func (params *UpdateConnectAppParams) SetDeauthorizeCallbackUrl(DeauthorizeCallbackUrl string) *UpdateConnectAppParams { 286 params.DeauthorizeCallbackUrl = &DeauthorizeCallbackUrl 287 return params 288 } 289 func (params *UpdateConnectAppParams) SetDescription(Description string) *UpdateConnectAppParams { 290 params.Description = &Description 291 return params 292 } 293 func (params *UpdateConnectAppParams) SetFriendlyName(FriendlyName string) *UpdateConnectAppParams { 294 params.FriendlyName = &FriendlyName 295 return params 296 } 297 func (params *UpdateConnectAppParams) SetHomepageUrl(HomepageUrl string) *UpdateConnectAppParams { 298 params.HomepageUrl = &HomepageUrl 299 return params 300 } 301 func (params *UpdateConnectAppParams) SetPermissions(Permissions []string) *UpdateConnectAppParams { 302 params.Permissions = &Permissions 303 return params 304 } 305 306 // Update a connect-app with the specified parameters 307 func (c *ApiService) UpdateConnectApp(Sid string, params *UpdateConnectAppParams) (*ApiV2010ConnectApp, error) { 308 path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json" 309 if params != nil && params.PathAccountSid != nil { 310 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 311 } else { 312 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 313 } 314 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 315 316 data := url.Values{} 317 headers := make(map[string]interface{}) 318 319 if params != nil && params.AuthorizeRedirectUrl != nil { 320 data.Set("AuthorizeRedirectUrl", *params.AuthorizeRedirectUrl) 321 } 322 if params != nil && params.CompanyName != nil { 323 data.Set("CompanyName", *params.CompanyName) 324 } 325 if params != nil && params.DeauthorizeCallbackMethod != nil { 326 data.Set("DeauthorizeCallbackMethod", *params.DeauthorizeCallbackMethod) 327 } 328 if params != nil && params.DeauthorizeCallbackUrl != nil { 329 data.Set("DeauthorizeCallbackUrl", *params.DeauthorizeCallbackUrl) 330 } 331 if params != nil && params.Description != nil { 332 data.Set("Description", *params.Description) 333 } 334 if params != nil && params.FriendlyName != nil { 335 data.Set("FriendlyName", *params.FriendlyName) 336 } 337 if params != nil && params.HomepageUrl != nil { 338 data.Set("HomepageUrl", *params.HomepageUrl) 339 } 340 if params != nil && params.Permissions != nil { 341 for _, item := range *params.Permissions { 342 data.Add("Permissions", item) 343 } 344 } 345 346 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 347 if err != nil { 348 return nil, err 349 } 350 351 defer resp.Body.Close() 352 353 ps := &ApiV2010ConnectApp{} 354 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 355 return nil, err 356 } 357 358 return ps, err 359 }