lunchmoney

package module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 11 Imported by: 1

README

lunchmoney

GoDoc Go Report Card Build Status

Golang API wrapper for Lunch Money API

To use this API, you need to create an API token by following the directions at developers.lunchmoney.app.

Notes

  • We currently only support read only requests. We'd love a PR to add support for write though!
  • We currently only support Go 1.14 and greater.

Documentation

Index

Constants

View Source
const (
	// BaseAPIURL is the base url we use for all API requests.
	BaseAPIURL = "https://dev.lunchmoney.app/"
)

Variables

This section is empty.

Functions

func ParseCurrency

func ParseCurrency(amount, currency string) (*money.Money, error)

ParseCurrency turns two strings into a money struct.

Types

type Asset

type Asset struct {
	ID              int64     `json:"id"`
	TypeName        string    `json:"type_name"`
	SubtypeName     string    `json:"subtype_name"`
	Name            string    `json:"name"`
	Balance         string    `json:"balance"`
	BalanceAsOf     time.Time `json:"balance_as_of"`
	Currency        string    `json:"currency"`
	Status          string    `json:"status"`
	InstitutionName string    `json:"institution_name"`
	CreatedAt       time.Time `json:"created_at"`
}

Asset is a single LM asset.

func (*Asset) ParsedAmount

func (a *Asset) ParsedAmount() (*money.Money, error)

ParsedAmount turns the currency from lunchmoney into a Go currency.

type AssetsResponse

type AssetsResponse struct {
	Assets []*Asset `json:"assets"`
}

AssetsResponse is a response to an asset lookup.

type Budget

type Budget struct {
	CategoryGroupName string                 `json:"category_group_name,omitempty"`
	CategoryID        int                    `json:"category_id"`
	CategoryName      string                 `json:"category_name"`
	Data              map[string]*BudgetData `json:"data,omitempty" validate:"dive"`
	ExcludeFromBudget bool                   `json:"exclude_from_budget"`
	ExcludeFromTotals bool                   `json:"exclude_from_totals"`
	GroupID           int                    `json:"group_id"`
	HasChildren       bool                   `json:"has_children,omitempty"`
	IsGroup           bool                   `json:"is_group,omitempty"`
	IsIncome          bool                   `json:"is_income"`
	Order             int                    `json:"order"`
	Recurring         struct {
		Sum  float64 `json:"sum"`
		List []struct {
			Payee    string  `json:"payee"`
			Amount   string  `json:"amount"`
			Currency string  `json:"currency"`
			ToBase   float64 `json:"to_base"`
		} `json:"list"`
	} `json:"recurring,omitempty"`
}

Budget defines a categories budget over time.

type BudgetData

type BudgetData struct {
	BudgetMonth     string      `json:"budget_month,omitempty" validate:"datetime=2006-01-02"`
	BudgetToBase    float64     `json:"budget_to_base,omitempty"`
	BudgetAmount    json.Number `json:"budget_amount,omitempty"`
	BudgetCurrency  string      `json:"budget_currency,omitempty"`
	SpendingToBase  float64     `json:"spending_to_base,omitempty"`
	NumTransactions int         `json:"num_transactions,omitempty"`
}

BudgetData is a single month's budget for a category.

func (*BudgetData) ParsedAmount

func (b *BudgetData) ParsedAmount() (*money.Money, error)

ParsedAmount turns the currency from lunchmoney into a Go currency.

type BudgetFilters

type BudgetFilters struct {
	StartDate string `json:"start_date" validate:"datetime=2006-01-02,required"`
	EndDate   string `json:"end_date" validate:"datetime=2006-01-02,required"`
}

BudgetFilters are options to pass into the request for budget history.

func (*BudgetFilters) ToMap

func (r *BudgetFilters) ToMap() (map[string]string, error)

ToMap converts the filters to a string map to be sent with the request as GET parameters.

type CategoriesResponse

