-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexpense-category.go
40 lines (35 loc) · 1.29 KB
/
expense-category.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
package harvest
import (
"fmt"
"time"
)
type ExpenseCategoriesResponse struct {
PagedResponse
ExpenseCategories []*ExpenseCategory `json:"expense_categories"`
}
type ExpenseCategory struct {
ID int64 `json:"id"`
Name string `json:"name"`
UnitName string `json:"unit_name"`
UnitPrice float64 `json:"unit_price"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Deactivated bool `json:"deactivated"`
}
func (a *API) GetExpenseCategory(expenseCategoryID int64, args Arguments) (expenseCategory *ExpenseCategory, err error) {
expenseCategory = &ExpenseCategory{}
path := fmt.Sprintf("/expense_categories/%v", expenseCategoryID)
err = a.Get(path, args, expenseCategory)
return expenseCategory, err
}
func (a *API) GetExpenseCategories(args Arguments) (expenseCategories []*ExpenseCategory, err error) {
expenseCategories = make([]*ExpenseCategory, 0)
expenseCategoriesResponse := ExpenseCategoriesResponse{}
err = a.GetPaginated("/expense_categories", args, &expenseCategoriesResponse, func() {
for _, ec := range expenseCategoriesResponse.ExpenseCategories {
expenseCategories = append(expenseCategories, ec)
}
expenseCategoriesResponse.ExpenseCategories = make([]*ExpenseCategory, 0)
})
return expenseCategories, err
}