Documentation ¶
Index ¶
- Constants
- Variables
- type CashbackConfig
- type Config
- type ConfigType
- type ConfigValue
- type Firefly
- func (f *Firefly) CreateTransaction(t *models.StoreTransactionRequest) (*models.UpsertTransactionResponse, error)
- func (f *Firefly) LinkTransactions(linkTypeID string, inwardID string, outwardID string) error
- func (f *Firefly) UpdateTransaction(id int, t *models.UpdateTransactionRequest) (*models.UpsertTransactionResponse, error)
- type FireflyOption
- type SplitTicketConfig
- type TransactionType
- type TransferConfig
- type WebhookMessage
- type WebhookMessageTransaction
- type WebhookResponse
- type WebhookTrigger
Constants ¶
const ( // Triggers STORE_TRANSACTION WebhookTrigger = "STORE_TRANSACTION" UPDATE_TRANSACTION WebhookTrigger = "UPDATE_TRANSACTION" DESTROY_TRANSACTION WebhookTrigger = "DESTROY_TRANSACTION" // Responses RESPONSE_TRANSACTIONS WebhookResponse = "TRANSACTIONS" RESPONSE_ACCOUNTS WebhookResponse = "ACCOUNTS" RESPONSE_NONE WebhookResponse = "NONE" )
const WEBHOOK_TAG_PREFIX = "Webhook:"
WEBHOOK_TAG_PREFIX is the prefix used for all tags we are going to attach to transactions.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CashbackConfig ¶ added in v1.2.0
type CashbackConfig struct { Trigger WebhookTrigger `json:"trigger"` Response WebhookResponse `json:"response"` Secret string `json:"secret"` Type TransactionType `json:"type"` Title string `json:"title"` SourceMustHaveTag string `json:"source_must_have_tag"` LinkTypeId string `json:"link_type_id"` SourceAccountId int `json:"source_account_id"` DepositSourceAccountId int `json:"deposit_source_account_id"` DestinationAccountId int `json:"destination_account_id"` Amount float64 `json:"amount"` CategoryID int `json:"category_id"` DestinationCurrencyId int `json:"destination_currency_id"` DestinationCurrencyDecimalPlaces int `json:"destination_currency_decimal_places"` }
CashbackConfig holds configuration for creating a cashback transaction.
func (CashbackConfig) AppliesTo ¶ added in v1.2.0
func (c CashbackConfig) AppliesTo(msg WebhookMessage) bool
AppliesTo checks if the configuration applies to the given message.
type Config ¶
type Config map[ConfigType][]ConfigValue
Config holds configuration regarding Firefly webhooks.
func ReadConfig ¶
ReadConfig reads the configuration from a JSON file.
func (*Config) FindConfig ¶
func (c *Config) FindConfig(t ConfigType, msg WebhookMessage) (ConfigValue, error)
FindConfig finds the configuration that applies to the given message.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON configuration file into the Config struct.
type ConfigType ¶
type ConfigType string
ConfigType is an enum listing all possible configuration types.
const ( SplitTicket ConfigType = "split_ticket" Cashback ConfigType = "cashback" Transfer ConfigType = "transfer" )
type ConfigValue ¶
type ConfigValue interface { // AppliesTo checks if the configuration applies to the given message. AppliesTo(msg WebhookMessage) bool }
type Firefly ¶
type Firefly struct {
// contains filtered or unexported fields
}
Firefly client used to interact with the Firefly III API.
func NewFirefly ¶
func NewFirefly(baseUrl string, opts ...FireflyOption) *Firefly
Create a new Firefly with the given configuration.
func (*Firefly) CreateTransaction ¶
func (f *Firefly) CreateTransaction(t *models.StoreTransactionRequest) (*models.UpsertTransactionResponse, error)
CreateTransaction will create a new transaction in Firefly III.
func (*Firefly) LinkTransactions ¶ added in v1.1.0
LinkTransactions will create a new link between two transactions in Firefly III.
func (*Firefly) UpdateTransaction ¶
func (f *Firefly) UpdateTransaction(id int, t *models.UpdateTransactionRequest) (*models.UpsertTransactionResponse, error)
UpdateTransaction will create a new transaction in Firefly III.
type FireflyOption ¶
type FireflyOption func(*fireflyOpts) error
FireflyOption is a function that updates the fireflyOpts struct.
func WithApiKey ¶
func WithApiKey(apiKey string) FireflyOption
WithApiKey is a configuration function that updates the api key used for each request.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) FireflyOption
WithTimeout is a configuration function that updates the client timeout.
type SplitTicketConfig ¶
type SplitTicketConfig struct { Trigger WebhookTrigger `json:"trigger"` Response WebhookResponse `json:"response"` Secret string `json:"secret"` Type TransactionType `json:"type"` LinkTypeId string `json:"link_type_id"` SourceAccountId int `json:"source_account_id"` DestinationAccountId int `json:"destination_account_id"` DestinationCurrencyId int `json:"destination_currency_id"` DestinationCurrencyDecimalPlaces int `json:"destination_currency_decimal_places"` SplitAmount float64 `json:"split_amount"` }
SplitTicketConfig holds configuration for splitting a transaction.
func (SplitTicketConfig) AppliesTo ¶
func (c SplitTicketConfig) AppliesTo(msg WebhookMessage) bool
AppliesTo checks if the configuration applies to the given message.
type TransactionType ¶
type TransactionType string
const ( WITHDRAWAL TransactionType = "withdrawal" DEPOSIT TransactionType = "deposit" TRANSFER TransactionType = "transfer" )
type TransferConfig ¶ added in v1.3.0
type TransferConfig struct { FixedAmount *float64 `json:"fixed_amount,omitempty"` ModuloAmount *float64 `json:"modulo_amount,omitempty"` LinkTypeId string `json:"link_type_id"` Secret string `json:"secret"` Type TransactionType `json:"type"` Title string `json:"title"` SourceMustHaveTag string `json:"source_must_have_tag"` Trigger WebhookTrigger `json:"trigger"` Response WebhookResponse `json:"response"` SourceAccountId int `json:"source_account_id"` DestinationAccountId int `json:"destination_account_id"` CategoryID int `json:"category_id"` DestinationCurrencyId int `json:"destination_currency_id"` DestinationCurrencyDecimalPlaces int `json:"destination_currency_decimal_places"` }
TransferConfig holds configuration for creating a transfer transaction.
func (TransferConfig) AppliesTo ¶ added in v1.3.0
func (c TransferConfig) AppliesTo(msg WebhookMessage) bool
AppliesTo checks if the configuration applies to the given message.
type WebhookMessage ¶
type WebhookMessage struct { RawContent json.RawMessage `json:"content"` Content interface{} `json:"-"` Uuid string `json:"uuid"` Trigger WebhookTrigger `json:"trigger"` Response WebhookResponse `json:"response"` Url string `json:"url"` Version string `json:"version"` UserId int `json:"user_id"` }
The UUID is unique for each webhook message. You can use it for debug purposes. The user ID matches the user who created the webhook, and the trigger + response fields tell you why the webhook was fired and what the content of the content field is.
func (*WebhookMessage) UnmarshalJSON ¶
func (msg *WebhookMessage) UnmarshalJSON(b []byte) error
func (*WebhookMessage) VerifySignature ¶
func (msg *WebhookMessage) VerifySignature(signatureHeader, body, secret string) error
verifySignature will check if the signature is valid for the current message. Signature example: t=1610738765,v1=d62463af1dcdcc7b5a2db6cf6b1e01d985c31685ee75d01a4f40754dbb4cf396
type WebhookMessageTransaction ¶
type WebhookMessageTransaction struct { Transactions []models.Transaction `json:"transactions"` ID int `json:"id"` User int `json:"user"` }
type WebhookResponse ¶
type WebhookResponse string
type WebhookTrigger ¶
type WebhookTrigger string