client

package
v0.50.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client handles pincher-api calls

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID          uuid.UUID `json:"id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	BudgetID    uuid.UUID `json:"budget_id"`
	AccountType string    `json:"account_type"`
	IsDeleted   bool      `json:"is_deleted"`
	Meta
}

type Budget

type Budget struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	AdminID   uuid.UUID `json:"admin_id"`
	Meta
}

type Cache

type Cache struct {
	CachedEntries map[string]cacheEntry `json:"cached_entries"`
	// contains filtered or unexported fields
}

func NewCache

func NewCache(interval time.Duration) *Cache

func (*Cache) Add

func (c *Cache) Add(key string, value []byte, protect bool)

func (*Cache) Clear

func (c *Cache) Clear()

Clear deletes all cached entries.

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) DeleteAllStartsWith

func (c *Cache) DeleteAllStartsWith(prefix string)

DeleteAllStartsWith removes all cached entries whose key starts with the given prefix. This can be used to invalidate all entries related to a resource that may have had an instance updated or removed.

func (*Cache) Get

func (c *Cache) Get(key string) (entryData []byte, found bool)

func (*Cache) Set

func (c *Cache) Set(entries map[string]cacheEntry)

type Category

type Category struct {
	ID        uuid.UUID  `json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	BudgetID  uuid.UUID  `json:"budget_id"`
	GroupID   *uuid.UUID `json:"group_id"`
	Meta
}

type CategoryReport

type CategoryReport struct {
	MonthID  time.Time `json:"month_id"`
	Name     string    `json:"category_name"`
	Assigned int64     `json:"assigned"`
	Activity int64     `json:"activity"`
	Balance  int64     `json:"balance"`
}

type Client

type Client struct {
	http.Client

	ViewedBudget Budget
	BaseURL      string

	RefreshToken string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(timeout, cacheInterval time.Duration, baseURL string) Client

func (*Client) API

func (c *Client) API() string

func (*Client) AssignAmountToCategory

func (c *Client) AssignAmountToCategory(amount int64, toCategoryName, fromCategoryName, monthID string) error

func (*Client) ClearCache

func (c *Client) ClearCache()

ClearCache calls the Clear() function on the cache attached to the client and forces an early save of the cache file.

func (*Client) CreateAccount

func (c *Client) CreateAccount(name, notes, accountType string) (success bool, error error)

func (*Client) CreateBudget

func (c *Client) CreateBudget(name, notes string) (success bool, error error)

func (*Client) CreateCategory

func (c *Client) CreateCategory(name, notes, groupName string) (success bool, error error)

func (*Client) CreateGroup

func (c *Client) CreateGroup(name, notes string) (success bool, error error)

func (*Client) CreatePayee

func (c *Client) CreatePayee(name, notes string) (success bool, error error)

func (*Client) CreateUser

func (c *Client) CreateUser(username, password string) (success bool, error error)

func (*Client) Delete

func (c *Client) Delete(url, token string, payload any) (*http.Response, error)

Delete wrapper for doRequest

func (*Client) DeleteAccount

func (c *Client) DeleteAccount(accountID, deleteHard string) error

func (*Client) DeleteBudget

func (c *Client) DeleteBudget(budgetID string) error

func (*Client) DeleteCategory

func (c *Client) DeleteCategory(categoryID string) error

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(groupID string) error

func (*Client) DeletePayee

func (c *Client) DeletePayee(payeeID, newPayeeName string) error

func (*Client) DeleteUser

func (c *Client) DeleteUser(username, password string) error

func (*Client) Get

func (c *Client) Get(url, token string, out any) (response *http.Response, respFromCache bool, err error)

Get wrapper for doRequest

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() error

func (*Client) GetAccessTokenWithUser

func (c *Client) GetAccessTokenWithUser() (user User, err error)

func (*Client) GetAccounts

func (c *Client) GetAccounts(urlQuery string) ([]Account, error)

func (*Client) GetBudgetReport

func (c *Client) GetBudgetReport(monthID string) (MonthReport, error)

func (*Client) GetBudgets

func (c *Client) GetBudgets(urlQuery string) ([]Budget, error)

func (*Client) GetCategories

func (c *Client) GetCategories(urlQuery string) ([]Category, error)

func (*Client) GetCategoryReports

func (c *Client) GetCategoryReports(monthID string) ([]CategoryReport, error)

func (*Client) GetGroups

func (c *Client) GetGroups(urlQuery string) ([]Group, error)

func (*Client) GetPayees

func (c *Client) GetPayees(urlQuery string) ([]Payee, error)

func (*Client) GetServerReady

func (c *Client) GetServerReady() (bool, error)

GetServerReady reports back with a 200 Status Code

func (*Client) GetTxns

func (c *Client) GetTxns(urlQuery string) ([]TransactionDetail, error)

func (*Client) LoadCacheFile

func (c *Client) LoadCacheFile() error

LoadCacheFile looks for a file with the given name within the user cache directory and attempts to load it into the cache.

func (*Client) LogTxn

func (c *Client) LogTxn(accountName, transferAccountName, transactionDate, payeeName, notes string, isCleared bool, amounts map[string]int64) (success bool, error error)

func (*Client) LoginUser

func (c *Client) LoginUser(username, password string) (User, error)

func (*Client) MakeRequest

func (c *Client) MakeRequest(method, path, token string, body any) (*http.Request, error)

func (*Client) Patch

func (c *Client) Patch(url, token string, payload any) (*http.Response, error)

Patch wrapper for doRequest

func (*Client) Post

func (c *Client) Post(url, token string, payload, out any) (*http.Response, error)

Post wrapper for doRequest

func (*Client) Put

func (c *Client) Put(url, token string, payload any) (*http.Response, error)

Put wrapper for doRequest

func (*Client) RestoreAccount

func (c *Client) RestoreAccount(accountID, name string) error

func (*Client) RevokeRefreshToken

func (c *Client) RevokeRefreshToken() error

func (*Client) SaveCacheFile

func (c *Client) SaveCacheFile() error

SaveCacheFile saves the current cache to a local file with the given name under the user cache directory.

func (*Client) UpdateAccount

func (c *Client) UpdateAccount(accountID, name, notes, accountType string) error

func (*Client) UpdateBudget

func (c *Client) UpdateBudget(budgetID, name, notes string) error

func (*Client) UpdateCategory

func (c *Client) UpdateCategory(categoryID, name, notes, groupID string) error

func (*Client) UpdateGroup

func (c *Client) UpdateGroup(groupID, name, notes string) error

func (*Client) UpdatePayee

func (c *Client) UpdatePayee(payeeID, name, notes string) error

func (*Client) UpdateUser

func (c *Client) UpdateUser(username, password string) error

type Group

type Group struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	BudgetID  uuid.UUID `json:"budget_id"`
	Meta
}

