forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.go
47 lines (39 loc) · 929 Bytes
/
card.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
package aiven
import (
"encoding/json"
"errors"
)
type (
Card struct {
Brand string `json:"brand"`
CardId string `json:"card_id"`
Country string `json:"country"`
CountryCode string `json:"country_code"`
ExpMonth int `json:"exp_month"`
ExpYear int `json:"exp_year"`
Last4 string `json:"last4"`
Name string `json:"name"`
ProjectNames []string `json:"projects"`
}
CardsHandler struct {
client *Client
}
CardListResponse struct {
APIResponse
Cards []*Card `json:"cards"`
}
)
func (h *CardsHandler) List() ([]*Card, error) {
rsp, err := h.client.doGetRequest("/card", nil)
if err != nil {
return nil, err
}
var response *CardListResponse
if err := json.Unmarshal(rsp, &response); err != nil {
return nil, err
}
if len(response.Errors) != 0 {
return nil, errors.New(response.Message)
}
return response.Cards, nil
}