type CategoriesResponse struct {
	Categories []*Category `json:"categories"`
	Error      string      `json:"error"`
}

CategoriesResponse is the response we get from requesting categories.

type Category

type Category struct {
	ID                int64     `json:"id"`
	Name              string    `json:"name"`
	Description       string    `json:"description"`
	IsIncome          bool      `json:"is_income"`
	ExcludeFromBudget bool      `json:"exclude_from_budget"`
	ExcludeFromTotals bool      `json:"exclude_from_totals"`
	UpdatedAt         time.Time `json:"updated_at"`
	CreatedAt         time.Time `json:"created_at"`
	IsGroup           bool      `json:"is_group"`
	GroupID           int64     `json:"group_id"`
}

Category is a single LM category.

type Client

type Client struct {
	HTTP *http.Client
	Base *url.URL
}

Client holds our base configuration for our LunchMoney client.

func NewClient

func NewClient(apikey string) (*Client, error)

NewClient creates a new client with the specified API key.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, options map[string]string) (io.Reader, error)

Get makes a request using the client to the path specified with the key/value pairs specified in options. It returns the body of the response or an error.

func (*Client) GetAssets

func (c *Client) GetAssets(ctx context.Context) ([]*Asset, error)

GetAssets gets all assets filtered by the filters.

func (*Client) GetBudgets

func (c *Client) GetBudgets(ctx context.Context, filters *BudgetFilters) ([]*Budget, error)

GetBudgets returns budgets within a time period.

func (*Client) GetPlaidAccounts

func (c *Client) GetPlaidAccounts(ctx context.Context) ([]*PlaidAccount, error)

GetPlaidAccounts gets all plaid accounts filtered by the filters.

func (*Client) GetRecurringExpenses

func (c *Client) GetRecurringExpenses(ctx context.Context, filters *RecurringExpenseFilters) ([]*RecurringExpense, error)

GetRecurringExpenses gets all recurring expenses filtered by the filters.

func (*Client) GetTags

func (c *Client) GetTags(ctx context.Context) ([]*Tag, error)

GetTags gets all tags filtered by the filters.

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, id int64, filters *TransactionFilters) (*Transaction, error)

GetTransaction gets a transaction by id.

func (*Client) GetTransactions

func (c *Client) GetTransactions(ctx context.Context, filters *TransactionFilters) ([]*Transaction, error)

GetTransactions gets all transactions filtered by the filters.

type ErrorResponse

type ErrorResponse struct {
	ErrorString   string `json:"error,omitempty"`
	ErrorName     string `json:"name,omitempty"`
	MessageString string `json:"message,omitempty"`
}

ErrorResponse is json if we get an error from the LM API.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type PlaidAccount

type PlaidAccount struct {
	ID                int64     `json:"id"`
	DateLinked        time.Time `json:"date_linked"`
	Name              string    `json:"name"`
	Type              string    `json:"type"`
	Subtype           string    `json:"subtype"`
	Mask              string    `json:"mask"`
	InstitutionName   string    `json:"institution_name"`
	Status            string    `json:"status"`
	LastImport        time.Time `json:"last_import"`
	Balance           string    `json:"balance"`
	Currency          string    `json:"currency"`
	BalanceLastUpdate time.Time `json:"balance_last_update"`
	Limit             int64     `json:"limit"`
}

PlaidAccount is a single LM Plaid account.

func (*PlaidAccount) ParsedAmount

func (p *PlaidAccount) ParsedAmount() (*money.Money, error)

ParsedAmount turns the currency from lunchmoney into a Go currency.

type PlaidAccountsResponse

type PlaidAccountsResponse struct {
	PlaidAccounts []*PlaidAccount `json:"plaid_accounts"`
}

PlaidAccountsResponse is a list plaid accounts response.

type RecurringExpense

