generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinvitations_api.go
50 lines (41 loc) · 905 Bytes
/
invitations_api.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
package invitations
import (
"context"
"fmt"
"net/url"
"github.com/go-resty/resty/v2"
)
const (
route = "api/v1/invitations"
api = "User Invitations API"
)
type API struct {
url *url.URL
httpClient *resty.Client
}
func (a *API) AcceptInvitation(ctx context.Context, paymail string) error {
_, err := a.httpClient.
R().
SetContext(ctx).
Post(a.url.JoinPath(paymail, "contacts").String())
if err != nil {
return fmt.Errorf("HTTP response failure: %w", err)
}
return nil
}
func (a *API) RejectInvitation(ctx context.Context, paymail string) error {
_, err := a.httpClient.
R().
SetContext(ctx).
Delete(a.url.JoinPath(paymail).String())
if err != nil {
return fmt.Errorf("HTTP response failure: %w", err)
}
return nil
}
func NewAPI(url *url.URL, httpClient *resty.Client) *API {
return &API{
url: url.JoinPath(route),
httpClient: httpClient,
}
}