-
Notifications
You must be signed in to change notification settings - Fork 0
/
apikey.go
54 lines (50 loc) · 1.28 KB
/
apikey.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
package fluidpay
import (
"encoding/json"
)
//CreateKey creates a new API key for a user.
func CreateKey(fluidpay Fluidpay, reqBody KeyRequest) (KeyResponse, error) {
var response KeyResponse
body, err := json.Marshal(reqBody)
if err != nil {
return response, err
}
param := []string{"user", "apikey"}
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
}
// GetKeys gets all the API keys to a user.
func GetKeys(fluidpay Fluidpay) (KeysResponse, error) {
var response KeysResponse
param := []string{"user", "apikeys"}
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
}
// DeleteKey deletes the API key identified by the id.
func DeleteKey(fluidpay Fluidpay, apiKeyID string) (KeyResponse, error) {
var response KeyResponse
param := []string{"user", "apikey", apiKeyID}
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
}