forked from soracom/soracom-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk.go
1193 lines (1013 loc) · 33 KB
/
sdk.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package: SORACOM SDK for Go.
package soracom
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httputil"
"net/url"
"strconv"
"strings"
"time"
)
// Tag is a pair of Name and Value.
type Tag struct {
TagName string `json:"tagName"`
TagValue string `json:"tagValue"`
}
// Tags is a map of tag name and tag value
type Tags map[string]string
// Properties is a map of property name and propaty value
type Properties map[string]string
// TimestampMilli is ...
type TimestampMilli struct {
time.Time
}
// MarshalJSON is ...
func (t *TimestampMilli) MarshalJSON() ([]byte, error) {
ts := t.Time.UnixNano() / (1000 * 1000)
stamp := fmt.Sprint(ts)
return []byte(stamp), nil
}
// UnmarshalJSON is ...
func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
ts, err := strconv.Atoi(string(b))
if err != nil {
return err
}
ms := int64(ts)
s := ms / 1000
ns := (ms % 1000) * 1000 * 1000
t.Time = time.Unix(s, ns)
return nil
}
// UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC.
func (t *TimestampMilli) UnixMilli() int64 {
ns := t.Time.UnixNano()
return ns / (1000 * 1000)
}
// AuthRequest contains parameters for /auth API
type AuthRequest struct {
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
AuthKeyID string `json:"authKeyId,omitempty"`
AuthKey string `json:"authKey,omitempty"`
TokenTimeoutSeconds int `json:"tokenTimeoutSeconds"`
}
// JSON returns JSON representing AuthRequest
func (ar *AuthRequest) JSON() string {
return toJSON(ar)
}
// AuthKey contains AuthKeyID and AuthKeySecret
type AuthKey struct {
AuthKeyID string `json:"authKeyId"`
AuthKeySecret string `json:"authKey"`
}
// JSON returns JSON representing AuthKey
func (ak *AuthKey) JSON() string {
return toJSON(ak)
}
// AuthResponse contains all values returned from /auth API
type AuthResponse struct {
APIKey string `json:"apiKey"`
OperatorID string `json:"operatorId"`
Token string `json:"token"`
}
func parseAuthResponse(resp *http.Response) *AuthResponse {
var ar AuthResponse
dec := json.NewDecoder(resp.Body)
dec.Decode(&ar)
return &ar
}
type generateAPITokenRequest struct {
Timeout int `json:"timeout_seconds"`
}
// JSON retunrs a JSON representing updateSpeedClassRequest object
func (r *generateAPITokenRequest) JSON() string {
return toJSON(r)
}
// GenerateAPITokenResponse contains all values returned from /operators/{operator_id}/token API
type GenerateAPITokenResponse struct {
Token string `json:"token"`
}
func parseGenerateAPITokenResponse(resp *http.Response) *GenerateAPITokenResponse {
var r GenerateAPITokenResponse
dec := json.NewDecoder(resp.Body)
dec.Decode(&r)
return &r
}
type updatePasswordRequest struct {
CurrentPassword string `json:"currentPassword"`
NewPassword string `json:"newPassword"`
}
func (r *updatePasswordRequest) JSON() string {
return toJSON(r)
}
// GetSupportTokenResponse contains all values returned from /operators/{operator_id}/support/token API.
type GetSupportTokenResponse struct {
Token string `json:"token"`
}
func parseGetSupportTokenResponse(resp *http.Response) *GetSupportTokenResponse {
var r GetSupportTokenResponse
dec := json.NewDecoder(resp.Body)
dec.Decode(&r)
return &r
}
// CreateOperatorRequest defines the email, password, and coverage type(s) of the operator to be created
type CreateOperatorRequest struct {
Email string `json:"email"`
Password string `json:"password"`
CoverageTypes []string `json:"coverageTypes,omitempty"`
}
// JSON encodes a CreateOperatorRequest object
func (r *CreateOperatorRequest) JSON() string {
return toJSON(r)
}
type verifyOperatorRequest struct {
Token string `json:"token"`
}
func (r *verifyOperatorRequest) JSON() string {
return toJSON(r)
}
// Operator keeps information about an operator
type Operator struct {
OperatorID string `json:"operatorId"`
RootOperatorID *string `json:"rootOperatorId"`
Email string `json:"email"`
Description *string `json:"description"`
CreateDate *time.Time `json:"createDate"`
UpdateDate *time.Time `json:"updateDate"`
}
func parseOperator(resp *http.Response) *Operator {
var o Operator
dec := json.NewDecoder(resp.Body)
dec.Decode(&o)
return &o
}
// TagValueMatchMode is one of MatchModeUnspecified, MatchModeExact or MatchModePrefix
type TagValueMatchMode int
const (
// MatchModeUnspecified is a value of TagValueMatchMode.
// For list functions, they don't match tag values (i.e. list all items regardless of values of tags) if this value is specified.
MatchModeUnspecified TagValueMatchMode = iota
// MatchModeExact is a value of TagValueMatchMode.
// For list functions, they do exact match for tag values if this value is specified.
MatchModeExact
// MatchModePrefix is a value of TagValueMatchMode.
// For list functions, they do prefix match for tag values if this value is specified.
MatchModePrefix
)
func (m TagValueMatchMode) String() string {
switch m {
case MatchModeExact:
return "exact"
case MatchModePrefix:
return "prefix"
}
return ""
}
// Parse parses a provided string and returns TagValueMatchMode
func (m TagValueMatchMode) Parse(s string) TagValueMatchMode {
switch s {
case "exact":
return MatchModeExact
case "prefix":
return MatchModePrefix
default:
return MatchModeUnspecified
}
}
// ListSubscribersOptions holds options for APIClient.ListSubscribers()
type ListSubscribersOptions struct {
TagName string
TagValue string
TagValueMatchMode TagValueMatchMode
StatusFilter string
TypeFilter string
Limit int
LastEvaluatedKey string
}
func (lso *ListSubscribersOptions) String() string {
var s = make([]string, 0, 10)
if lso.TagName != "" {
s = append(s, "tag_name="+lso.TagName)
}
if lso.TagValue != "" {
s = append(s, "tag_value="+lso.TagValue)
}
if lso.TagValueMatchMode != MatchModeUnspecified {
s = append(s, "tag_value_match_mode="+lso.TagValueMatchMode.String())
}
if lso.StatusFilter != "" {
s = append(s, "status_filter="+lso.StatusFilter)
}
if lso.TypeFilter != "" {
s = append(s, "type_filter="+lso.TypeFilter)
}
if lso.Limit != 0 {
s = append(s, "limit="+strconv.Itoa(lso.Limit))
}
if lso.LastEvaluatedKey != "" {
s = append(s, "last_evaluated_key="+lso.LastEvaluatedKey)
}
return strings.Join(s, "&")
}
// RegisterSubscriberOptions keeps information for registering a subscriber
type RegisterSubscriberOptions struct {
RegistrationSecret string `json:"registrationSecret"`
GroupID string `json:"groupId"`
Tags Tags `json:"tags"`
}
// JSON retunrs a JSON representing RegisterSubscriberOptions object
func (rso *RegisterSubscriberOptions) JSON() string {
if rso.Tags == nil {
rso.Tags = Tags{}
}
return toJSON(rso)
}
type IMEILock struct {
IMEI string `json:"imei"`
}
// Cell keeps information about a cell
type Cell struct {
RadioType string `json:"radioType"`
MCC int `json:"mcc"` // Mobile Country Code
MNC int `json:"mnc"` // Mobile Network Code
TAC int `json:"tac"` // Tracking Area Code
ECI int `json:"eci"` // E-UTRAN Cell Identifier
}
// SessionStatus keeps information about a session
type SessionStatus struct {
DNSServers []string `json:"dnsServers"`
IMEI string `json:"imei"`
LastUpdatedAt *TimestampMilli `json:"lastUpdatedAt"`
Location *string `json:"location"`
Cell *Cell `json:"cell"`
Online bool `json:"online"`
UEIPAddress string `json:"ueIpAddress"`
}
// SessionEvent contains a session connect/disconnect event
type SessionEvent struct {
APN string `json:"apn"`
DNS0 string `json:"dns0"`
DNS1 string `json:"dns1"`
Event string `json:"event"`
GatewayPrivateIPAddress string `json:"gatewayPrivateIpAddress"`
GatewayPublicIPAddress string `json:"gatewayPublicIpAddress"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
OperatorID string `json:"operatorId"`
Time int64 `json:"time"`
UEIPAddress string `json:"ueIpAddress"`
VPGID string `json:"vpgId"`
}
// Subscriber keeps information about a subscriber
type Subscriber struct {
APN string `json:"apn"`
CreatedAt *TimestampMilli `json:"createdAt"`
ExpiredAt *TimestampMilli `json:"expiredAt"`
ExpiryAction *string `json:"expiryAction,omitempty"`
GroupID *string `json:"groupId,omitempty"`
ICCID string `json:"iccid,omitempty"`
IMEILock *IMEILock `json:"imeiLock,omitempty"`
IMSI string `json:"imsi"`
IPAddress *string `json:"ipAddress,omitempty"`
LastModifiedAt *TimestampMilli `json:"lastModifiedAt"`
ModuleType string `json:"ModuleType"`
MSISDN string `json:"msisdn"`
OperatorID string `json:"operatorId"`
Plan int `json:"plan"`
SerialNumber string `json:"serialNumber"`
SessionStatus *SessionStatus `json:"sessionStatus"`
SpeedClass string `json:"speedClass"`
Status string `json:"status"`
Tags Tags `json:"tags"`
TerminationEnabled bool `json:"terminationEnabled"`
}
// PaginationKeys holds keys for pagination
type PaginationKeys struct {
Prev string
Next string
}
func parseLinkHeader(linkHeader string) *PaginationKeys {
var pk *PaginationKeys
if linkHeader != "" {
pk = &PaginationKeys{}
links := strings.Split(linkHeader, ",")
for _, link := range links {
s := strings.Split(link, ";")
url, err := url.Parse(strings.Trim(s[0], "<>"))
if err != nil {
continue
}
lek := url.Query()["last_evaluated_key"][0]
rel := strings.Split(s[1], "=")[1]
if rel == "prev" {
pk.Prev = lek
} else if rel == "next" {
pk.Next = lek
}
}
}
return pk
}
func parseListSubscribersResponse(resp *http.Response) ([]Subscriber, *PaginationKeys, error) {
subs := make([]Subscriber, 0, 10)
dec := json.NewDecoder(resp.Body)
// read open bracket
_, err := dec.Token()
if err != nil {
return nil, nil, err
}
for dec.More() {
var s Subscriber
err = dec.Decode(&s)
if err != nil {
continue
}
subs = append(subs, s)
}
// read close bracket
_, err = dec.Token()
if err != nil {
return nil, nil, err
}
linkHeader := resp.Header.Get(http.CanonicalHeaderKey("Link"))
pk := parseLinkHeader(linkHeader)
return subs, pk, nil
}
func parseSubscriber(resp *http.Response) *Subscriber {
var sub Subscriber
dec := json.NewDecoder(resp.Body)
dec.Decode(&sub)
return &sub
}
type updateSpeedClassRequest struct {
SpeedClass string `json:"speedClass"`
}
// JSON retunrs a JSON representing updateSpeedClassRequest object
func (r *updateSpeedClassRequest) JSON() string {
bodyBytes, err := json.Marshal(r)
if err != nil {
return ""
}
return string(bodyBytes)
}
type setExpiredAtRequest struct {
ExpiredAt string `json:"expiryTime"`
}
// JSON retunrs a JSON representing setExpiredAtRequest object
func (r *setExpiredAtRequest) JSON() string {
bodyBytes, err := json.Marshal(r)
if err != nil {
return ""
}
return string(bodyBytes)
}
type setSubscriberGroupRequest struct {
GroupID string `json:"groupId"`
}
// JSON retunrs a JSON representing setSubscriberGroupRequest object
func (r *setSubscriberGroupRequest) JSON() string {
bodyBytes, err := json.Marshal(r)
if err != nil {
return ""
}
return string(bodyBytes)
}
// StatsPeriod is a period to gather stats
type StatsPeriod int
const (
// StatsPeriodUnspecified means no StatsPeriod is specified
StatsPeriodUnspecified StatsPeriod = iota
// StatsPeriodMonth means the period of gathering stats is 'month'
StatsPeriodMonth
// StatsPeriodDay means that the period of gathering stats is 'day'
StatsPeriodDay
// StatsPeriodMinutes means that the period of gathering stats is 'minutes'
StatsPeriodMinutes
)
func (p StatsPeriod) String() string {
switch p {
case StatsPeriodMonth:
return "month"
case StatsPeriodDay:
return "day"
case StatsPeriodMinutes:
return "minutes"
}
return ""
}
// Parse parses the specified string and returns a StatsPeriod value represented by the string
func (p StatsPeriod) Parse(s string) StatsPeriod {
switch s {
case "month":
return StatsPeriodMonth
case "day":
return StatsPeriodDay
case "minutes":
return StatsPeriodMinutes
default:
return StatsPeriodUnspecified
}
}
// SpeedClass represents one of speed classes
type SpeedClass string
const (
// SpeedClassS1Minimum is s1.minimum
SpeedClassS1Minimum SpeedClass = "s1.minimum"
// SpeedClassS1Slow is s1.slow
SpeedClassS1Slow SpeedClass = "s1.slow"
// SpeedClassS1Standard is s1.standard
SpeedClassS1Standard SpeedClass = "s1.standard"
// SpeedClassS1Fast is s1.fast
SpeedClassS1Fast SpeedClass = "s1.fast"
)
// AirStatsForSpeedClass holds Upload/Download Bytes/Packets for a speed class
type AirStatsForSpeedClass struct {
UploadBytes uint64 `json:"uploadByteSizeTotal"`
UploadPackets uint64 `json:"uploadPacketSizeTotal"`
DownloadBytes uint64 `json:"downloadByteSizeTotal"`
DownloadPackets uint64 `json:"downloadPacketSizeTotal"`
}
// AirStats holds a set of traffic information for each speed class
type AirStats struct {
Date string `json:"date"`
Unixtime uint64 `json:"unixtime"`
Traffic map[SpeedClass]AirStatsForSpeedClass `json:"dataTrafficStatsMap"`
}
func parseAirStats(resp *http.Response) []AirStats {
var v []AirStats
dec := json.NewDecoder(resp.Body)
dec.Decode(&v)
return v
}
// JSON retunrs a JSON representing AirStats object
func (o *AirStats) JSON() string {
return toJSON(o)
}
// BeamType represents one of in/out protocols for Beam
type BeamType string
const (
// BeamTypeInHTTP is ...
BeamTypeInHTTP = "inHttp"
// BeamTypeInMQTT is ...
BeamTypeInMQTT = "inMqtt"
// BeamTypeInTCP is ...
BeamTypeInTCP = "inTcp"
// BeamTypeInUDP is ...
BeamTypeInUDP = "inUdp"
// BeamTypeOutHTTP is ...
BeamTypeOutHTTP = "outHttp"
// BeamTypeOutHTTPS is ...
BeamTypeOutHTTPS = "outHttps"
// BeamTypeOutMQTT is ...
BeamTypeOutMQTT = "outMqtt"
// BeamTypeOutMQTTS is ...
BeamTypeOutMQTTS = "outMqtts"
// BeamTypeOutTCP is ...
BeamTypeOutTCP = "outTcp"
// BeamTypeOutTCPS is ...
BeamTypeOutTCPS = "outTcps"
// BeamTypeOutUDP is ...
BeamTypeOutUDP = "outUdp"
)
// BeamStatsForType holds Upload/Download Bytes/Packets for a speed class
type BeamStatsForType struct {
Count uint64 `json:"count"`
}
// BeamStats holds a set of traffic information for each speed class
type BeamStats struct {
Date string `json:"date"`
Unixtime uint64 `json:"unixtime"`
Traffic map[BeamType]BeamStatsForType `json:"beamStatsMap"`
}
func parseBeamStats(resp *http.Response) []BeamStats {
var v []BeamStats
dec := json.NewDecoder(resp.Body)
dec.Decode(&v)
return v
}
// JSON retunrs a JSON representing BeamStats object
func (o *BeamStats) JSON() string {
return toJSON(o)
}
type exportAirStatsRequest struct {
From int64 `json:"from"`
To int64 `json:"to"`
Period string `json:"period"`
}
func (r *exportAirStatsRequest) JSON() string {
return toJSON(r)
}
type exportAirStatsResponse struct {
URL string `json:"url"`
}
func parseExportAirStatsResponse(resp *http.Response) *exportAirStatsResponse {
var r exportAirStatsResponse
dec := json.NewDecoder(resp.Body)
dec.Decode(&r)
return &r
}
type exportBeamStatsRequest struct {
From int64 `json:"from"`
To int64 `json:"to"`
Period string `json:"period"`
}
func (r *exportBeamStatsRequest) JSON() string {
return toJSON(r)
}
type exportBeamStatsResponse struct {
URL string `json:"url"`
}
func parseExportBeamStatsResponse(resp *http.Response) *exportBeamStatsResponse {
var r exportBeamStatsResponse
dec := json.NewDecoder(resp.Body)
dec.Decode(&r)
return &r
}
// ConfigNamespace is a type of namespace of a configuration
type ConfigNamespace string
// Group keeps information about a group
type Group struct {
Configuration map[ConfigNamespace]interface{} `json:"configuration"`
CreatedTime *TimestampMilli `json:"createdTime"`
GroupID string `json:"groupId"`
LastModifiedTime *TimestampMilli `json:"lastModifiedTime"`
OperatorID string `json:"operatorId"`
Tags Tags `json:"tags"`
}
// ListGroupsOptions holds options for APIClient.ListGroups()
type ListGroupsOptions struct {
TagName string
TagValue string
TagValueMatchMode TagValueMatchMode
Limit int
LastEvaluatedKey string
}
func (lso *ListGroupsOptions) String() string {
var s = make([]string, 0, 10)
if lso.TagName != "" {
s = append(s, "tag_name="+lso.TagName)
}
if lso.TagValue != "" {
s = append(s, "tag_value="+lso.TagValue)
}
if lso.TagValueMatchMode != MatchModeUnspecified {
s = append(s, "tag_value_match_mode="+lso.TagValueMatchMode.String())
}
if lso.Limit != 0 {
s = append(s, "limit="+strconv.Itoa(lso.Limit))
}
if lso.LastEvaluatedKey != "" {
s = append(s, "last_evaluated_key="+lso.LastEvaluatedKey)
}
return strings.Join(s, "&")
}
func parseListGroupsResponse(resp *http.Response) ([]Group, *PaginationKeys, error) {
groups := make([]Group, 0, 10)
dec := json.NewDecoder(resp.Body)
// read open bracket
_, err := dec.Token()
if err != nil {
return nil, nil, err
}
for dec.More() {
var g Group
err = dec.Decode(&g)
if err != nil {
continue
}
groups = append(groups, g)
}
// read close bracket
_, err = dec.Token()
if err != nil {
return nil, nil, err
}
linkHeader := resp.Header.Get(http.CanonicalHeaderKey("Link"))
pk := parseLinkHeader(linkHeader)
return groups, pk, nil
}
type createGroupRequest struct {
Tags Tags `json:"tags"`
}
func (r *createGroupRequest) JSON() string {
return toJSON(r)
}
func parseGroup(resp *http.Response) *Group {
var g Group
dec := json.NewDecoder(resp.Body)
dec.Decode(&g)
return &g
}
// ListSubscribersInGroupOptions holds options for APIClient.ListSubscribersInGroup()
type ListSubscribersInGroupOptions struct {
Limit int
LastEvaluatedKey string
}
func (lso *ListSubscribersInGroupOptions) String() string {
var s = make([]string, 0, 10)
if lso.Limit != 0 {
s = append(s, "limit="+strconv.Itoa(lso.Limit))
}
if lso.LastEvaluatedKey != "" {
s = append(s, "last_evaluated_key="+lso.LastEvaluatedKey)
}
return strings.Join(s, "&")
}
// GroupConfig holds a pair of a key and a value
type GroupConfig struct {
Key string `json:"key"`
Value interface{} `json:"value"`
}
// MetaData holds configuration for SORACOM Air Metadata
type MetaData struct {
Enabled bool `json:"enabled"`
ReadOnly bool `json:"readonly"`
AllowOrigin string `json:"allowOrigin"`
}
// AirConfig holds configuration parameters for SORACOM Air
type AirConfig struct {
UseCustomDNS bool `json:"useCustomDns"`
DNSServers []string `json:"dnsServers"`
MetaData MetaData `json:"metadata"`
UserData string `json:"userdata"`
}
// JSON converts AirConfig into JSON string
func (ac *AirConfig) JSON() string {
return toJSON([]GroupConfig{
GroupConfig{Key: "useCustomDns", Value: ac.UseCustomDNS},
GroupConfig{Key: "dnsServers", Value: ac.DNSServers},
})
}
// CustomHeader holds Action, Key and Value for a custom header
type CustomHeader struct {
Action string `json:"action"`
Key string `json:"headerKey"`
Value string `json:"headerValue"`
}
// BeamTCPConfig holds SORACOM Beam TCP entry point configurations
type BeamTCPConfig struct {
Name string `json:"name"`
Destination string `json:"destination"`
Enabled bool `json:"enabled"`
AddSubscriberHeader bool `json:"addSubscriberHeader"`
AddSignature bool `json:"addSignature"`
PSK string `json:"psk"`
}
// BeamUDPConfig holds SORACOM Beam UDP entry point configurations
type BeamUDPConfig struct {
Name string `json:"name"`
Destination string `json:"destination"`
Enabled bool `json:"enabled"`
AddSubscriberHeader bool `json:"addSubscriberHeader"`
AddSignature bool `json:"addSignature"`
PSK string `json:"psk"`
}
// ClientCerts consists of a CA certificate,
type ClientCerts struct {
CA string `json:"ca"`
Cert string `json:"cert"`
PrivateKey string `json:"key"`
}
// BeamMQTTConfig holds SORACOM Beam MQTT entry point configurations
type BeamMQTTConfig struct {
Name string `json:"name"`
Destination string `json:"destination"`
Enabled bool `json:"enabled"`
AddSubscriberHeader bool `json:"addSubscriberHeader"`
Username string `json:"username"`
Password string `json:"password"`
UseClientCertificates string `json:"useClientCert"`
ClientCertificates map[string]ClientCerts `json:"clientCerts"`
}
// BeamHTTPConfig holds SORACOM Beam HTTP entry point configurations
type BeamHTTPConfig struct {
Name string `json:"name"`
Destination string `json:"destination"`
Enabled bool `json:"enabled"`
AddSubscriberHeader bool `json:"addSubscriberHeader"`
AddSignature bool `json:"addSignature"`
CustomHeaders map[string]CustomHeader `json:"customHeaders"`
PSK string `json:"psk"`
}
// FunnelDestinationConfig holds SORACOM Funnel Destination configurations
type FunnelDestinationConfig struct {
Provider string `json:"provider"`
Service string `json:"service"`
ResourceUrl string `json:"resourceUrl"`
}
// EventHandlerRuleType is a type of event hander's rule
type EventHandlerRuleType string
const (
// EventHandlerRuleTypeUnspecified means that the type field in RuleConfig has not been specified
EventHandlerRuleTypeUnspecified EventHandlerRuleType = ""
// EventHandlerRuleTypeDailyTraffic is a rule type to invoke actions when data traffic for a day for a subscriber exceeds the specified limit
EventHandlerRuleTypeDailyTraffic EventHandlerRuleType = "DailyTrafficRule"
// EventHandlerRuleTypeMonthlyTraffic is a rule type to invoke actions when data traffic for a month for a subscriber exceeds the specified limit
EventHandlerRuleTypeMonthlyTraffic EventHandlerRuleType = "MonthlyTrafficRule"
// EventHandlerRuleTypeCumulativeTraffic is a rule type to invoke actions when cumulative data traffic for a subscriber exceeds the specified limit
EventHandlerRuleTypeCumulativeTraffic EventHandlerRuleType = "CumulativeTrafficRule"
// EventHandlerRuleTypeDailyTotalTraffic is a rule type to invoke actions when total data traffic for a day for all subscribers exceeds the specified limit
EventHandlerRuleTypeDailyTotalTraffic EventHandlerRuleType = "DailyTotalTrafficRule"
// EventHandlerRuleTypeMonthlyTotalTraffic is a rule type to invoke actions when total data traffic for a month for all subscribers exceeds the specified limit
EventHandlerRuleTypeMonthlyTotalTraffic EventHandlerRuleType = "MonthlyTotalTrafficRule"
// EventHandlerRuleTypeSubscriberStatusAttribute is a rule type to invoke actions when status of a subscriber has been changed
EventHandlerRuleTypeSubscriberStatusAttribute EventHandlerRuleType = "SubscriberStatusAttributeRule"
// EventHandlerRuleTypeSubscriberSpeedClassAttribute is a rule type to invoke actions when speed class of a subscriber has been changed
EventHandlerRuleTypeSubscriberSpeedClassAttribute EventHandlerRuleType = "SubscriberSpeedClassAttributeRule"
// EventHandlerRuleTypeSubscriberExpired is a rule type to invoke actions when a subscriber has been expired
EventHandlerRuleTypeSubscriberExpired EventHandlerRuleType = "SubscriberExpiredRule"
)
// RuleConfig contains a condition to invoke actions
type RuleConfig struct {
Type EventHandlerRuleType `json:"type"`
Properties Properties `json:"properties"`
}
// EventHandlerActionType is a type of event hander's action
type EventHandlerActionType string
const (
// EventHandlerActionTypeUnspecified means that the type field in ActionConfigList has not been specified
EventHandlerActionTypeUnspecified EventHandlerActionType = ""
// EventHandlerActionTypeChangeSpeedClass indicates a type of action to be invoked to change speed class for a subscriber once a condition is satisfied
EventHandlerActionTypeChangeSpeedClass EventHandlerActionType = "ChangeSpeedClassAction"
// EventHandlerActionTypeSendMail indicates a type of action to be invoked to send an email once a condition is satisfied
EventHandlerActionTypeSendMail EventHandlerActionType = "SendMailAction"
// EventHandlerActionTypeInvokeAWSLambda indicates a type of action to be invoked to invoke AWS Lambda function once a condition is satisfied
EventHandlerActionTypeInvokeAWSLambda EventHandlerActionType = "InvokeAWSLambdaAction"
)
// ActionConfig contains an action to be invoked when a condition is satisfied
type ActionConfig struct {
Type EventHandlerActionType `json:"type"`
Properties Properties `json:"properties"`
}
// EventHandler keeps information about an event handler
type EventHandler struct {
HandlerID string `json:"handlerId"`
TargetImsi *string `json:"targetImsi"`
TargetOperatorID *string `json:"targetOperatorId"`
TargetTag *Tags `json:"targetTag"`
TargetGroupID *string `json:"targetGroupId"`
Name string `json:"name"`
Description string `json:"description"`
RuleConfig RuleConfig `json:"ruleConfig"`
Status string `json:"status"`
ActionConfigList []ActionConfig `json:"actionConfigList"`
}
// JSON converts Eventhandler into a JSON string
func (o *EventHandler) JSON() string {
return toJSON(o)
}
// ListEventHandlersOptions holds options for APIClient.ListEventHandlers()
type ListEventHandlersOptions struct {
Target string
}
func (leho *ListEventHandlersOptions) String() string {
var s = make([]string, 0, 10)
if leho.Target != "" {
s = append(s, "target="+leho.Target)
}
return strings.Join(s, "&")
}
func parseListEventHandlersResponse(resp *http.Response) ([]EventHandler, error) {
eventHandlers := make([]EventHandler, 0, 10)
dec := json.NewDecoder(resp.Body)
// read open bracket
_, err := dec.Token()
if err != nil {
return nil, err
}
for dec.More() {
var eh EventHandler
err = dec.Decode(&eh)
if err != nil {
continue
}
eventHandlers = append(eventHandlers, eh)
}
// read close bracket
_, err = dec.Token()
if err != nil {
return nil, err
}
return eventHandlers, nil
}
func parseEventHandler(resp *http.Response) (*EventHandler, error) {
dec := json.NewDecoder(resp.Body)
var eh EventHandler
err := dec.Decode(&eh)
if err != nil {
return nil, err
}
return &eh, nil
}
// CreateEventHandlerOptions keeps information to create an event handler
type CreateEventHandlerOptions struct {
TargetIMSI *string `json:"targetImsi"`
TargetOperatorID *string `json:"targetOperatorId"`
TargetTag *Tags `json:"targetTag"`
TargetGroupID *string `json:"targetGroupId"`
Name string `json:"name"`
Description string `json:"description"`
RuleConfig RuleConfig `json:"ruleConfig"`
Status string `json:"status"`
ActionConfigList []ActionConfig `json:"actionConfigList"`
}
// JSON converts CreateEventhandlerOptions into a JSON string
func (o *CreateEventHandlerOptions) JSON() string {
return toJSON(o)
}
// PaymentMethodInfoWebPay keeps information of an WebPay payment method
type PaymentMethodInfoWebPay struct {
Cvc string `json:"cvc"`
ExpireMonth int `json:"expireMonth"`
ExpireYear int `json:"expireYear"`
Name string `json:"name"`
Number string `json:"number"`
}
// JSON converts PaymentMethodInfoWebPay into a JSON string
func (o *PaymentMethodInfoWebPay) JSON() string {
return toJSON(o)
}
// PaymentMethodInfoPayJP holds payment method tokens
type PaymentMethodInfoPayJP struct {
PayJPToken string `json:"payJPToken"`
StripeToken string `json:"stripeToken"`
}
// JSON converts PaymentMethodInfoPayJP into a JSON string
func (o *PaymentMethodInfoPayJP) JSON() string {
return toJSON(o)
}
// SandboxGetSignupTokenResponse keeps information of a signup token
type SandboxGetSignupTokenResponse struct {
Token string `json:"token"`
}