Documentation
¶
Overview ¶
Package category implements category entities and services
Index ¶
- type Category
- type Goal
- type Group
- type GroupWithCategories
- type PayloadMonthCategory
- type Service
- func (s *Service) GetCategories(budgetID string) ([]*GroupWithCategories, error)
- func (s *Service) GetCategory(budgetID, categoryID string) (*Category, error)
- func (s *Service) GetCategoryForCurrentMonth(budgetID, categoryID string) (*Category, error)
- func (s *Service) GetCategoryForMonth(budgetID, categoryID string, month api.Date) (*Category, error)
- func (s *Service) UpdateCategoryForCurrentMonth(budgetID, categoryID string, p PayloadMonthCategory) (*Category, error)
- func (s *Service) UpdateCategoryForMonth(budgetID, categoryID string, month api.Date, p PayloadMonthCategory) (*Category, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct { ID string `json:"id"` CategoryGroupID string `json:"category_group_id"` Name string `json:"name"` Hidden bool `json:"hidden"` // Budgeted Budgeted amount in current month in milliunits format Budgeted int64 `json:"budgeted"` // Activity Activity amount in current month in milliunits format Activity int64 `json:"activity"` // Balance Balance in current month in milliunits format Balance int64 `json:"balance"` // Deleted Deleted category groups will only be included in delta requests Deleted bool `json:"deleted"` Note *string `json:"note"` // OriginalCategoryGroupID If category is hidden this is the ID of the category // group it originally belonged to before it was hidden OriginalCategoryGroupID *string `json:"original_category_group_id"` GoalType *Goal `json:"goal_type"` // GoalCreationMonth the month a goal was created GoalCreationMonth *api.Date `json:"goal_creation_month"` // GoalTarget the goal target amount in milliunits GoalTarget *int64 `json:"goal_target"` // GoalTargetMonth if the goal type is GoalTargetCategoryBalanceByDate, // this is the target month for the goal to be completed GoalTargetMonth *api.Date `json:"goal_target_month"` // GoalPercentageComplete the percentage completion of the goal GoalPercentageComplete *uint16 `json:"goal_percentage_complete"` }
Category represents a category for a budget
type Goal ¶
type Goal string
Goal represents the goal of a category
const ( // GoalTargetCategoryBalance Goal targets category balance GoalTargetCategoryBalance Goal = "TB" // GoalTargetCategoryBalanceByDate Goal targets category balance by date GoalTargetCategoryBalanceByDate Goal = "TBD" // GoalMonthlyFunding Goal by monthly funding GoalMonthlyFunding Goal = "MF" )
type Group ¶
type Group struct { ID string `json:"id"` Name string `json:"name"` Hidden bool `json:"hidden"` // Deleted Deleted category groups will only be included in delta requests Deleted bool `json:"deleted"` }
Group represents a resumed category group for a budget
type GroupWithCategories ¶
type GroupWithCategories struct { ID string `json:"id"` Name string `json:"name"` Hidden bool `json:"hidden"` // Deleted Deleted category groups will only be included in delta requests Deleted bool `json:"deleted"` Categories []*Category `json:"categories"` }
GroupWithCategories represents a category group for a budget
type PayloadMonthCategory ¶
type PayloadMonthCategory struct {
Budgeted int64
}
PayloadMonthCategory is the payload contract for updating a category for a month
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service wraps YNAB category API endpoints
func NewService ¶
func NewService(c api.ClientReaderWriter) *Service
NewService facilitates the creation of a new category service instance
func (*Service) GetCategories ¶
func (s *Service) GetCategories(budgetID string) ([]*GroupWithCategories, error)
GetCategories fetches the list of category groups for a budget https://api.youneedabudget.com/v1#/Categories/getCategories
Example ¶
package main import ( "fmt" "reflect" "go.bmvs.io/ynab" ) func main() { client := ynab.NewClient("<valid_ynab_access_token>") categories, _ := client.Category().GetCategories("<valid_budget_id>") fmt.Println(reflect.TypeOf(categories)) }
Output: []*category.GroupWithCategories
func (*Service) GetCategory ¶
GetCategory fetches a specific category from a budget https://api.youneedabudget.com/v1#/Categories/getCategoryById
Example ¶
package main import ( "fmt" "reflect" "go.bmvs.io/ynab" ) func main() { client := ynab.NewClient("<valid_ynab_access_token>") c, _ := client.Category().GetCategory("<valid_budget_id>", "<valid_category_id>") fmt.Println(reflect.TypeOf(c)) }
Output: *category.Category
func (*Service) GetCategoryForCurrentMonth ¶
GetCategoryForCurrentMonth fetches a specific category from the current budget month https://api.youneedabudget.com/v1#/Categories/getMonthCategoryById
Example ¶
package main import ( "fmt" "reflect" "go.bmvs.io/ynab" ) func main() { client := ynab.NewClient("<valid_ynab_access_token>") c, _ := client.Category().GetCategoryForCurrentMonth("<valid_budget_id>", "<valid_category_id>") fmt.Println(reflect.TypeOf(c)) }
Output: *category.Category
func (*Service) GetCategoryForMonth ¶
func (s *Service) GetCategoryForMonth(budgetID, categoryID string, month api.Date) (*Category, error)
GetCategoryForMonth fetches a specific category from a budget month https://api.youneedabudget.com/v1#/Categories/getMonthCategoryById
Example ¶
package main import ( "fmt" "reflect" "go.bmvs.io/ynab" "go.bmvs.io/ynab/api" ) func main() { client := ynab.NewClient("<valid_ynab_access_token>") c, _ := client.Category().GetCategoryForMonth("<valid_budget_id>", "<valid_category_id>", api.Date{}) fmt.Println(reflect.TypeOf(c)) }
Output: *category.Category
func (*Service) UpdateCategoryForCurrentMonth ¶
func (s *Service) UpdateCategoryForCurrentMonth(budgetID, categoryID string, p PayloadMonthCategory) (*Category, error)
UpdateCategoryForCurrentMonth updates a category for the current month https://api.youneedabudget.com/v1#/Categories/updateMonthCategory
Example ¶
package main import ( "fmt" "go.bmvs.io/ynab/api/category" "reflect" "go.bmvs.io/ynab" ) func main() { validPayload := category.PayloadMonthCategory{Budgeted: 1000} client := ynab.NewClient("<valid_ynab_access_token>") c, _ := client.Category().UpdateCategoryForCurrentMonth("<valid_budget_id>", "<valid_category_id>", validPayload) fmt.Println(reflect.TypeOf(c)) }
Output: *category.Category
func (*Service) UpdateCategoryForMonth ¶
func (s *Service) UpdateCategoryForMonth(budgetID, categoryID string, month api.Date, p PayloadMonthCategory) (*Category, error)
UpdateCategoryForMonth updates a category for a month https://api.youneedabudget.com/v1#/Categories/updateMonthCategory
Example ¶
package main import ( "fmt" "go.bmvs.io/ynab/api/category" "reflect" "go.bmvs.io/ynab" "go.bmvs.io/ynab/api" ) func main() { validMonth, _ := api.DateFromString("2018-01-01") validPayload := category.PayloadMonthCategory{Budgeted: 1000} client := ynab.NewClient("<valid_ynab_access_token>") c, _ := client.Category().UpdateCategoryForMonth("<valid_budget_id>", "<valid_category_id>", validMonth, validPayload) fmt.Println(reflect.TypeOf(c)) }
Output: *category.Category