-
Notifications
You must be signed in to change notification settings - Fork 32
/
users.go
50 lines (40 loc) · 1.39 KB
/
users.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 api
import (
"context"
"github.com/manifoldco/torus-cli/apitypes"
"github.com/manifoldco/torus-cli/envelope"
"github.com/manifoldco/torus-cli/registry"
)
// UsersClient makes requests to the registry's and daemon's users endpoints
type UsersClient struct {
*registry.UsersClient
client *apiRoundTripper
}
func newUsersClient(upstream *registry.UsersClient, rt *apiRoundTripper) *UsersClient {
return &UsersClient{upstream, rt}
}
// Create will have the daemon create a new user request
func (u *UsersClient) Create(ctx context.Context, signup *apitypes.Signup, output *ProgressFunc) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "POST", "/signup", nil, &signup, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
}
// Update performs a profile update to the user object
func (u *UsersClient) Update(ctx context.Context, delta apitypes.ProfileUpdate) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "PATCH", "/self", nil, &delta, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
}
// Verify verifies the users account using the given code
func (u *UsersClient) Verify(ctx context.Context, code string) error {
verifyEmail := apitypes.VerifyEmail{
Code: code,
}
return u.client.DaemonRoundTrip(ctx, "POST", "/verify", nil, &verifyEmail, nil, nil)
}