github.com/twilio/twilio-go@v1.20.1/rest/supersim/v1/fleets.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Supersim 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 'CreateFleet' 27 type CreateFleetParams struct { 28 // The SID or unique name of the Network Access Profile that will control which cellular networks the Fleet's SIMs can connect to. 29 NetworkAccessProfile *string `json:"NetworkAccessProfile,omitempty"` 30 // An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource. 31 UniqueName *string `json:"UniqueName,omitempty"` 32 // Defines whether SIMs in the Fleet are capable of using 2G/3G/4G/LTE/CAT-M data connectivity. Defaults to `true`. 33 DataEnabled *bool `json:"DataEnabled,omitempty"` 34 // The total data usage (download and upload combined) in Megabytes that each Super SIM assigned to the Fleet can consume during a billing period (normally one month). Value must be between 1MB (1) and 2TB (2,000,000). Defaults to 1GB (1,000). 35 DataLimit *int `json:"DataLimit,omitempty"` 36 // The URL that will receive a webhook when a Super SIM in the Fleet is used to send an IP Command from your device to a special IP address. Your server should respond with an HTTP status code in the 200 range; any response body will be ignored. 37 IpCommandsUrl *string `json:"IpCommandsUrl,omitempty"` 38 // A string representing the HTTP method to use when making a request to `ip_commands_url`. Can be one of `POST` or `GET`. Defaults to `POST`. 39 IpCommandsMethod *string `json:"IpCommandsMethod,omitempty"` 40 // Defines whether SIMs in the Fleet are capable of sending and receiving machine-to-machine SMS via Commands. Defaults to `true`. 41 SmsCommandsEnabled *bool `json:"SmsCommandsEnabled,omitempty"` 42 // The URL that will receive a webhook when a Super SIM in the Fleet is used to send an SMS from your device to the SMS Commands number. Your server should respond with an HTTP status code in the 200 range; any response body will be ignored. 43 SmsCommandsUrl *string `json:"SmsCommandsUrl,omitempty"` 44 // A string representing the HTTP method to use when making a request to `sms_commands_url`. Can be one of `POST` or `GET`. Defaults to `POST`. 45 SmsCommandsMethod *string `json:"SmsCommandsMethod,omitempty"` 46 } 47 48 func (params *CreateFleetParams) SetNetworkAccessProfile(NetworkAccessProfile string) *CreateFleetParams { 49 params.NetworkAccessProfile = &NetworkAccessProfile 50 return params 51 } 52 func (params *CreateFleetParams) SetUniqueName(UniqueName string) *CreateFleetParams { 53 params.UniqueName = &UniqueName 54 return params 55 } 56 func (params *CreateFleetParams) SetDataEnabled(DataEnabled bool) *CreateFleetParams { 57 params.DataEnabled = &DataEnabled 58 return params 59 } 60 func (params *CreateFleetParams) SetDataLimit(DataLimit int) *CreateFleetParams { 61 params.DataLimit = &DataLimit 62 return params 63 } 64 func (params *CreateFleetParams) SetIpCommandsUrl(IpCommandsUrl string) *CreateFleetParams { 65 params.IpCommandsUrl = &IpCommandsUrl 66 return params 67 } 68 func (params *CreateFleetParams) SetIpCommandsMethod(IpCommandsMethod string) *CreateFleetParams { 69 params.IpCommandsMethod = &IpCommandsMethod 70 return params 71 } 72 func (params *CreateFleetParams) SetSmsCommandsEnabled(SmsCommandsEnabled bool) *CreateFleetParams { 73 params.SmsCommandsEnabled = &SmsCommandsEnabled 74 return params 75 } 76 func (params *CreateFleetParams) SetSmsCommandsUrl(SmsCommandsUrl string) *CreateFleetParams { 77 params.SmsCommandsUrl = &SmsCommandsUrl 78 return params 79 } 80 func (params *CreateFleetParams) SetSmsCommandsMethod(SmsCommandsMethod string) *CreateFleetParams { 81 params.SmsCommandsMethod = &SmsCommandsMethod 82 return params 83 } 84 85 // Create a Fleet 86 func (c *ApiService) CreateFleet(params *CreateFleetParams) (*SupersimV1Fleet, error) { 87 path := "/v1/Fleets" 88 89 data := url.Values{} 90 headers := make(map[string]interface{}) 91 92 if params != nil && params.NetworkAccessProfile != nil { 93 data.Set("NetworkAccessProfile", *params.NetworkAccessProfile) 94 } 95 if params != nil && params.UniqueName != nil { 96 data.Set("UniqueName", *params.UniqueName) 97 } 98 if params != nil && params.DataEnabled != nil { 99 data.Set("DataEnabled", fmt.Sprint(*params.DataEnabled)) 100 } 101 if params != nil && params.DataLimit != nil { 102 data.Set("DataLimit", fmt.Sprint(*params.DataLimit)) 103 } 104 if params != nil && params.IpCommandsUrl != nil { 105 data.Set("IpCommandsUrl", *params.IpCommandsUrl) 106 } 107 if params != nil && params.IpCommandsMethod != nil { 108 data.Set("IpCommandsMethod", *params.IpCommandsMethod) 109 } 110 if params != nil && params.SmsCommandsEnabled != nil { 111 data.Set("SmsCommandsEnabled", fmt.Sprint(*params.SmsCommandsEnabled)) 112 } 113 if params != nil && params.SmsCommandsUrl != nil { 114 data.Set("SmsCommandsUrl", *params.SmsCommandsUrl) 115 } 116 if params != nil && params.SmsCommandsMethod != nil { 117 data.Set("SmsCommandsMethod", *params.SmsCommandsMethod) 118 } 119 120 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 121 if err != nil { 122 return nil, err 123 } 124 125 defer resp.Body.Close() 126 127 ps := &SupersimV1Fleet{} 128 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 129 return nil, err 130 } 131 132 return ps, err 133 } 134 135 // Fetch a Fleet instance from your account. 136 func (c *ApiService) FetchFleet(Sid string) (*SupersimV1Fleet, error) { 137 path := "/v1/Fleets/{Sid}" 138 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 139 140 data := url.Values{} 141 headers := make(map[string]interface{}) 142 143 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 144 if err != nil { 145 return nil, err 146 } 147 148 defer resp.Body.Close() 149 150 ps := &SupersimV1Fleet{} 151 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 152 return nil, err 153 } 154 155 return ps, err 156 } 157 158 // Optional parameters for the method 'ListFleet' 159 type ListFleetParams struct { 160 // The SID or unique name of the Network Access Profile that controls which cellular networks the Fleet's SIMs can connect to. 161 NetworkAccessProfile *string `json:"NetworkAccessProfile,omitempty"` 162 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 163 PageSize *int `json:"PageSize,omitempty"` 164 // Max number of records to return. 165 Limit *int `json:"limit,omitempty"` 166 } 167 168 func (params *ListFleetParams) SetNetworkAccessProfile(NetworkAccessProfile string) *ListFleetParams { 169 params.NetworkAccessProfile = &NetworkAccessProfile 170 return params 171 } 172 func (params *ListFleetParams) SetPageSize(PageSize int) *ListFleetParams { 173 params.PageSize = &PageSize 174 return params 175 } 176 func (params *ListFleetParams) SetLimit(Limit int) *ListFleetParams { 177 params.Limit = &Limit 178 return params 179 } 180 181 // Retrieve a single page of Fleet records from the API. Request is executed immediately. 182 func (c *ApiService) PageFleet(params *ListFleetParams, pageToken, pageNumber string) (*ListFleetResponse, error) { 183 path := "/v1/Fleets" 184 185 data := url.Values{} 186 headers := make(map[string]interface{}) 187 188 if params != nil && params.NetworkAccessProfile != nil { 189 data.Set("NetworkAccessProfile", *params.NetworkAccessProfile) 190 } 191 if params != nil && params.PageSize != nil { 192 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 193 } 194 195 if pageToken != "" { 196 data.Set("PageToken", pageToken) 197 } 198 if pageNumber != "" { 199 data.Set("Page", pageNumber) 200 } 201 202 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 203 if err != nil { 204 return nil, err 205 } 206 207 defer resp.Body.Close() 208 209 ps := &ListFleetResponse{} 210 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 211 return nil, err 212 } 213 214 return ps, err 215 } 216 217 // Lists Fleet records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 218 func (c *ApiService) ListFleet(params *ListFleetParams) ([]SupersimV1Fleet, error) { 219 response, errors := c.StreamFleet(params) 220 221 records := make([]SupersimV1Fleet, 0) 222 for record := range response { 223 records = append(records, record) 224 } 225 226 if err := <-errors; err != nil { 227 return nil, err 228 } 229 230 return records, nil 231 } 232 233 // Streams Fleet records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 234 func (c *ApiService) StreamFleet(params *ListFleetParams) (chan SupersimV1Fleet, chan error) { 235 if params == nil { 236 params = &ListFleetParams{} 237 } 238 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 239 240 recordChannel := make(chan SupersimV1Fleet, 1) 241 errorChannel := make(chan error, 1) 242 243 response, err := c.PageFleet(params, "", "") 244 if err != nil { 245 errorChannel <- err 246 close(recordChannel) 247 close(errorChannel) 248 } else { 249 go c.streamFleet(response, params, recordChannel, errorChannel) 250 } 251 252 return recordChannel, errorChannel 253 } 254 255 func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetParams, recordChannel chan SupersimV1Fleet, errorChannel chan error) { 256 curRecord := 1 257 258 for response != nil { 259 responseRecords := response.Fleets 260 for item := range responseRecords { 261 recordChannel <- responseRecords[item] 262 curRecord += 1 263 if params.Limit != nil && *params.Limit < curRecord { 264 close(recordChannel) 265 close(errorChannel) 266 return 267 } 268 } 269 270 record, err := client.GetNext(c.baseURL, response, c.getNextListFleetResponse) 271 if err != nil { 272 errorChannel <- err 273 break 274 } else if record == nil { 275 break 276 } 277 278 response = record.(*ListFleetResponse) 279 } 280 281 close(recordChannel) 282 close(errorChannel) 283 } 284 285 func (c *ApiService) getNextListFleetResponse(nextPageUrl string) (interface{}, error) { 286 if nextPageUrl == "" { 287 return nil, nil 288 } 289 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 290 if err != nil { 291 return nil, err 292 } 293 294 defer resp.Body.Close() 295 296 ps := &ListFleetResponse{} 297 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 298 return nil, err 299 } 300 return ps, nil 301 } 302 303 // Optional parameters for the method 'UpdateFleet' 304 type UpdateFleetParams struct { 305 // An application-defined string that uniquely identifies the resource. It can be used in place of the resource's `sid` in the URL to address the resource. 306 UniqueName *string `json:"UniqueName,omitempty"` 307 // The SID or unique name of the Network Access Profile that will control which cellular networks the Fleet's SIMs can connect to. 308 NetworkAccessProfile *string `json:"NetworkAccessProfile,omitempty"` 309 // The URL that will receive a webhook when a Super SIM in the Fleet is used to send an IP Command from your device to a special IP address. Your server should respond with an HTTP status code in the 200 range; any response body will be ignored. 310 IpCommandsUrl *string `json:"IpCommandsUrl,omitempty"` 311 // A string representing the HTTP method to use when making a request to `ip_commands_url`. Can be one of `POST` or `GET`. Defaults to `POST`. 312 IpCommandsMethod *string `json:"IpCommandsMethod,omitempty"` 313 // The URL that will receive a webhook when a Super SIM in the Fleet is used to send an SMS from your device to the SMS Commands number. Your server should respond with an HTTP status code in the 200 range; any response body will be ignored. 314 SmsCommandsUrl *string `json:"SmsCommandsUrl,omitempty"` 315 // A string representing the HTTP method to use when making a request to `sms_commands_url`. Can be one of `POST` or `GET`. Defaults to `POST`. 316 SmsCommandsMethod *string `json:"SmsCommandsMethod,omitempty"` 317 // The total data usage (download and upload combined) in Megabytes that each Super SIM assigned to the Fleet can consume during a billing period (normally one month). Value must be between 1MB (1) and 2TB (2,000,000). Defaults to 1GB (1,000). 318 DataLimit *int `json:"DataLimit,omitempty"` 319 } 320 321 func (params *UpdateFleetParams) SetUniqueName(UniqueName string) *UpdateFleetParams { 322 params.UniqueName = &UniqueName 323 return params 324 } 325 func (params *UpdateFleetParams) SetNetworkAccessProfile(NetworkAccessProfile string) *UpdateFleetParams { 326 params.NetworkAccessProfile = &NetworkAccessProfile 327 return params 328 } 329 func (params *UpdateFleetParams) SetIpCommandsUrl(IpCommandsUrl string) *UpdateFleetParams { 330 params.IpCommandsUrl = &IpCommandsUrl 331 return params 332 } 333 func (params *UpdateFleetParams) SetIpCommandsMethod(IpCommandsMethod string) *UpdateFleetParams { 334 params.IpCommandsMethod = &IpCommandsMethod 335 return params 336 } 337 func (params *UpdateFleetParams) SetSmsCommandsUrl(SmsCommandsUrl string) *UpdateFleetParams { 338 params.SmsCommandsUrl = &SmsCommandsUrl 339 return params 340 } 341 func (params *UpdateFleetParams) SetSmsCommandsMethod(SmsCommandsMethod string) *UpdateFleetParams { 342 params.SmsCommandsMethod = &SmsCommandsMethod 343 return params 344 } 345 func (params *UpdateFleetParams) SetDataLimit(DataLimit int) *UpdateFleetParams { 346 params.DataLimit = &DataLimit 347 return params 348 } 349 350 // Updates the given properties of a Super SIM Fleet instance from your account. 351 func (c *ApiService) UpdateFleet(Sid string, params *UpdateFleetParams) (*SupersimV1Fleet, error) { 352 path := "/v1/Fleets/{Sid}" 353 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 354 355 data := url.Values{} 356 headers := make(map[string]interface{}) 357 358 if params != nil && params.UniqueName != nil { 359 data.Set("UniqueName", *params.UniqueName) 360 } 361 if params != nil && params.NetworkAccessProfile != nil { 362 data.Set("NetworkAccessProfile", *params.NetworkAccessProfile) 363 } 364 if params != nil && params.IpCommandsUrl != nil { 365 data.Set("IpCommandsUrl", *params.IpCommandsUrl) 366 } 367 if params != nil && params.IpCommandsMethod != nil { 368 data.Set("IpCommandsMethod", *params.IpCommandsMethod) 369 } 370 if params != nil && params.SmsCommandsUrl != nil { 371 data.Set("SmsCommandsUrl", *params.SmsCommandsUrl) 372 } 373 if params != nil && params.SmsCommandsMethod != nil { 374 data.Set("SmsCommandsMethod", *params.SmsCommandsMethod) 375 } 376 if params != nil && params.DataLimit != nil { 377 data.Set("DataLimit", fmt.Sprint(*params.DataLimit)) 378 } 379 380 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 381 if err != nil { 382 return nil, err 383 } 384 385 defer resp.Body.Close() 386 387 ps := &SupersimV1Fleet{} 388 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 389 return nil, err 390 } 391 392 return ps, err 393 }