forked from cherryservers/cherrygo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
54 lines (41 loc) · 1.54 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
51
52
53
54
package cherrygo
import "fmt"
const baseUserPath = "/v1/users"
// UsersService is an interface for interfacing with the the User endpoints of the CherryServers API
// See: https://api.cherryservers.com/doc/#tag/Users
type UsersService interface {
CurrentUser(opts *GetOptions) (User, *Response, error)
Get(userID int, opts *GetOptions) (User, *Response, error)
}
type User struct {
ID int `json:"id,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
Phone string `json:"phone,omitempty"`
SecurityPhone string `json:"security_phone,omitempty"`
SecurityPhoneVerified bool `json:"security_phone_verified,omitempty"`
Href string `json:"href,omitempty"`
}
type UsersClient struct {
client *Client
}
func (s *UsersClient) CurrentUser(opts *GetOptions) (User, *Response, error) {
var trans User
path := opts.WithQuery(fmt.Sprintf("/v1/user"))
resp, err := s.client.MakeRequest("GET", path, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}
func (s *UsersClient) Get(userID int, opts *GetOptions) (User, *Response, error) {
var trans User
path := opts.WithQuery(fmt.Sprintf("%s/%d", baseUserPath, userID))
resp, err := s.client.MakeRequest("GET", path, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}