github.com/twilio/twilio-go@v1.20.1/rest/numbers/v2/regulatory_compliance_bundles.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Numbers 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 'CreateBundle' 28 type CreateBundleParams struct { 29 // The string that you assigned to describe the resource. 30 FriendlyName *string `json:"FriendlyName,omitempty"` 31 // The email address that will receive updates when the Bundle resource changes status. 32 Email *string `json:"Email,omitempty"` 33 // The URL we call to inform your application of status changes. 34 StatusCallback *string `json:"StatusCallback,omitempty"` 35 // The unique string of a regulation that is associated to the Bundle resource. 36 RegulationSid *string `json:"RegulationSid,omitempty"` 37 // The [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the Bundle's phone number country ownership request. 38 IsoCountry *string `json:"IsoCountry,omitempty"` 39 // 40 EndUserType *string `json:"EndUserType,omitempty"` 41 // The type of phone number of the Bundle's ownership request. Can be `local`, `mobile`, `national`, or `toll free`. 42 NumberType *string `json:"NumberType,omitempty"` 43 } 44 45 func (params *CreateBundleParams) SetFriendlyName(FriendlyName string) *CreateBundleParams { 46 params.FriendlyName = &FriendlyName 47 return params 48 } 49 func (params *CreateBundleParams) SetEmail(Email string) *CreateBundleParams { 50 params.Email = &Email 51 return params 52 } 53 func (params *CreateBundleParams) SetStatusCallback(StatusCallback string) *CreateBundleParams { 54 params.StatusCallback = &StatusCallback 55 return params 56 } 57 func (params *CreateBundleParams) SetRegulationSid(RegulationSid string) *CreateBundleParams { 58 params.RegulationSid = &RegulationSid 59 return params 60 } 61 func (params *CreateBundleParams) SetIsoCountry(IsoCountry string) *CreateBundleParams { 62 params.IsoCountry = &IsoCountry 63 return params 64 } 65 func (params *CreateBundleParams) SetEndUserType(EndUserType string) *CreateBundleParams { 66 params.EndUserType = &EndUserType 67 return params 68 } 69 func (params *CreateBundleParams) SetNumberType(NumberType string) *CreateBundleParams { 70 params.NumberType = &NumberType 71 return params 72 } 73 74 // Create a new Bundle. 75 func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, error) { 76 path := "/v2/RegulatoryCompliance/Bundles" 77 78 data := url.Values{} 79 headers := make(map[string]interface{}) 80 81 if params != nil && params.FriendlyName != nil { 82 data.Set("FriendlyName", *params.FriendlyName) 83 } 84 if params != nil && params.Email != nil { 85 data.Set("Email", *params.Email) 86 } 87 if params != nil && params.StatusCallback != nil { 88 data.Set("StatusCallback", *params.StatusCallback) 89 } 90 if params != nil && params.RegulationSid != nil { 91 data.Set("RegulationSid", *params.RegulationSid) 92 } 93 if params != nil && params.IsoCountry != nil { 94 data.Set("IsoCountry", *params.IsoCountry) 95 } 96 if params != nil && params.EndUserType != nil { 97 data.Set("EndUserType", *params.EndUserType) 98 } 99 if params != nil && params.NumberType != nil { 100 data.Set("NumberType", *params.NumberType) 101 } 102 103 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 104 if err != nil { 105 return nil, err 106 } 107 108 defer resp.Body.Close() 109 110 ps := &NumbersV2Bundle{} 111 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 112 return nil, err 113 } 114 115 return ps, err 116 } 117 118 // Delete a specific Bundle. 119 func (c *ApiService) DeleteBundle(Sid string) error { 120 path := "/v2/RegulatoryCompliance/Bundles/{Sid}" 121 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 122 123 data := url.Values{} 124 headers := make(map[string]interface{}) 125 126 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 127 if err != nil { 128 return err 129 } 130 131 defer resp.Body.Close() 132 133 return nil 134 } 135 136 // Fetch a specific Bundle instance. 137 func (c *ApiService) FetchBundle(Sid string) (*NumbersV2Bundle, error) { 138 path := "/v2/RegulatoryCompliance/Bundles/{Sid}" 139 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 140 141 data := url.Values{} 142 headers := make(map[string]interface{}) 143 144 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 145 if err != nil { 146 return nil, err 147 } 148 149 defer resp.Body.Close() 150 151 ps := &NumbersV2Bundle{} 152 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 153 return nil, err 154 } 155 156 return ps, err 157 } 158 159 // Optional parameters for the method 'ListBundle' 160 type ListBundleParams struct { 161 // The verification status of the Bundle resource. Please refer to [Bundle Statuses](https://www.twilio.com/docs/phone-numbers/regulatory/api/bundles#bundle-statuses) for more details. 162 Status *string `json:"Status,omitempty"` 163 // The string that you assigned to describe the resource. The column can contain 255 variable characters. 164 FriendlyName *string `json:"FriendlyName,omitempty"` 165 // The unique string of a [Regulation resource](https://www.twilio.com/docs/phone-numbers/regulatory/api/regulations) that is associated to the Bundle resource. 166 RegulationSid *string `json:"RegulationSid,omitempty"` 167 // The 2-digit [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the Bundle's phone number country ownership request. 168 IsoCountry *string `json:"IsoCountry,omitempty"` 169 // The type of phone number of the Bundle's ownership request. Can be `local`, `mobile`, `national`, or `tollfree`. 170 NumberType *string `json:"NumberType,omitempty"` 171 // Indicates that the Bundle is a valid Bundle until a specified expiration date. 172 HasValidUntilDate *bool `json:"HasValidUntilDate,omitempty"` 173 // Can be `valid-until` or `date-updated`. Defaults to `date-created`. 174 SortBy *string `json:"SortBy,omitempty"` 175 // Default is `DESC`. Can be `ASC` or `DESC`. 176 SortDirection *string `json:"SortDirection,omitempty"` 177 // Date to filter Bundles having their `valid_until_date` before or after the specified date. Can be `ValidUntilDate>=` or `ValidUntilDate<=`. Both can be used in conjunction as well. [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) is the acceptable date format. 178 ValidUntilDate *time.Time `json:"ValidUntilDate,omitempty"` 179 // Date to filter Bundles having their `valid_until_date` before or after the specified date. Can be `ValidUntilDate>=` or `ValidUntilDate<=`. Both can be used in conjunction as well. [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) is the acceptable date format. 180 ValidUntilDateBefore *time.Time `json:"ValidUntilDate<,omitempty"` 181 // Date to filter Bundles having their `valid_until_date` before or after the specified date. Can be `ValidUntilDate>=` or `ValidUntilDate<=`. Both can be used in conjunction as well. [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) is the acceptable date format. 182 ValidUntilDateAfter *time.Time `json:"ValidUntilDate>,omitempty"` 183 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 184 PageSize *int `json:"PageSize,omitempty"` 185 // Max number of records to return. 186 Limit *int `json:"limit,omitempty"` 187 } 188 189 func (params *ListBundleParams) SetStatus(Status string) *ListBundleParams { 190 params.Status = &Status 191 return params 192 } 193 func (params *ListBundleParams) SetFriendlyName(FriendlyName string) *ListBundleParams { 194 params.FriendlyName = &FriendlyName 195 return params 196 } 197 func (params *ListBundleParams) SetRegulationSid(RegulationSid string) *ListBundleParams { 198 params.RegulationSid = &RegulationSid 199 return params 200 } 201 func (params *ListBundleParams) SetIsoCountry(IsoCountry string) *ListBundleParams { 202 params.IsoCountry = &IsoCountry 203 return params 204 } 205 func (params *ListBundleParams) SetNumberType(NumberType string) *ListBundleParams { 206 params.NumberType = &NumberType 207 return params 208 } 209 func (params *ListBundleParams) SetHasValidUntilDate(HasValidUntilDate bool) *ListBundleParams { 210 params.HasValidUntilDate = &HasValidUntilDate 211 return params 212 } 213 func (params *ListBundleParams) SetSortBy(SortBy string) *ListBundleParams { 214 params.SortBy = &SortBy 215 return params 216 } 217 func (params *ListBundleParams) SetSortDirection(SortDirection string) *ListBundleParams { 218 params.SortDirection = &SortDirection 219 return params 220 } 221 func (params *ListBundleParams) SetValidUntilDate(ValidUntilDate time.Time) *ListBundleParams { 222 params.ValidUntilDate = &ValidUntilDate 223 return params 224 } 225 func (params *ListBundleParams) SetValidUntilDateBefore(ValidUntilDateBefore time.Time) *ListBundleParams { 226 params.ValidUntilDateBefore = &ValidUntilDateBefore 227 return params 228 } 229 func (params *ListBundleParams) SetValidUntilDateAfter(ValidUntilDateAfter time.Time) *ListBundleParams { 230 params.ValidUntilDateAfter = &ValidUntilDateAfter 231 return params 232 } 233 func (params *ListBundleParams) SetPageSize(PageSize int) *ListBundleParams { 234 params.PageSize = &PageSize 235 return params 236 } 237 func (params *ListBundleParams) SetLimit(Limit int) *ListBundleParams { 238 params.Limit = &Limit 239 return params 240 } 241 242 // Retrieve a single page of Bundle records from the API. Request is executed immediately. 243 func (c *ApiService) PageBundle(params *ListBundleParams, pageToken, pageNumber string) (*ListBundleResponse, error) { 244 path := "/v2/RegulatoryCompliance/Bundles" 245 246 data := url.Values{} 247 headers := make(map[string]interface{}) 248 249 if params != nil && params.Status != nil { 250 data.Set("Status", *params.Status) 251 } 252 if params != nil && params.FriendlyName != nil { 253 data.Set("FriendlyName", *params.FriendlyName) 254 } 255 if params != nil && params.RegulationSid != nil { 256 data.Set("RegulationSid", *params.RegulationSid) 257 } 258 if params != nil && params.IsoCountry != nil { 259 data.Set("IsoCountry", *params.IsoCountry) 260 } 261 if params != nil && params.NumberType != nil { 262 data.Set("NumberType", *params.NumberType) 263 } 264 if params != nil && params.HasValidUntilDate != nil { 265 data.Set("HasValidUntilDate", fmt.Sprint(*params.HasValidUntilDate)) 266 } 267 if params != nil && params.SortBy != nil { 268 data.Set("SortBy", *params.SortBy) 269 } 270 if params != nil && params.SortDirection != nil { 271 data.Set("SortDirection", *params.SortDirection) 272 } 273 if params != nil && params.ValidUntilDate != nil { 274 data.Set("ValidUntilDate", fmt.Sprint((*params.ValidUntilDate).Format(time.RFC3339))) 275 } 276 if params != nil && params.ValidUntilDateBefore != nil { 277 data.Set("ValidUntilDate<", fmt.Sprint((*params.ValidUntilDateBefore).Format(time.RFC3339))) 278 } 279 if params != nil && params.ValidUntilDateAfter != nil { 280 data.Set("ValidUntilDate>", fmt.Sprint((*params.ValidUntilDateAfter).Format(time.RFC3339))) 281 } 282 if params != nil && params.PageSize != nil { 283 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 284 } 285 286 if pageToken != "" { 287 data.Set("PageToken", pageToken) 288 } 289 if pageNumber != "" { 290 data.Set("Page", pageNumber) 291 } 292 293 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 294 if err != nil { 295 return nil, err 296 } 297 298 defer resp.Body.Close() 299 300 ps := &ListBundleResponse{} 301 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 302 return nil, err 303 } 304 305 return ps, err 306 } 307 308 // Lists Bundle records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 309 func (c *ApiService) ListBundle(params *ListBundleParams) ([]NumbersV2Bundle, error) { 310 response, errors := c.StreamBundle(params) 311 312 records := make([]NumbersV2Bundle, 0) 313 for record := range response { 314 records = append(records, record) 315 } 316 317 if err := <-errors; err != nil { 318 return nil, err 319 } 320 321 return records, nil 322 } 323 324 // Streams Bundle records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 325 func (c *ApiService) StreamBundle(params *ListBundleParams) (chan NumbersV2Bundle, chan error) { 326 if params == nil { 327 params = &ListBundleParams{} 328 } 329 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 330 331 recordChannel := make(chan NumbersV2Bundle, 1) 332 errorChannel := make(chan error, 1) 333 334 response, err := c.PageBundle(params, "", "") 335 if err != nil { 336 errorChannel <- err 337 close(recordChannel) 338 close(errorChannel) 339 } else { 340 go c.streamBundle(response, params, recordChannel, errorChannel) 341 } 342 343 return recordChannel, errorChannel 344 } 345 346 func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBundleParams, recordChannel chan NumbersV2Bundle, errorChannel chan error) { 347 curRecord := 1 348 349 for response != nil { 350 responseRecords := response.Results 351 for item := range responseRecords { 352 recordChannel <- responseRecords[item] 353 curRecord += 1 354 if params.Limit != nil && *params.Limit < curRecord { 355 close(recordChannel) 356 close(errorChannel) 357 return 358 } 359 } 360 361 record, err := client.GetNext(c.baseURL, response, c.getNextListBundleResponse) 362 if err != nil { 363 errorChannel <- err 364 break 365 } else if record == nil { 366 break 367 } 368 369 response = record.(*ListBundleResponse) 370 } 371 372 close(recordChannel) 373 close(errorChannel) 374 } 375 376 func (c *ApiService) getNextListBundleResponse(nextPageUrl string) (interface{}, error) { 377 if nextPageUrl == "" { 378 return nil, nil 379 } 380 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 381 if err != nil { 382 return nil, err 383 } 384 385 defer resp.Body.Close() 386 387 ps := &ListBundleResponse{} 388 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 389 return nil, err 390 } 391 return ps, nil 392 } 393 394 // Optional parameters for the method 'UpdateBundle' 395 type UpdateBundleParams struct { 396 // 397 Status *string `json:"Status,omitempty"` 398 // The URL we call to inform your application of status changes. 399 StatusCallback *string `json:"StatusCallback,omitempty"` 400 // The string that you assigned to describe the resource. 401 FriendlyName *string `json:"FriendlyName,omitempty"` 402 // The email address that will receive updates when the Bundle resource changes status. 403 Email *string `json:"Email,omitempty"` 404 } 405 406 func (params *UpdateBundleParams) SetStatus(Status string) *UpdateBundleParams { 407 params.Status = &Status 408 return params 409 } 410 func (params *UpdateBundleParams) SetStatusCallback(StatusCallback string) *UpdateBundleParams { 411 params.StatusCallback = &StatusCallback 412 return params 413 } 414 func (params *UpdateBundleParams) SetFriendlyName(FriendlyName string) *UpdateBundleParams { 415 params.FriendlyName = &FriendlyName 416 return params 417 } 418 func (params *UpdateBundleParams) SetEmail(Email string) *UpdateBundleParams { 419 params.Email = &Email 420 return params 421 } 422 423 // Updates a Bundle in an account. 424 func (c *ApiService) UpdateBundle(Sid string, params *UpdateBundleParams) (*NumbersV2Bundle, error) { 425 path := "/v2/RegulatoryCompliance/Bundles/{Sid}" 426 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 427 428 data := url.Values{} 429 headers := make(map[string]interface{}) 430 431 if params != nil && params.Status != nil { 432 data.Set("Status", *params.Status) 433 } 434 if params != nil && params.StatusCallback != nil { 435 data.Set("StatusCallback", *params.StatusCallback) 436 } 437 if params != nil && params.FriendlyName != nil { 438 data.Set("FriendlyName", *params.FriendlyName) 439 } 440 if params != nil && params.Email != nil { 441 data.Set("Email", *params.Email) 442 } 443 444 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 445 if err != nil { 446 return nil, err 447 } 448 449 defer resp.Body.Close() 450 451 ps := &NumbersV2Bundle{} 452 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 453 return nil, err 454 } 455 456 return ps, err 457 }