client

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedactSuffixLength the number of characters that remain unredacted at the end of a string
	RedactSuffixLength = 4

	// Ledger account types
	AssetAccount     = "assets"
	LiabilityAccount = "liabilities"
	ExpenseAccount   = "expenses"
	RevenueAccount   = "revenues"
)
View Source
const (
	// Uncategorized is used as the default account2 on an imported transaction
	Uncategorized = "uncategorized"
)

Variables

View Source
var (
	// ErrAuthFailed is returned whenever a signon request fails with an authentication problem
	ErrAuthFailed = errors.New("Username or password is incorrect")
)

Functions

func IsChecking added in v0.3.0

func IsChecking(s string) bool

IsChecking returns true if the given account type is a checking account

func IsLocalhostTestURL added in v0.5.0

func IsLocalhostTestURL(urlStr string) bool

IsLocalhostTestURL returns true if this is a valid URL and starts with http://localhost

func IsSavings added in v0.3.0

func IsSavings(s string) bool

IsSavings returns true if the given account type is a savings account

func LedgerAccountName

func LedgerAccountName(a Account) string

LedgerAccountName returns a suitable account name for a ledger file

func New

func New(url string, config Config) (ofxgo.Client, error)

New creates a new ofxgo Client with the given connection info

func NewLocalClient added in v0.5.0

func NewLocalClient(url string, client *ofxgo.BasicClient) (ofxgo.Client, error)

NewLocalClient returns a new LocalClient for the given URL and basic client

func ReadOFX added in v0.5.0

func ReadOFX(r io.Reader) ([]ledger.Transaction, error)

ReadOFX reads r and parses it for an OFX file's transactions

func Transactions

func Transactions(account Account, start, end time.Time) ([]ledger.Transaction, error)

Transactions downloads and returns transactions from a bank or credit card account for the given time period, ending today

func Verify added in v0.3.0

func Verify(account Account) error

Verify attempts to sign in with the given account. Returns any encountered errors

Types

type Account

type Account interface {
	ID() string
	Description() string
	Institution() Institution

	Statement(start, end time.Time) (ofxgo.Request, error)
}

Account identifies an account at a financial institution

func NewCheckingAccount

func NewCheckingAccount(id, bankID, description string, institution Institution) Account

NewCheckingAccount creates an account from checking details

func NewCreditCard

func NewCreditCard(id, description string, institution Institution) Account

NewCreditCard creates an account from credit card details

func NewSavingsAccount

func NewSavingsAccount(id, bankID, description string, institution Institution) Account

NewSavingsAccount creates an account from savings details

func UnmarshalBuiltinAccount added in v0.3.0

func UnmarshalBuiltinAccount(b []byte) (Account, error)

type AccountStore added in v0.3.0

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

AccountStore enables manipulation of accounts in memory

func NewAccountStore added in v0.3.0

func NewAccountStore(accounts []Account) (*AccountStore, error)

NewAccountStore creates an account store from the given accounts, must not contain duplicate account IDs

func NewAccountStoreFromReader added in v0.3.0

func NewAccountStoreFromReader(r io.Reader) (*AccountStore, error)

NewAccountStoreFromReader returns a new account store loaded from the provided JSON-encoded reader

func (*AccountStore) Add added in v0.3.0

func (s *AccountStore) Add(account Account) error

Add pushes a new account into the store, fails if the account ID is already in use

func (*AccountStore) Find added in v0.3.0

func (s *AccountStore) Find(id string) (account Account, found bool)

Find returns the account with the given ID if it exists, otherwise found is false

func (*AccountStore) FindLedger added in v0.4.0

func (s *AccountStore) FindLedger(format *LedgerAccountFormat) (account Account, found bool)

FindLedger returns the account with the given ledger account string if it exists, otherwise found is false

func (*AccountStore) Iterate added in v0.3.0

func (s *AccountStore) Iterate(f func(Account) (keepGoing bool)) bool

Iterate ranges over the accounts in the store, running f on each one until it returns false Returns the last return value from f

func (*AccountStore) MarshalJSON added in v0.3.0

func (s *AccountStore) MarshalJSON() ([]byte, error)

MarshalJSON marshals into a sorted list of accounts

func (*AccountStore) MarshalWithPassword added in v0.3.0

func (s *AccountStore) MarshalWithPassword() ([]byte, error)

MarshalWithPassword marshals into a sorted list of accounts with their passwords. Only use this when persisting the accounts, never pass this back through an API call

func (*AccountStore) Remove added in v0.3.0

func (s *AccountStore) Remove(id string) error

Remove deletes the account from the store by ID

func (*AccountStore) UnmarshalJSON added in v0.3.0

func (s *AccountStore) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals from a list of accounts

func (*AccountStore) Update added in v0.3.0

func (s *AccountStore) Update(id string, account Account) error

Update replaces the account with a matching ID, fails if the account does not exist

type Bank

type Bank interface {
	Account

	BankID() string
}

Bank is an Account plus the Bank's routing number or 'Bank ID'. Common interface for Savings and Checking

type Checking

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

Checking represents a checking bank account

func (Checking) BankID

func (b Checking) BankID() string

func (Checking) MarshalJSON added in v0.3.0

func (c Checking) MarshalJSON() ([]byte, error)

