-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbans.go
45 lines (35 loc) · 779 Bytes
/
bans.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
package tebexgo
import (
"encoding/json"
"fmt"
"log"
"github.com/itschip/tebexgo/internal"
)
func (s *Session) GetAllBans() (*Bans, error) {
res, err := internal.GetRequest(s.Secret, BansEndpoint)
if err != nil {
log.Println(err.Error())
return nil, err
}
var bans Bans
err = internal.UnmarshalResponse(res, &bans)
if err != nil {
return nil, err
}
return &bans, err
}
func (s *Session) CreateBan(input *BanInput) (*Bans, error) {
jsonBody, err := json.Marshal(&input)
if err != nil {
return nil, err
}
res, err := internal.PostRequest(s.Secret, BansEndpoint, jsonBody)
if err != nil {
log.Println("Failed to create ban")
return nil, err
}
fmt.Println(string(res))
var ban Bans
internal.UnmarshalResponse(res, &ban)
return &ban, nil
}