forked from davidsteinsland/ynab-go
/
months.go
53 lines (44 loc) · 1.26 KB
/
months.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 MonthsService service
type MonthSummariesResponse struct {
Data MonthSummariesWrapper `json:"data"`
}
type MonthSummariesWrapper struct {
Months []MonthSummary `json:"months"`
}
type MonthDetailResponse struct {
Data MonthDetailWrapper `json:"data"`
}
type MonthDetailWrapper struct {
Month MonthDetail `json:"month"`
}
type MonthSummary struct {
Month string `json:"month"`
Note *string `json:"note"`
ToBeBudgeted *int `json:"to_be_budgeted"`
AgeOfMoney *int `json:"age_of_money"`
}
type MonthDetail struct {
MonthSummary
Categories []Category `json:"categories"`
}
/*
https://api.youneedabudget.com/v1#/Months/getBudgetMonths
*/
func (ms *MonthsService) List(budgetId string) ([]MonthSummary, error) {
var response MonthSummariesResponse
if err := service(*ms).do("GET", "budgets/" + budgetId + "/months", nil, &response); err != nil {
return nil, err
}
return response.Data.Months, nil
}
/*
https://api.youneedabudget.com/v1#/Months/getBudgetMonth
*/
func (ms *MonthsService) Get(budgetId string, month string) (MonthDetail, error) {
var response MonthDetailResponse
if err := service(*ms).do("GET", "budgets/" + budgetId + "/months/" + month, nil, &response); err != nil {
return MonthDetail{}, err
}
return response.Data.Month, nil
}