Skip to content

Commit

Permalink
feat(spaces): adding spaces API
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Thomazi Bonicontro committed Aug 29, 2018
1 parent 2a6dc4b commit 59cdfad
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 59cdfad

Please sign in to comment.