-
Notifications
You must be signed in to change notification settings - Fork 32
/
org_invite.go
61 lines (50 loc) · 1.61 KB
/
org_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
54
55
56
57
58
59
60
61
package registry
import (
"context"
"errors"
"log"
"github.com/arigatomachine/cli/envelope"
"github.com/arigatomachine/cli/identity"
)
// OrgInviteClient represents the `/org-invites` registry endpoint, used for
// sending, accepting, and approving invitations to organizations in Torus.
type OrgInviteClient struct {
client *Client
}
// Approve sends an approval notification to the registry regarding a specific
// invitation.
func (o *OrgInviteClient) Approve(ctx context.Context, inviteID *identity.ID) (*envelope.Unsigned, error) {
path := "/org-invites/" + inviteID.String() + "/approve"
req, err := o.client.NewRequest("POST", path, nil, nil)
if err != nil {
log.Printf(
"Error building POST /org-invites/:id/approve api request: %s", err)
return nil, err
}
invite := envelope.Unsigned{}
_, err = o.client.Do(ctx, req, &invite)
if err != nil {
log.Printf("Error performing POST /org-invites/:id/accept: %s", err)
return nil, err
}
return &invite, nil
}
// Get returns a specific Org Invite based on it's ID
func (o *OrgInviteClient) Get(ctx context.Context, inviteID *identity.ID) (*envelope.Unsigned, error) {
if inviteID == nil {
return nil, errors.New("an inviteID must be provided")
}
path := "/org-invites/" + inviteID.String()
req, err := o.client.NewRequest("GET", path, nil, nil)
if err != nil {
log.Printf("Error building GET /org-invites/:id request: %s", err)
return nil, err
}
invite := envelope.Unsigned{}
_, err = o.client.Do(ctx, req, &invite)
if err != nil {
log.Printf("Error performing GET /org-invites/:id request: %s", err)
return nil, err
}
return &invite, nil
}