forked from yunpian/yunpian-go-sdk
/
user.go
86 lines (71 loc) · 2.13 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package yunpian
// User is used to manipulate the user API
type User struct {
c *Client
}
// User is used to return a handle to the user APIs
func (c *Client) User() *User {
return &User{c}
}
// UserResponse - 账户信息响应
type UserResponse struct {
Nick string `json:"nick"`
Created string `json:"gmt_created"`
Mobile string `json:"mobile"`
Email string `json:"email"`
IPWhitelist string `json:"ip_whitelist"`
APIVersion string `json:"api_version"`
Balance float64 `json:"balance"`
AlarmBalance int64 `json:"alarm_balance"`
EmergencyContact string `json:"emergency_contact"`
EmergencyMobile string `json:"emergency_mobile"`
}
// Get - 查询账户信息接口
func (u *User) Get() (*UserResponse, error) {
r := u.c.newRequest("POST", u.c.config.userHost, "/v2/user/get.json")
r.header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
reader, err := u.c.encodeFormBody(struct{}{})
if err != nil {
return nil, err
}
r.body = reader
resp, err := u.c.doRequest(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result UserResponse
if err = u.c.handleResponse(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// UserSetRequest - 修改账号信息请求参数
type UserSetRequest struct {
EmergencyContact string `schema:"emergency_contact,omitempty"`
EmergencyMobile string `schema:"emergency_mobile,omitempty"`
AlarmBalance int64 `schema:"alarm_balance,omitempty"`
}
// Set - 修改账号信息接口
func (u *User) Set(input *UserSetRequest) (*UserResponse, error) {
if input == nil {
input = &UserSetRequest{}
}
r := u.c.newRequest("POST", u.c.config.userHost, "/v2/user/set.json")
r.header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
reader, err := u.c.encodeFormBody(input)
if err != nil {
return nil, err
}
r.body = reader
resp, err := u.c.doRequest(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result UserResponse
if err = u.c.handleResponse(resp, &result); err != nil {
return nil, err
}
return &result, nil
}