-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
122 lines (114 loc) · 3.01 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package fluidpay
import (
"encoding/json"
)
// ChangePassword changes your password to the new one given in the request body.
func ChangePassword(fluidpay Fluidpay, reqBody ChangePasswordRequest) (GeneralResponse, error) {
var response GeneralResponse
body, err := json.Marshal(reqBody)
if err != nil {
return response, err
}
param := []string{"user", "change-password"}
resBody, err := DoRequest(fluidpay, "POST", param, body)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// CreateUser creates a new user.
func CreateUser(fluidpay Fluidpay, reqBody CreateUserRequest) (UserResponse, error) {
var response UserResponse
body, err := json.Marshal(reqBody)
if err != nil {
return response, err
}
param := []string{"user"}
resBody, err := DoRequest(fluidpay, "POST", param, body)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// UpdateUser updates the user identified by the ID.
func UpdateUser(fluidpay Fluidpay, reqBody UpdateUserRequest, userID string) (UserResponse, error) {
var response UserResponse
body, err := json.Marshal(reqBody)
if err != nil {
return response, err
}
param := []string{"user", userID}
resBody, err := DoRequest(fluidpay, "POST", param, body)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// GetUser gets a specific user identified by the ID.
func GetUser(fluidpay Fluidpay, userID string) (UserResponse, error) {
var response UserResponse
param := []string{"user", userID}
resBody, err := DoRequest(fluidpay, "GET", param, nil)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// GetCurrentUser gets current user.
func GetCurrentUser(fluidpay Fluidpay) (UserResponse, error) {
var response UserResponse
param := []string{"user"}
resBody, err := DoRequest(fluidpay, "GET", param, nil)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// GetUsers gets all the users.
func GetUsers(fluidpay Fluidpay) (UsersResponse, error) {
var response UsersResponse
param := []string{"users"}
resBody, err := DoRequest(fluidpay, "GET", param, nil)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}
// DeleteUser deletes the user identified by the id.
func DeleteUser(fluidpay Fluidpay, userID string) (GeneralResponse, error) {
var response GeneralResponse
param := []string{"user", userID}
resBody, err := DoRequest(fluidpay, "DELETE", param, nil)
if err != nil {
return response, err
}
err = json.Unmarshal(resBody, &response)
if err != nil {
return response, err
}
return response, nil
}