forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.go
52 lines (44 loc) · 1.15 KB
/
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
48
49
50
51
52
package aiven
import (
"encoding/json"
"errors"
)
type (
// Card represents the card model on Aiven.
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 is the client that interacts with the cards endpoints on
// Aiven.
CardsHandler struct {
client *Client
}
// CardListResponse is the response for listing cards.
CardListResponse struct {
APIResponse
Cards []*Card `json:"cards"`
}
)
// List lists all the cards linked to the authenticated account/
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
}