-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
45 lines (36 loc) · 900 Bytes
/
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
package mercadopago
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type TestUser struct {
ID int `json:"id"`
Nickname string `json:"nickname"`
Password string `json:"password"`
SiteStatus string `json:"site_status"`
Email string `json:"email"`
}
type TestUserParams struct {
SiteID string `json:"site_id"`
}
// NewTestUser creates a new test user
func (c *client) NewTestUser(params TestUserParams) (*TestUser, error) {
u := fmt.Sprintf("%s/users/test_user", c.baseURL)
body, err := json.Marshal(params)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, u, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.accessToken))
var testUser TestUser
err = c.requestAndDecode(req, &testUser)
if err != nil {
return nil, err
}
return &testUser, nil
}