/
settings_updates.go
177 lines (148 loc) · 5.04 KB
/
settings_updates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Supersim
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package openapi
import (
"encoding/json"
"fmt"
"net/url"
"github.com/twilio/twilio-go/client"
)
// Optional parameters for the method 'ListSettingsUpdate'
type ListSettingsUpdateParams struct {
// Filter the Settings Updates by a Super SIM's SID or UniqueName.
Sim *string `json:"Sim,omitempty"`
// Filter the Settings Updates by status. Can be `scheduled`, `in-progress`, `successful`, or `failed`.
Status *string `json:"Status,omitempty"`
// How many resources to return in each list page. The default is 50, and the maximum is 1000.
PageSize *int `json:"PageSize,omitempty"`
// Max number of records to return.
Limit *int `json:"limit,omitempty"`
}
func (params *ListSettingsUpdateParams) SetSim(Sim string) *ListSettingsUpdateParams {
params.Sim = &Sim
return params
}
func (params *ListSettingsUpdateParams) SetStatus(Status string) *ListSettingsUpdateParams {
params.Status = &Status
return params
}
func (params *ListSettingsUpdateParams) SetPageSize(PageSize int) *ListSettingsUpdateParams {
params.PageSize = &PageSize
return params
}
func (params *ListSettingsUpdateParams) SetLimit(Limit int) *ListSettingsUpdateParams {
params.Limit = &Limit
return params
}
// Retrieve a single page of SettingsUpdate records from the API. Request is executed immediately.
func (c *ApiService) PageSettingsUpdate(params *ListSettingsUpdateParams, pageToken, pageNumber string) (*ListSettingsUpdateResponse, error) {
path := "/v1/SettingsUpdates"
data := url.Values{}
headers := make(map[string]interface{})
if params != nil && params.Sim != nil {
data.Set("Sim", *params.Sim)
}
if params != nil && params.Status != nil {
data.Set("Status", *params.Status)
}
if params != nil && params.PageSize != nil {
data.Set("PageSize", fmt.Sprint(*params.PageSize))
}
if pageToken != "" {
data.Set("PageToken", pageToken)
}
if pageNumber != "" {
data.Set("Page", pageNumber)
}
resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &ListSettingsUpdateResponse{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, err
}
// Lists SettingsUpdate records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
func (c *ApiService) ListSettingsUpdate(params *ListSettingsUpdateParams) ([]SupersimV1SettingsUpdate, error) {
response, errors := c.StreamSettingsUpdate(params)
records := make([]SupersimV1SettingsUpdate, 0)
for record := range response {
records = append(records, record)
}
if err := <-errors; err != nil {
return nil, err
}
return records, nil
}
// Streams SettingsUpdate records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
func (c *ApiService) StreamSettingsUpdate(params *ListSettingsUpdateParams) (chan SupersimV1SettingsUpdate, chan error) {
if params == nil {
params = &ListSettingsUpdateParams{}
}
params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
recordChannel := make(chan SupersimV1SettingsUpdate, 1)
errorChannel := make(chan error, 1)
response, err := c.PageSettingsUpdate(params, "", "")
if err != nil {
errorChannel <- err
close(recordChannel)
close(errorChannel)
} else {
go c.streamSettingsUpdate(response, params, recordChannel, errorChannel)
}
return recordChannel, errorChannel
}
func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, params *ListSettingsUpdateParams, recordChannel chan SupersimV1SettingsUpdate, errorChannel chan error) {
curRecord := 1
for response != nil {
responseRecords := response.SettingsUpdates
for item := range responseRecords {
recordChannel <- responseRecords[item]
curRecord += 1
if params.Limit != nil && *params.Limit < curRecord {
close(recordChannel)
close(errorChannel)
return
}
}
record, err := client.GetNext(c.baseURL, response, c.getNextListSettingsUpdateResponse)
if err != nil {
errorChannel <- err
break
} else if record == nil {
break
}
response = record.(*ListSettingsUpdateResponse)
}
close(recordChannel)
close(errorChannel)
}
func (c *ApiService) getNextListSettingsUpdateResponse(nextPageUrl string) (interface{}, error) {
if nextPageUrl == "" {
return nil, nil
}
resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &ListSettingsUpdateResponse{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, nil
}