github.com/twilio/twilio-go@v1.20.1/rest/supersim/v1/network_access_profiles.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 'CreateNetworkAccessProfile' 27 type CreateNetworkAccessProfileParams struct { 28 // 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. 29 UniqueName *string `json:"UniqueName,omitempty"` 30 // List of Network SIDs that this Network Access Profile will allow connections to. 31 Networks *[]string `json:"Networks,omitempty"` 32 } 33 34 func (params *CreateNetworkAccessProfileParams) SetUniqueName(UniqueName string) *CreateNetworkAccessProfileParams { 35 params.UniqueName = &UniqueName 36 return params 37 } 38 func (params *CreateNetworkAccessProfileParams) SetNetworks(Networks []string) *CreateNetworkAccessProfileParams { 39 params.Networks = &Networks 40 return params 41 } 42 43 // Create a new Network Access Profile 44 func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { 45 path := "/v1/NetworkAccessProfiles" 46 47 data := url.Values{} 48 headers := make(map[string]interface{}) 49 50 if params != nil && params.UniqueName != nil { 51 data.Set("UniqueName", *params.UniqueName) 52 } 53 if params != nil && params.Networks != nil { 54 for _, item := range *params.Networks { 55 data.Add("Networks", item) 56 } 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 := &SupersimV1NetworkAccessProfile{} 67 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 68 return nil, err 69 } 70 71 return ps, err 72 } 73 74 // Fetch a Network Access Profile instance from your account. 75 func (c *ApiService) FetchNetworkAccessProfile(Sid string) (*SupersimV1NetworkAccessProfile, error) { 76 path := "/v1/NetworkAccessProfiles/{Sid}" 77 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 78 79 data := url.Values{} 80 headers := make(map[string]interface{}) 81 82 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 83 if err != nil { 84 return nil, err 85 } 86 87 defer resp.Body.Close() 88 89 ps := &SupersimV1NetworkAccessProfile{} 90 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 91 return nil, err 92 } 93 94 return ps, err 95 } 96 97 // Optional parameters for the method 'ListNetworkAccessProfile' 98 type ListNetworkAccessProfileParams struct { 99 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 100 PageSize *int `json:"PageSize,omitempty"` 101 // Max number of records to return. 102 Limit *int `json:"limit,omitempty"` 103 } 104 105 func (params *ListNetworkAccessProfileParams) SetPageSize(PageSize int) *ListNetworkAccessProfileParams { 106 params.PageSize = &PageSize 107 return params 108 } 109 func (params *ListNetworkAccessProfileParams) SetLimit(Limit int) *ListNetworkAccessProfileParams { 110 params.Limit = &Limit 111 return params 112 } 113 114 // Retrieve a single page of NetworkAccessProfile records from the API. Request is executed immediately. 115 func (c *ApiService) PageNetworkAccessProfile(params *ListNetworkAccessProfileParams, pageToken, pageNumber string) (*ListNetworkAccessProfileResponse, error) { 116 path := "/v1/NetworkAccessProfiles" 117 118 data := url.Values{} 119 headers := make(map[string]interface{}) 120 121 if params != nil && params.PageSize != nil { 122 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 123 } 124 125 if pageToken != "" { 126 data.Set("PageToken", pageToken) 127 } 128 if pageNumber != "" { 129 data.Set("Page", pageNumber) 130 } 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 := &ListNetworkAccessProfileResponse{} 140 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 141 return nil, err 142 } 143 144 return ps, err 145 } 146 147 // Lists NetworkAccessProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 148 func (c *ApiService) ListNetworkAccessProfile(params *ListNetworkAccessProfileParams) ([]SupersimV1NetworkAccessProfile, error) { 149 response, errors := c.StreamNetworkAccessProfile(params) 150 151 records := make([]SupersimV1NetworkAccessProfile, 0) 152 for record := range response { 153 records = append(records, record) 154 } 155 156 if err := <-errors; err != nil { 157 return nil, err 158 } 159 160 return records, nil 161 } 162 163 // Streams NetworkAccessProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 164 func (c *ApiService) StreamNetworkAccessProfile(params *ListNetworkAccessProfileParams) (chan SupersimV1NetworkAccessProfile, chan error) { 165 if params == nil { 166 params = &ListNetworkAccessProfileParams{} 167 } 168 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 169 170 recordChannel := make(chan SupersimV1NetworkAccessProfile, 1) 171 errorChannel := make(chan error, 1) 172 173 response, err := c.PageNetworkAccessProfile(params, "", "") 174 if err != nil { 175 errorChannel <- err 176 close(recordChannel) 177 close(errorChannel) 178 } else { 179 go c.streamNetworkAccessProfile(response, params, recordChannel, errorChannel) 180 } 181 182 return recordChannel, errorChannel 183 } 184 185 func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfileResponse, params *ListNetworkAccessProfileParams, recordChannel chan SupersimV1NetworkAccessProfile, errorChannel chan error) { 186 curRecord := 1 187 188 for response != nil { 189 responseRecords := response.NetworkAccessProfiles 190 for item := range responseRecords { 191 recordChannel <- responseRecords[item] 192 curRecord += 1 193 if params.Limit != nil && *params.Limit < curRecord { 194 close(recordChannel) 195 close(errorChannel) 196 return 197 } 198 } 199 200 record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkAccessProfileResponse) 201 if err != nil { 202 errorChannel <- err 203 break 204 } else if record == nil { 205 break 206 } 207 208 response = record.(*ListNetworkAccessProfileResponse) 209 } 210 211 close(recordChannel) 212 close(errorChannel) 213 } 214 215 func (c *ApiService) getNextListNetworkAccessProfileResponse(nextPageUrl string) (interface{}, error) { 216 if nextPageUrl == "" { 217 return nil, nil 218 } 219 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 220 if err != nil { 221 return nil, err 222 } 223 224 defer resp.Body.Close() 225 226 ps := &ListNetworkAccessProfileResponse{} 227 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 228 return nil, err 229 } 230 return ps, nil 231 } 232 233 // Optional parameters for the method 'UpdateNetworkAccessProfile' 234 type UpdateNetworkAccessProfileParams struct { 235 // The new unique name of the Network Access Profile. 236 UniqueName *string `json:"UniqueName,omitempty"` 237 } 238 239 func (params *UpdateNetworkAccessProfileParams) SetUniqueName(UniqueName string) *UpdateNetworkAccessProfileParams { 240 params.UniqueName = &UniqueName 241 return params 242 } 243 244 // Updates the given properties of a Network Access Profile in your account. 245 func (c *ApiService) UpdateNetworkAccessProfile(Sid string, params *UpdateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { 246 path := "/v1/NetworkAccessProfiles/{Sid}" 247 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 248 249 data := url.Values{} 250 headers := make(map[string]interface{}) 251 252 if params != nil && params.UniqueName != nil { 253 data.Set("UniqueName", *params.UniqueName) 254 } 255 256 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 257 if err != nil { 258 return nil, err 259 } 260 261 defer resp.Body.Close() 262 263 ps := &SupersimV1NetworkAccessProfile{} 264 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 265 return nil, err 266 } 267 268 return ps, err 269 }