budget

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2018 License: BSD-2-Clause Imports: 8 Imported by: 6

Documentation

Overview

Package budget implements budget entities and services

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

type Budget struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	Accounts                 []*account.Account                     `json:"accounts"`
	Payees                   []*payee.Payee                         `json:"payees"`
	PayeeLocations           []*payee.Location                      `json:"payee_locations"`
	Categories               []*category.Category                   `json:"categories"`
	CategoryGroups           []*category.Group                      `json:"category_groups"`
	Months                   []*month.Month                         `json:"months"`
	Transactions             []*transaction.Summary                 `json:"transactions"`
	SubTransactions          []*transaction.SubTransaction          `json:"subtransactions"`
	ScheduledTransactions    []*transaction.ScheduledSummary        `json:"scheduled_transactions"`
	ScheduledSubTransactions []*transaction.ScheduledSubTransaction `json:"scheduled_sub_transactions"`

	// DateFormat the date format setting for the budget. In some cases
	// the format will not be available and will be specified as null.
	DateFormat *DateFormat `json:"date_format"`
	// CurrencyFormat the currency format setting for the budget. In
	// some cases the format will not be available and will be specified
	// as null.
	CurrencyFormat *CurrencyFormat `json:"currency_format"`
	// LastModifiedOn the last time any changes were made to the budget
	// from either a web or mobile client.
	LastModifiedOn *time.Time `json:"last_modified_on"`
	// FirstMonth undocumented field
	FirstMonth *api.Date `json:"first_month"`
	// LastMonth undocumented field
	LastMonth *api.Date `json:"last_month"`
}

Budget represents a budget

type CurrencyFormat

type CurrencyFormat struct {
	ISOCode          string `json:"iso_code"`
	ExampleFormat    string `json:"example_format"`
	DecimalDigits    uint64 `json:"decimal_digits"`
	DecimalSeparator string `json:"decimal_separator"`
	GroupSeparator   string `json:"group_separator"`
	SymbolFirst      bool   `json:"symbol_first"`
	CurrencySymbol   string `json:"currency_symbol"`
	DisplaySymbol    bool   `json:"display_symbol"`
}

CurrencyFormat represents a currency format for a budget settings

type DateFormat

type DateFormat struct {
	Format string `json:"format"`
}

DateFormat represents date format for a budget

type Filter

type Filter struct {
	// LastKnowledgeOfServer The starting server knowledge. If provided,
	// only entities that have changed since last_knowledge_of_server
	// will be included
	LastKnowledgeOfServer uint64
}

Filter represents the optional version filter while fetching a budget

func (*Filter) ToQuery

func (f *Filter) ToQuery() string

ToQuery returns the filters as a HTTP query string

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service wraps YNAB budget API endpoints

func NewService

func NewService(c api.ClientReader) *Service

NewService facilitates the creation of a new budget service instance

func (*Service) GetBudget

func (s *Service) GetBudget(budgetID string, f *Filter) (*Snapshot, error)

GetBudget fetches a single budget with all related entities, effectively a full budget export with filtering capabilities https://api.youneedabudget.com/v1#/Budgets/getBudgetById

Example
package main

import (
	"fmt"
	"reflect"

	"go.bmvs.io/ynab"
)

func main() {
	c := ynab.NewClient("<valid_ynab_access_token>")
	b, _ := c.Budget().GetBudget("<valid_budget_id>", nil)
	fmt.Println(reflect.TypeOf(b))

}
Output:

*budget.Snapshot
Example (Filtered)
package main

import (
	"fmt"
	"reflect"

	"go.bmvs.io/ynab"
	"go.bmvs.io/ynab/api/budget"
)

func main() {
	c := ynab.NewClient("<valid_ynab_access_token>")

	f := budget.Filter{LastKnowledgeOfServer: 10}
	b, _ := c.Budget().GetBudget("<valid_budget_id>", &f)
	fmt.Println(reflect.TypeOf(b))

}
Output:

*budget.Snapshot

func (*Service) GetBudgetSettings

func (s *Service) GetBudgetSettings(budgetID string) (*Settings, error)

GetBudgetSettings fetches a budget settings https://api.youneedabudget.com/v1#/Budgets/getBudgetSettingsById

Example
package main

import (
	"fmt"
	"reflect"

	"go.bmvs.io/ynab"
)

func main() {
	c := ynab.NewClient("<valid_ynab_access_token>")
	s, _ := c.Budget().GetBudgetSettings("<valid_budget_id>")
	fmt.Println(reflect.TypeOf(s))

}
Output:

*budget.Settings

func (*Service) GetBudgets

func (s *Service) GetBudgets() ([]*Summary, error)

GetBudgets fetches the list of budgets of the logger in user https://api.youneedabudget.com/v1#/Budgets/getBudgets

Example
package main

import (
	"fmt"
	"reflect"

	"go.bmvs.io/ynab"
)

func main() {
	c := ynab.NewClient("<valid_ynab_access_token>")
	budgets, _ := c.Budget().GetBudgets()
	fmt.Println(reflect.TypeOf(budgets))

}
Output:

[]*budget.Summary

func (*Service) GetLastUsedBudget

func (s *Service) GetLastUsedBudget(f *Filter) (*Snapshot, error)

GetLastUsedBudget fetches the last used budget with all related entities, effectively a full budget export with filtering capabilities https://api.youneedabudget.com/v1#/Budgets/getBudgetById

Example
package main

import (
	"fmt"
	"reflect"

	"go.bmvs.io/ynab"
)

func main() {
	c := ynab.NewClient("<valid_ynab_access_token>")
	b, _ := c.Budget().GetLastUsedBudget(nil)
	fmt.Println(reflect.TypeOf(b))

}
Output:

*budget.Snapshot

type Settings

type Settings struct {
	// DateFormat the date format setting for the budget. In some cases
	// the format will not be available and will be specified as null.
	DateFormat *DateFormat `json:"date_format"`
	// CurrencyFormat the currency format setting for the budget. In
	// some cases the format will not be available and will be specified
	// as null.
	CurrencyFormat *CurrencyFormat `json:"currency_format"`
}

Settings represents the settings for a budget

type Snapshot

type Snapshot struct {
	Budget          *Budget
	ServerKnowledge int64
}

Snapshot represents a versioned snapshot for a budget

type Summary

type Summary struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	// DateFormat the date format setting for the budget. In some cases
	// the format will not be available and will be specified as null.
	DateFormat *DateFormat `json:"date_format"`
	// CurrencyFormat the currency format setting for the budget. In
	// some cases the format will not be available and will be specified
	// as null.
	CurrencyFormat *CurrencyFormat `json:"currency_format"`
	// LastModifiedOn the last time any changes were made to the budget
	// from either a web or mobile client.
	LastModifiedOn *time.Time `json:"last_modified_on"`
	// FirstMonth undocumented field
	FirstMonth *api.Date `json:"first_month"`
	// LastMonth undocumented field
	LastMonth *api.Date `json:"last_month"`
}

Summary represents the summary of a budget

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL