forked from kevinburke/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuper_sim.go
235 lines (207 loc) · 8.02 KB
/
super_sim.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package twilio
import (
"context"
"net/url"
)
const superSimPathPart = "Sims"
const fleetPathPart = "Fleets"
const usageRecordPathPart = "UsageRecords"
type SuperSimService struct {
client *Client
}
type SuperSim struct {
Sid string `json:"sid"`
Status string `json:"status"`
DateCreated TwilioTime `json:"date_created"`
DateUpdated TwilioTime `json:"date_updated"`
AccountSid string `json:"account_sid"`
UniqueName string `json:"unique_name"`
Iccid string `json:"iccid"`
FleetSid string `json:"fleet_sid"`
Url string `json:"url"`
}
// SuperSimPage represents a page of SuperSims.
type SuperSimPage struct {
Meta Meta `json:"meta"`
SuperSims []*SuperSim `json:"sims"`
}
type superSimPageIterator struct {
p *PageIterator
}
// Register registers a new SIM with the provided account.
//
// See https://www.twilio.com/docs/iot/supersim/api/sim-resource#add-a-super-sim-to-your-account
func (s *SuperSimService) Register(ctx context.Context, iccid, registrationCode string) (*SuperSim, error) {
superSim := new(SuperSim)
data := url.Values{}
data.Set("Iccid", iccid)
data.Set("RegistrationCode", registrationCode)
err := s.client.CreateResource(ctx, superSimPathPart, data, superSim)
return superSim, err
}
// Get finds a single SuperSim resource by its sid or unique name, or returns an error.
func (s *SuperSimService) Get(ctx context.Context, sidOrUniqueName string) (*SuperSim, error) {
superSim := new(SuperSim)
err := s.client.GetResource(ctx, superSimPathPart, sidOrUniqueName, superSim)
return superSim, err
}
// Activate sets the status of the SIM provided to "active".
//
// See https://www.twilio.com/docs/iot/supersim/api/sim-resource#update-a-sim-resource
func (s *SuperSimService) Activate(ctx context.Context, sid string) (*SuperSim, error) {
superSim := new(SuperSim)
data := url.Values{}
data.Set("Status", "active")
err := s.client.UpdateResource(ctx, superSimPathPart, sid, data, superSim)
return superSim, err
}
// Update updates the specified SuperSim resource with the data provided, or returns an error.
func (s *SuperSimService) Update(ctx context.Context, sid string, data url.Values) (*SuperSim, error) {
superSim := new(SuperSim)
err := s.client.UpdateResource(ctx, superSimPathPart, sid, data, superSim)
return superSim, err
}
// GetPage returns a single Page of SuperSims, filtered by data.
//
// See https://www.twilio.com/docs/iot/supersim/api/sim-resource#read-multiple-sim-resources.
func (s *SuperSimService) GetPage(ctx context.Context, data url.Values) (*SuperSimPage, error) {
return s.GetPageIterator(data).Next(ctx)
}
// GetPageIterator returns a superSimPageIterator with the given page
// filters. Call iterator.Next() to get the first page of resources (and again
// to retrieve subsequent pages).
func (s *SuperSimService) GetPageIterator(data url.Values) *superSimPageIterator {
iter := NewPageIterator(s.client, data, superSimPathPart)
return &superSimPageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (s *superSimPageIterator) Next(ctx context.Context) (*SuperSimPage, error) {
ap := new(SuperSimPage)
err := s.p.Next(ctx, ap)
if err != nil {
return nil, err
}
s.p.SetNextPageURI(ap.Meta.NextPageURL)
return ap, nil
}
type Fleet struct {
Sid string `json:"sid"`
Url string `json:"url"`
AccountSid string `json:"account_sid"`
UniqueName string `json:"unique_name""`
DataEnabled bool `json:"data_enabled"`
DataLimit int64 `json:"data_limit"`
DataMetering string `json:"data_metering"`
DateCreated TwilioTime `json:"date_created"`
DateUpdated TwilioTime `json:"date_updated"`
CommandsEnabled bool `json:"commands_enabled"`
CommandsUrl string `json:"commands_url"`
CommandsMethod string `json:"commands_method"`
SmsCommandsEnabled bool `json:"sms_commands_enabled"`
SmsCommandsMethod string `json:"sms_commands_method"`
IPCommandsMethod string `json:"ip_commands_method"`
IPCommandsUrl string `json:"ip_commands_url"`
NetworkAccessProfileSid string `json:"network_access_profile_sid"`
}
// FleetPage represents a page of Fleets.
type FleetPage struct {
Meta Meta `json:"meta"`
Fleets []*Fleet `json:"fleets"`
}
type fleetPageIterator struct {
p *PageIterator
}
// Create creates a new SuperSim Fleet with the data provided, or returns an error.
func (s *SuperSimService) CreateFleet(ctx context.Context, data url.Values) (*Fleet, error) {
fleet := new(Fleet)
err := s.client.CreateResource(ctx, fleetPathPart, data, fleet)
return fleet, err
}
// Get finds a single SuperSim Fleet by its sid, or returns an error.
func (s *SuperSimService) GetFleet(ctx context.Context, sid string) (*Fleet, error) {
fleet := new(Fleet)
err := s.client.GetResource(ctx, fleetPathPart, sid, fleet)
return fleet, err
}
// GetPage returns a single Page of fleets, filtered by data.
//
// See https://www.twilio.com/docs/iot/supersim/api/fleet-resource#read-multiple-fleet-resources.
func (s *SuperSimService) GetFleetPage(ctx context.Context, data url.Values) (*FleetPage, error) {
return s.GetFleetPageIterator(data).Next(ctx)
}
// GetFleetPageIterator returns a fleetPageIterator with the given page
// filters. Call iterator.Next() to get the first page of resources (and again
// to retrieve subsequent pages).
func (s *SuperSimService) GetFleetPageIterator(data url.Values) *fleetPageIterator {
iter := NewPageIterator(s.client, data, fleetPathPart)
return &fleetPageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (s *fleetPageIterator) Next(ctx context.Context) (*FleetPage, error) {
ap := new(FleetPage)
err := s.p.Next(ctx, ap)
if err != nil {
return nil, err
}
s.p.SetNextPageURI(ap.Meta.NextPageURL)
return ap, nil
}
type UsageRecord struct {
AccountSid string `json:"account_sid"`
SimSid string `json:"sim_sid"`
FleetSid string `json:"fleet_sid"`
NetworkSid string `json:"network_sid"`
// Total data uploaded in bytes, aggregated by the query parameters
DataUpload int64 `json:"data_upload"`
// Total data downloaded in bytes, aggregated by the query parameters
DataDownload int64 `json:"data_download"`
// Total of data_upload and data_download (in bytes).
DataTotal int64 `json:"data_total"`
// Alpha-2 ISO Country Code
IsoCountry string `json:"iso_country"`
Period SuperSimUsagePeriod `json:"period"`
}
type SuperSimUsagePeriod struct {
Start TwilioTime `json:"start_time"`
End TwilioTime `json:"end_time"`
}
// UsageRecordPage represents a page of UsageRecords.
type UsageRecordPage struct {
Meta Meta `json:"meta"`
UsageRecords []*UsageRecord `json:"usage_records"`
}
type UsageRecordPageIterator struct {
p *PageIterator
}
// GetPage returns a single Page of UsageRecords, filtered by data.
//
// See https://www.twilio.com/docs/iot/supersim/api/usage-record-resource#read-usagerecord-resources.
func (s *SuperSimService) GetUsageRecordPage(ctx context.Context, data url.Values) (*UsageRecordPage, error) {
return s.GetUsageRecordPageIterator(data).Next(ctx)
}
// GetPageIterator returns a UsageRecordPageIterator with the given page
// filters. Call iterator.Next() to get the first page of resources (and again
// to retrieve subsequent pages).
func (s *SuperSimService) GetUsageRecordPageIterator(data url.Values) *UsageRecordPageIterator {
iter := NewPageIterator(s.client, data, usageRecordPathPart)
return &UsageRecordPageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (s *UsageRecordPageIterator) Next(ctx context.Context) (*UsageRecordPage, error) {
ap := new(UsageRecordPage)
err := s.p.Next(ctx, ap)
if err != nil {
return nil, err
}
s.p.SetNextPageURI(ap.Meta.NextPageURL)
return ap, nil
}