MarshalJSON marshals a checking account

func (Checking) MarshalWithPassword added in v0.3.0

func (c Checking) MarshalWithPassword() ([]byte, error)

MarshalWithPassword marshals a checking account and includes the password

func (Checking) Statement

func (c Checking) Statement(start, end time.Time) (ofxgo.Request, error)

Statement fetches a statement for a checking account

func (*Checking) UnmarshalJSON added in v0.3.0

func (b *Checking) UnmarshalJSON(buf []byte) error

type Config

type Config struct {
	AppID      string
	AppVersion string
	ClientID   string `json:",omitempty"`
	OFXVersion string
	NoIndent   bool `json:",omitempty"`
}

Config contains financial institution connection details

type CreditCard

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

CreditCard represents a credit card account

func (CreditCard) Description

func (b CreditCard) Description() string

func (CreditCard) ID

func (b CreditCard) ID() string

func (CreditCard) Institution

func (b CreditCard) Institution() Institution

func (CreditCard) MarshalJSON added in v0.3.0

func (b CreditCard) MarshalJSON() ([]byte, error)

func (CreditCard) MarshalWithPassword added in v0.3.0

func (b CreditCard) MarshalWithPassword() ([]byte, error)

func (*CreditCard) Statement

func (cc *CreditCard) Statement(start, end time.Time) (ofxgo.Request, error)

func (*CreditCard) UnmarshalJSON added in v0.3.0

func (b *CreditCard) UnmarshalJSON(buf []byte) error

type Institution

type Institution interface {
	Description() string
	FID() string
	Org() string
	URL() string
	Username() string
	Password() *Password

	Config() Config
}

Institution represents the connection and identification details for a financial institution

func NewInstitution

func NewInstitution(
	description,
	fid,
	org,
	url,
	username, password string,
	config Config,
) Institution

NewInstitution creates an institution

type LedgerAccountFormat added in v0.4.0

type LedgerAccountFormat struct {
	AccountType string
	Institution string
	AccountID   string
	Remaining   string
}

LedgerAccountFormat represents an account's structured name for a ledger account format

func LedgerFormat added in v0.4.0

func LedgerFormat(a Account) *LedgerAccountFormat

LedgerFormat parses the account and returns a ledger account format

func ParseLedgerFormat added in v0.4.0

func ParseLedgerFormat(account string) (*LedgerAccountFormat, error)

ParseLedgerFormat parses the given account string as a ledger account

func (*LedgerAccountFormat) String added in v0.4.0

func (l *LedgerAccountFormat) String() string

type LocalClient added in v0.5.0

type LocalClient struct {
	ofxgo.Client
}

LocalClient enables insecure requests on localhost, provided that no passwords are involved

func (*LocalClient) MarshalRequest added in v0.5.0

func (l *LocalClient) MarshalRequest(r *ofxgo.Request) (io.Reader, error)

MarshalRequest implement the requestMarshaler interface to handle the special empty password case

func (*LocalClient) RawRequest added in v0.5.0

func (l *LocalClient) RawRequest(url string, r io.Reader) (*http.Response, error)

RawRequest runs a raw request for the given URL and reader against localhost. Errors if the host isn't for localhost OR a password field is included.

func (*LocalClient) Request added in v0.5.0

func (l *LocalClient) Request(r *ofxgo.Request) (*ofxgo.Response, error)

Request runs the given request and parses the result

func (*LocalClient) RequestNoParse added in v0.5.0

func (l *LocalClient) RequestNoParse(r *ofxgo.Request) (*http.Response, error)

RequestNoParse runs a raw request by marshalling the given request, returns the raw response

type Password added in v0.3.0

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

Password is a string that makes it hard to expose the underlying string outside this package Only JSON-serializes to 'null'

func NewPassword added in v0.3.0

func NewPassword(s string) *Password

NewPassword returns a password set to s

func (*Password) IsEmpty added in v0.3.0

func (p *Password) IsEmpty() bool

IsEmpty returns true if the internal password string is not set

func (*Password) MarshalJSON added in v0.3.0

func (p *Password) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON 'null' to prevent serialization within a struct

func (*Password) Set added in v0.3.0

func (p *Password) Set(newPassword *Password)

Set changes the password value to newPassword

func (*Password) UnmarshalJSON added in v0.3.0

func (p *Password) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes b into a password

type PasswordMarshaler added in v0.3.0

type PasswordMarshaler interface {
	MarshalWithPassword() ([]byte, error)
}

PasswordMarshaler includes a password in it's marshaled output of MarshalWithPassword

type Savings

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

Savings represents a savings bank account

func (Savings) BankID

func (b Savings) BankID() string

func (Savings) MarshalJSON added in v0.3.0

func (s Savings) MarshalJSON() ([]byte, error)

MarshalJSON marshals a savings account

func (Savings) MarshalWithPassword added in v0.3.0

func (s Savings) MarshalWithPassword() ([]byte, error)

MarshalWithPassword marshals a savings account and includes the password

func (Savings) Statement

func (s Savings) Statement(start, end time.Time) (ofxgo.Request, error)

Statement fetches a statement for a savings account

func (*Savings) UnmarshalJSON added in v0.3.0

func (b *Savings) UnmarshalJSON(buf []byte) error

Jump to

Keyboard shortcuts

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