diff --git a/api.go b/api.go index 253baf6..bb90bed 100644 --- a/api.go +++ b/api.go @@ -187,6 +187,27 @@ type Statements []struct { Year int `json:"year"` } +type Spaces struct { + Spaces []struct { + Balance struct { + AvailableBalance float64 `json:"availableBalance"` + OverdraftAmount interface{} `json:"overdraftAmount"` + } `json:"balance"` + Color string `json:"color"` + Goal interface{} `json:"goal"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + IsCardAttached bool `json:"isCardAttached"` + IsPrimary bool `json:"isPrimary"` + Name string `json:"name"` + } `json:"spaces"` + TotalBalance float64 `json:"totalBalance"` + UserFeatures struct { + AvailableSpaces int `json:"availableSpaces"` + CanUpgrade bool `json:"canUpgrade"` + } `json:"userFeatures"` +} + type Client http.Client func NewClient(a Auth) (*Client, error) { @@ -365,6 +386,17 @@ func (auth *Client) UnblockCard(ID string) { fmt.Printf("\nYour card with ID: %s is ACTIVE\n\n", ID) } +func (auth *Client) GetSpaces(retType string) (string, *Spaces) { + body := auth.n26Request(http.MethodGet, "/api/spaces", nil) + spaces := &Spaces{} + check(json.Unmarshal(body, &spaces)) + identedJSON, _ := json.MarshalIndent(&spaces, "", " ") + if retType == "json" { + return string(identedJSON), spaces + } + return "", spaces +} + func check(e error) { if e != nil { panic(e)