/
RegisterUser.go
52 lines (43 loc) · 1.24 KB
/
RegisterUser.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
package platform
import (
"encoding/json"
"fmt"
"github.com/ao-space/platform-sdk-go/utils"
"github.com/jinzhu/copier"
"net/http"
"net/url"
)
type RegisterUserRequest struct {
UserID string `json:"userId"`
Subdomain string `json:"subdomain"`
UserType string `json:"userType"`
ClientUUID string `json:"clientUUID"`
}
type RegisterUserResponse struct {
BoxUUID string `json:"boxUUID"`
UserID string `json:"userId"`
UserDomain string `json:"userDomain"`
UserType string `json:"userType"`
ClientUUID string `json:"clientUUID"`
}
func (c *Client) RegisterUser(input *RegisterUserRequest) (*RegisterUserResponse, error) {
if !c.IsAvailable(uriRegisterUser, http.MethodPost) {
return nil, fmt.Errorf("the ability is not available: [%v] %v ", http.MethodPost, uriRegisterUser)
}
path := fmt.Sprintf("/platform/boxes/%v/users", c.BoxUUID)
URL := new(url.URL)
copier.Copy(URL, c.BaseURL)
URL = URL.JoinPath(path)
op := new(Operation)
op.SetOperation(http.MethodPost, URL)
requestBody, _ := json.Marshal(input)
response, err := c.Send(op, requestBody)
if err != nil {
return nil, err
}
output := new(RegisterUserResponse)
if err = utils.GetBody(response, output); err != nil {
return nil, err
}
return output, nil
}