-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.go
55 lines (44 loc) · 1.32 KB
/
User.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
package libremotebuild
import "strings"
// Login login into the server
func (librb LibRB) Login(username, password string) (*LoginResponse, error) {
var response LoginResponse
// Do http request
resp, err := librb.NewRequest(EPLogin, CredentialsRequest{
Password: password,
Username: strings.ToLower(username),
MachineID: librb.Config.MachineID,
}).Do(&response)
// Return new error on ... error
if err != nil || resp.Status == ResponseError {
return nil, NewErrorFromResponse(resp, err)
}
return &response, nil
}
// Register create a new account. Return true on success
func (librb LibRB) Register(username, password string) (*RestRequestResponse, error) {
// Do http request
resp, err := librb.NewRequest(EPRegister, CredentialsRequest{
Username: strings.ToLower(username),
Password: password,
}).Do(nil)
if err != nil || resp.Status == ResponseError {
return resp, NewErrorFromResponse(resp, err)
}
return resp, nil
}
// Ping pings a server the REST way to
// ensure it is reachable
func (librb LibRB) Ping() (*StringResponse, error) {
var response StringResponse
// Do ping request
req := librb.NewRequest(EPPing, PingRequest{Payload: "ping"})
if librb.Config.SessionToken != "" {
req.WithAuthFromConfig()
}
_, err := req.Do(&response)
if err != nil {
return nil, err
}
return &response, nil
}