type Meta

type Meta struct {
	Name  string `json:"name"`
	Notes string `json:"notes"`
}

type MonthReport

type MonthReport struct {
	Assigned int64 `json:"assigned"`
	Activity int64 `json:"activity"`
	Balance  int64 `json:"balance"`
}

type Payee

type Payee struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	BudgetID  uuid.UUID `json:"budget_id"`
	Meta
}

type Transaction

type Transaction struct {
	ID              uuid.UUID `json:"id"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	BudgetID        uuid.UUID `json:"budget_id"`
	LoggerID        uuid.UUID `json:"logger_id"`
	AccountID       uuid.UUID `json:"account_id"`
	TransactionType string    `json:"transaction_type"`
	TransactionDate time.Time `json:"transaction_date"`
	PayeeID         uuid.UUID `json:"payee_id"`
	Notes           string    `json:"notes"`
	Cleared         bool      `json:"is_cleared"`
}

type TransactionDetail

type TransactionDetail struct {
	ID              uuid.UUID        `json:"id"`
	TransactionDate time.Time        `json:"transaction_date"`
	TransactionType string           `json:"transaction_type"`
	Notes           string           `json:"notes"`
	PayeeName       string           `json:"payee_name"`
	BudgetName      string           `json:"budget_name"`
	AccountName     string           `json:"account_name"`
	LoggerName      string           `json:"logger_name"`
	TotalAmount     int64            `json:"total_amount"`
	Splits          map[string]int64 `json:"splits"`
	Cleared         bool             `json:"cleared"`
}

type TransactionSplit

type TransactionSplit struct {
	ID            uuid.UUID  `json:"id"`
	TransactionID uuid.UUID  `json:"transaction_id"`
	CategoryID    *uuid.UUID `json:"category_id"`
	Amount        int64      `json:"amount"`
}

type User

type User struct {
	ID             uuid.UUID `json:"id"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
	Username       string    `json:"username"`
	HashedPassword string    `json:"-"`
}

Jump to

Keyboard shortcuts

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