-
Notifications
You must be signed in to change notification settings - Fork 3
/
api_keys.go
45 lines (40 loc) · 1.33 KB
/
api_keys.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 btcpay
import (
"context"
"fmt"
)
func (c *Client) RevokeAPIKey(ctx context.Context, apiKey *APIKey) (int, error) {
endpoint := fmt.Sprintf("%s/api/v1/api-keys/%s", c.URL, *apiKey)
statusCode, err := c.doRequest(ctx, endpoint, "DELETE", nil, nil)
if err != nil {
return statusCode, err
}
return statusCode, nil
}
func (c *Client) GetCurrentAPIKey(ctx context.Context) (*APIKeyResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/api-keys/current", c.URL)
var dataRes APIKeyResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
func (c *Client) RevokeCurrentAPIKey(ctx context.Context) (*APIKeyResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/api-keys/current", c.URL)
var dataRes APIKeyResponse
statusCode, err := c.doRequest(ctx, endpoint, "DELETE", &dataRes, nil)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
func (c *Client) CreateAPIKey(ctx context.Context, apiKeyRequest *APIKeyRequest) (*APIKeyResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/api-keys", c.URL)
var dataRes APIKeyResponse
statusCode, err := c.doRequest(ctx, endpoint, "POST", &dataRes, apiKeyRequest)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}