-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquota.go
100 lines (79 loc) · 2 KB
/
quota.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
package chatnio
import (
"fmt"
"github.com/Deeptrain-Community/chatnio-api-go/utils"
)
type Quota struct {
Status bool `json:"status"`
Quota float32 `json:"quota"`
}
type QuotaBuy struct {
Status bool `json:"status"`
Error string `json:"error"`
}
type Package struct {
Status bool `json:"status"`
Data struct {
Cert bool `json:"cert"`
Teenager bool `json:"teenager"`
} `json:"data"`
}
type Subscription struct {
Status bool `json:"status"`
IsSubscribed bool `json:"is_subscribed"`
Expired int64 `json:"expired"`
}
type Subscribe struct {
Status bool `json:"status"`
Error string `json:"error"`
}
func (i *Instance) GetQuota() (float32, error) {
quota, err := utils.GetForm[Quota](i.Mix("/quota"), i.GetHeaders())
if err != nil {
return 0., err
} else if !quota.Status {
return 0., fmt.Errorf("quota query status is false")
}
return quota.Quota, nil
}
func (i *Instance) BuyQuota(quota int) error {
data, err := utils.PostForm[QuotaBuy](i.Mix("/buy"), i.GetHeaders(), map[string]interface{}{
"quota": quota,
})
if err != nil {
return err
} else if !data.Status {
return fmt.Errorf(data.Error)
}
return nil
}
func (i *Instance) GetPackage() (*Package, error) {
data, err := utils.GetForm[Package](i.Mix("/package"), i.GetHeaders())
if err != nil {
return nil, err
} else if !data.Status {
return nil, fmt.Errorf("package status is false")
}
return data, nil
}
func (i *Instance) GetSubscription() (*Subscription, error) {
data, err := utils.GetForm[Subscription](i.Mix("/subscription"), i.GetHeaders())
if err != nil {
return nil, err
} else if !data.Status {
return nil, fmt.Errorf("subscription status is false")
}
return data, nil
}
func (i *Instance) Subscribe(level int, month int) error {
data, err := utils.PostForm[Subscribe](i.Mix("/subscribe"), i.GetHeaders(), map[string]interface{}{
"level": level,
"month": month,
})
if err != nil {
return err
} else if !data.Status {
return fmt.Errorf(data.Error)
}
return nil
}