github.com/twilio/twilio-go@v1.20.1/rest/messaging/v1/a2p_brand_registrations.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Messaging 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 'CreateBrandRegistrations' 27 type CreateBrandRegistrationsParams struct { 28 // Customer Profile Bundle Sid. 29 CustomerProfileBundleSid *string `json:"CustomerProfileBundleSid,omitempty"` 30 // A2P Messaging Profile Bundle Sid. 31 A2PProfileBundleSid *string `json:"A2PProfileBundleSid,omitempty"` 32 // Type of brand being created. One of: \\\"STANDARD\\\", \\\"SOLE_PROPRIETOR\\\". SOLE_PROPRIETOR is for low volume, SOLE_PROPRIETOR use cases. STANDARD is for all other use cases. 33 BrandType *string `json:"BrandType,omitempty"` 34 // A boolean that specifies whether brand should be a mock or not. If true, brand will be registered as a mock brand. Defaults to false if no value is provided. 35 Mock *bool `json:"Mock,omitempty"` 36 // A flag to disable automatic secondary vetting for brands which it would otherwise be done. 37 SkipAutomaticSecVet *bool `json:"SkipAutomaticSecVet,omitempty"` 38 } 39 40 func (params *CreateBrandRegistrationsParams) SetCustomerProfileBundleSid(CustomerProfileBundleSid string) *CreateBrandRegistrationsParams { 41 params.CustomerProfileBundleSid = &CustomerProfileBundleSid 42 return params 43 } 44 func (params *CreateBrandRegistrationsParams) SetA2PProfileBundleSid(A2PProfileBundleSid string) *CreateBrandRegistrationsParams { 45 params.A2PProfileBundleSid = &A2PProfileBundleSid 46 return params 47 } 48 func (params *CreateBrandRegistrationsParams) SetBrandType(BrandType string) *CreateBrandRegistrationsParams { 49 params.BrandType = &BrandType 50 return params 51 } 52 func (params *CreateBrandRegistrationsParams) SetMock(Mock bool) *CreateBrandRegistrationsParams { 53 params.Mock = &Mock 54 return params 55 } 56 func (params *CreateBrandRegistrationsParams) SetSkipAutomaticSecVet(SkipAutomaticSecVet bool) *CreateBrandRegistrationsParams { 57 params.SkipAutomaticSecVet = &SkipAutomaticSecVet 58 return params 59 } 60 61 // 62 func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsParams) (*MessagingV1BrandRegistrations, error) { 63 path := "/v1/a2p/BrandRegistrations" 64 65 data := url.Values{} 66 headers := make(map[string]interface{}) 67 68 if params != nil && params.CustomerProfileBundleSid != nil { 69 data.Set("CustomerProfileBundleSid", *params.CustomerProfileBundleSid) 70 } 71 if params != nil && params.A2PProfileBundleSid != nil { 72 data.Set("A2PProfileBundleSid", *params.A2PProfileBundleSid) 73 } 74 if params != nil && params.BrandType != nil { 75 data.Set("BrandType", *params.BrandType) 76 } 77 if params != nil && params.Mock != nil { 78 data.Set("Mock", fmt.Sprint(*params.Mock)) 79 } 80 if params != nil && params.SkipAutomaticSecVet != nil { 81 data.Set("SkipAutomaticSecVet", fmt.Sprint(*params.SkipAutomaticSecVet)) 82 } 83 84 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 85 if err != nil { 86 return nil, err 87 } 88 89 defer resp.Body.Close() 90 91 ps := &MessagingV1BrandRegistrations{} 92 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 93 return nil, err 94 } 95 96 return ps, err 97 } 98 99 // 100 func (c *ApiService) FetchBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { 101 path := "/v1/a2p/BrandRegistrations/{Sid}" 102 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 103 104 data := url.Values{} 105 headers := make(map[string]interface{}) 106 107 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 108 if err != nil { 109 return nil, err 110 } 111 112 defer resp.Body.Close() 113 114 ps := &MessagingV1BrandRegistrations{} 115 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 116 return nil, err 117 } 118 119 return ps, err 120 } 121 122 // Optional parameters for the method 'ListBrandRegistrations' 123 type ListBrandRegistrationsParams struct { 124 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 125 PageSize *int `json:"PageSize,omitempty"` 126 // Max number of records to return. 127 Limit *int `json:"limit,omitempty"` 128 } 129 130 func (params *ListBrandRegistrationsParams) SetPageSize(PageSize int) *ListBrandRegistrationsParams { 131 params.PageSize = &PageSize 132 return params 133 } 134 func (params *ListBrandRegistrationsParams) SetLimit(Limit int) *ListBrandRegistrationsParams { 135 params.Limit = &Limit 136 return params 137 } 138 139 // Retrieve a single page of BrandRegistrations records from the API. Request is executed immediately. 140 func (c *ApiService) PageBrandRegistrations(params *ListBrandRegistrationsParams, pageToken, pageNumber string) (*ListBrandRegistrationsResponse, error) { 141 path := "/v1/a2p/BrandRegistrations" 142 143 data := url.Values{} 144 headers := make(map[string]interface{}) 145 146 if params != nil && params.PageSize != nil { 147 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 148 } 149 150 if pageToken != "" { 151 data.Set("PageToken", pageToken) 152 } 153 if pageNumber != "" { 154 data.Set("Page", pageNumber) 155 } 156 157 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 158 if err != nil { 159 return nil, err 160 } 161 162 defer resp.Body.Close() 163 164 ps := &ListBrandRegistrationsResponse{} 165 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 166 return nil, err 167 } 168 169 return ps, err 170 } 171 172 // Lists BrandRegistrations records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 173 func (c *ApiService) ListBrandRegistrations(params *ListBrandRegistrationsParams) ([]MessagingV1BrandRegistrations, error) { 174 response, errors := c.StreamBrandRegistrations(params) 175 176 records := make([]MessagingV1BrandRegistrations, 0) 177 for record := range response { 178 records = append(records, record) 179 } 180 181 if err := <-errors; err != nil { 182 return nil, err 183 } 184 185 return records, nil 186 } 187 188 // Streams BrandRegistrations records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 189 func (c *ApiService) StreamBrandRegistrations(params *ListBrandRegistrationsParams) (chan MessagingV1BrandRegistrations, chan error) { 190 if params == nil { 191 params = &ListBrandRegistrationsParams{} 192 } 193 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 194 195 recordChannel := make(chan MessagingV1BrandRegistrations, 1) 196 errorChannel := make(chan error, 1) 197 198 response, err := c.PageBrandRegistrations(params, "", "") 199 if err != nil { 200 errorChannel <- err 201 close(recordChannel) 202 close(errorChannel) 203 } else { 204 go c.streamBrandRegistrations(response, params, recordChannel, errorChannel) 205 } 206 207 return recordChannel, errorChannel 208 } 209 210 func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsResponse, params *ListBrandRegistrationsParams, recordChannel chan MessagingV1BrandRegistrations, errorChannel chan error) { 211 curRecord := 1 212 213 for response != nil { 214 responseRecords := response.Data 215 for item := range responseRecords { 216 recordChannel <- responseRecords[item] 217 curRecord += 1 218 if params.Limit != nil && *params.Limit < curRecord { 219 close(recordChannel) 220 close(errorChannel) 221 return 222 } 223 } 224 225 record, err := client.GetNext(c.baseURL, response, c.getNextListBrandRegistrationsResponse) 226 if err != nil { 227 errorChannel <- err 228 break 229 } else if record == nil { 230 break 231 } 232 233 response = record.(*ListBrandRegistrationsResponse) 234 } 235 236 close(recordChannel) 237 close(errorChannel) 238 } 239 240 func (c *ApiService) getNextListBrandRegistrationsResponse(nextPageUrl string) (interface{}, error) { 241 if nextPageUrl == "" { 242 return nil, nil 243 } 244 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 245 if err != nil { 246 return nil, err 247 } 248 249 defer resp.Body.Close() 250 251 ps := &ListBrandRegistrationsResponse{} 252 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 253 return nil, err 254 } 255 return ps, nil 256 } 257 258 // 259 func (c *ApiService) UpdateBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { 260 path := "/v1/a2p/BrandRegistrations/{Sid}" 261 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 262 263 data := url.Values{} 264 headers := make(map[string]interface{}) 265 266 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 267 if err != nil { 268 return nil, err 269 } 270 271 defer resp.Body.Close() 272 273 ps := &MessagingV1BrandRegistrations{} 274 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 275 return nil, err 276 } 277 278 return ps, err 279 }