forked from davidsteinsland/ynab-go
/
accounts.go
53 lines (45 loc) · 1.29 KB
/
accounts.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
53
package ynab
type AccountsService service
type AccountsResponse struct {
Data AccountsWrapper `json:"data"`
}
type AccountsWrapper struct {
Accounts []Account `json:"accounts"`
}
type AccountResponse struct {
Data AccountWrapper `json:"data"`
}
type AccountWrapper struct {
Account Account `json:"account"`
}
type Account struct {
Id string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
OnBudget bool `json:"on_budget"`
Closed bool `json:"closed"`
Note *string `json:"note"`
Balance int `json:"balance"`
ClearedBalance int `json:"cleared_balance"`
UnclearedBalance int `json:"uncleared_balance"`
}
/*
https://api.youneedabudget.com/v1#/Accounts/getAccounts
*/
func (as *AccountsService) List(budgetId string) ([]Account, error) {
var response AccountsResponse
if err := service(*as).do("GET", "budgets/" + budgetId + "/accounts", nil, &response); err != nil {
return nil, err
}
return response.Data.Accounts, nil
}
/*
https://api.youneedabudget.com/v1#/Accounts/getAccountById
*/
func (as *AccountsService) Get(budgetId string, accountId string) (Account, error) {
var response AccountResponse
if err := service(*as).do("GET", "budgets/" + budgetId + "/accounts/" + accountId, nil, &response); err != nil {
return Account{}, err
}
return response.Data.Account, nil
}