-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinvite.go
53 lines (43 loc) · 1 KB
/
invite.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
package rest
import (
"context"
"fmt"
"net/http"
"net/url"
"github.com/Postcord/objects"
"github.com/google/go-querystring/query"
)
type GetInviteParams struct {
WithCounts bool `url:"with_counts"`
}
func (c *Client) GetInvite(ctx context.Context, code string, params *GetInviteParams) (*objects.Invite, error) {
u, err := url.Parse(fmt.Sprintf(InviteFmt, code))
if err != nil {
return nil, err
}
v, err := query.Values(params)
if err != nil {
return nil, err
}
u.RawQuery = v.Encode()
invite := &objects.Invite{}
err = NewRequest().
Method(http.MethodGet).
WithContext(ctx).
Path(u.String()).
ContentType(JsonContentType).
Bind(invite).
Send(c)
return invite, err
}
func (c *Client) DeleteInvite(ctx context.Context, code, reason string) (*objects.Invite, error) {
invite := &objects.Invite{}
err := NewRequest().
Method(http.MethodDelete).
WithContext(ctx).
Path(fmt.Sprintf(InviteFmt, code)).
ContentType(JsonContentType).
Bind(invite).
Send(c)
return invite, err
}