-
Notifications
You must be signed in to change notification settings - Fork 8
/
collaborators.go
64 lines (52 loc) · 1.94 KB
/
collaborators.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
package scalingo
import (
"context"
"gopkg.in/errgo.v1"
)
type CollaboratorStatus string
const (
CollaboratorStatusPending CollaboratorStatus = "pending"
CollaboratorStatusAccepted CollaboratorStatus = "accepted"
CollaboratorStatusDeleted CollaboratorStatus = "user account deleted"
)
type CollaboratorsService interface {
CollaboratorsList(ctx context.Context, app string) ([]Collaborator, error)
CollaboratorAdd(ctx context.Context, app string, email string) (Collaborator, error)
CollaboratorRemove(ctx context.Context, app string, id string) error
}
var _ CollaboratorsService = (*Client)(nil)
type Collaborator struct {
ID string `json:"id"`
AppID string `json:"app_id"`
Username string `json:"username"`
Email string `json:"email"`
Status CollaboratorStatus `json:"status"`
UserID string `json:"user_id"`
}
type CollaboratorsRes struct {
Collaborators []Collaborator `json:"collaborators"`
}
type CollaboratorRes struct {
Collaborator Collaborator `json:"collaborator"`
}
func (c *Client) CollaboratorsList(ctx context.Context, app string) ([]Collaborator, error) {
var collaboratorsRes CollaboratorsRes
err := c.ScalingoAPI().SubresourceList(ctx, "apps", app, "collaborators", nil, &collaboratorsRes)
if err != nil {
return nil, errgo.Mask(err)
}
return collaboratorsRes.Collaborators, nil
}
func (c *Client) CollaboratorAdd(ctx context.Context, app string, email string) (Collaborator, error) {
var collaboratorRes CollaboratorRes
err := c.ScalingoAPI().SubresourceAdd(ctx, "apps", app, "collaborators", CollaboratorRes{
Collaborator: Collaborator{Email: email},
}, &collaboratorRes)
if err != nil {
return Collaborator{}, errgo.Mask(err)
}
return collaboratorRes.Collaborator, nil
}
func (c *Client) CollaboratorRemove(ctx context.Context, app string, id string) error {
return c.ScalingoAPI().SubresourceDelete(ctx, "apps", app, "collaborators", id)
}