type RecurringExpense struct {
	ID             int64     `json:"id"`
	StartDate      string    `json:"start_date" validate:"datetime=2006-01-02"`
	EndDate        string    `json:"end_date" validate:"datetime=2006-01-02"`
	Cadence        string    `json:"cadence"`
	Payee          string    `json:"payee"`
	Amount         string    `json:"amount"`
	Currency       string    `json:"currency"`
	CreatedAt      time.Time `json:"created_at"`
	Description    string    `json:"description"`
	BillingDate    string    `json:"billing_date"`
	Type           string    `json:"type"`
	OriginalName   string    `json:"original_name"`
	Source         string    `json:"source"`
	PlaidAccountID int64     `json:"plaid_account_id"`
	AssetID        int64     `json:"asset_id"`
	TransactionID  int64     `json:"transaction_id"`
}

RecurringExpense is like a transaction, but one that's scheduled to happen.

func (*RecurringExpense) ParsedAmount

func (r *RecurringExpense) ParsedAmount() (*money.Money, error)

ParsedAmount turns the currency from lunchmoney into a Go currency.

type RecurringExpenseFilters

type RecurringExpenseFilters struct {
	StartDate       string `json:"start_date" validate:"datetime=2006-01-02"`
	DebitAsNegative bool   `json:"debit_as_negative"`
}

RecurringExpenseFilters are options to pass to the request.

func (*RecurringExpenseFilters) ToMap

func (r *RecurringExpenseFilters) ToMap() (map[string]string, error)

ToMap converts the filters to a string map to be sent with the request as GET parameters.

type RecurringExpensesResponse

type RecurringExpensesResponse struct {
	RecurringExpenses []*RecurringExpense `json:"recurring_expenses"`
}

RecurringExpensesResponse is the data struct we get back from a get request.

type Tag

type Tag struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

Tag is a single LM tag.

type TagsResponse

type TagsResponse []*Tag

TagsResponse is the response from getting all tags.

type Transaction

type Transaction struct {
	ID             int64  `json:"id"`
	Date           string `json:"date" validate:"datetime=2006-01-02"`
	Payee          string `json:"payee"`
	Amount         string `json:"amount"`
	Currency       string `json:"currency"`
	Notes          string `json:"notes"`
	CategoryID     int64  `json:"category_id"`
	RecurringID    int64  `json:"recurring_id"`
	AssetID        int64  `json:"asset_id"`
	PlaidAccountID int64  `json:"plaid_account_id"`
	Status         string `json:"status"`
	IsGroup        bool   `json:"is_group"`
	GroupID        int64  `json:"group_id"`
	ParentID       int64  `json:"parent_id"`
	ExternalID     int64  `json:"external_id"`
}

Transaction is a single LM transaction.

func (*Transaction) ParsedAmount

func (t *Transaction) ParsedAmount() (*money.Money, error)

ParsedAmount turns the currency from lunchmoney into a Go currency.

type TransactionFilters

type TransactionFilters struct {
	TagID           int64  `json:"tag_id"`
	RecurringID     int64  `json:"recurring_id"`
	PlaidAccountID  int64  `json:"plaid_account_id"`
	CategoryID      int64  `json:"category_id"`
	AssetID         int64  `json:"asset_id"`
	Offset          int64  `json:"offset"`
	Limit           int64  `json:"limit"`
	StartDate       string `json:"start_date" validate:"datetime=2006-01-02"`
	EndDate         string `json:"end_date" validate:"datetime=2006-01-02"`
	DebitAsNegative bool   `json:"debit_as_negative"`
}

TransactionFilters are options to pass into the request for transactions.

func (*TransactionFilters) ToMap

func (r *TransactionFilters) ToMap() (map[string]string, error)

ToMap converts the filters to a string map to be sent with the request as GET parameters.

type TransactionsResponse

type TransactionsResponse struct {
	Transactions []*Transaction `json:"transactions"`
}

TransactionsResponse is the response we get from requesting transactions.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL