nwlib

package module
v0.0.0-...-7582d03 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: MIT Imports: 21 Imported by: 2

README

lib

Shared Golang lib

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AWSRegion = GetEnv("AWS_REGION", "us-east-1")

AWSRegion default aws region

Functions

func ErrorResp

func ErrorResp(w http.ResponseWriter, message interface{})

ErrorResp error response helper for api

func GetEnv

func GetEnv(params ...string) string

GetEnv get environment variable with default fall back

func LoadAWSConfig

func LoadAWSConfig() aws.Config

LoadAWSConfig set default aws config

func PublishSNS

func PublishSNS(arn string, message string) error

PublishSNS publish message to SNS topic

func PublishSlack

func PublishSlack(webhook string, message string, channel string) error

PublishSlack publish message to Slack

func SuccessResp

func SuccessResp(w http.ResponseWriter, message interface{})

SuccessResp success response helper for api

func SyncAccounts

func SyncAccounts(plaidClient *PlaidClient, db *DynamoDBClient, token *Token) error

SyncAccounts - get latest accounts from Plaid

func SyncNetworth

func SyncNetworth(db *DynamoDBClient, username string) error

SyncNetworth save net worth to db for current datetime

Types

type APIResponse

type APIResponse struct {
	Data interface{} `json:"data"`
}

APIResponse api reponse

type Account

type Account struct {
	plaid.Account
	InstitutionID   string `json:"institution_id"`
	InstitutionName string `json:"institution_name"`
}

Account wrapper struct for plaid.Account

type DynamoDBClient

type DynamoDBClient struct {
	*dynamodb.DynamoDB
}

DynamoDBClient db client struct

func NewDynamoDBClient

func NewDynamoDBClient() *DynamoDBClient

NewDynamoDBClient new dynamodb client

func (DynamoDBClient) GetAccounts

func (d DynamoDBClient) GetAccounts(username string) ([]Account, error)

GetAccounts return all accounts from db for a username

func (DynamoDBClient) GetAllUsers

func (d DynamoDBClient) GetAllUsers() ([]Token, error)

GetAllUsers - get all users

func (DynamoDBClient) GetNetworth

func (d DynamoDBClient) GetNetworth(username string) (Networth, error)

GetNetworth return Networth struct

func (DynamoDBClient) GetNetworthByDateRange

func (d DynamoDBClient) GetNetworthByDateRange(username string, startDate string, endDate string) ([]Networth, error)

GetNetworthByDateRange return net worth based on date

func (DynamoDBClient) GetToken

func (d DynamoDBClient) GetToken(kms *KMSClient, username, itemID string) (Token, error)

� - return decrypted token based on username and item_id

func (DynamoDBClient) GetTokenByItemID

func (d DynamoDBClient) GetTokenByItemID(kms *KMSClient, itemID string) (Token, error)

GetTokenByItemID - return decrypted token based on item_id

func (DynamoDBClient) GetTokens

func (d DynamoDBClient) GetTokens(kms *KMSClient, username string) ([]Token, error)

GetTokens - return all tokens decrypted from db for a username

func (DynamoDBClient) GetTokensWithError

func (d DynamoDBClient) GetTokensWithError(username string) ([]Token, error)

GetTokensWithError - return all tokens with error

func (DynamoDBClient) GetTransactions

func (d DynamoDBClient) GetTransactions(username string, accountID string) ([]Transaction, error)

GetTransactions return all transactions from db for a username

func (DynamoDBClient) GetUsernameByItemID

func (d DynamoDBClient) GetUsernameByItemID(itemID string) (string, error)

GetUsernameByItemID - return username based on item_id

func (DynamoDBClient) SetAccount

func (d DynamoDBClient) SetAccount(token *Token, account *plaid.Account) error

SetAccount save account to db

func (DynamoDBClient) SetNetworth

func (d DynamoDBClient) SetNetworth(username string, networth float64, assets float64, liabilities float64) error

SetNetworth value as of today date and current timestamp

func (DynamoDBClient) SetToken

func (d DynamoDBClient) SetToken(username string, token *Token) error

SetToken save token to db

func (DynamoDBClient) SetTransaction

func (d DynamoDBClient) SetTransaction(username string, transaction plaid.Transaction) error

SetTransaction save transaction to db

func (DynamoDBClient) SetWebhook

func (d DynamoDBClient) SetWebhook(webhook Webhook) error

SetWebhook save webhook to db

func (DynamoDBClient) UpdateTokenError

func (d DynamoDBClient) UpdateTokenError(token *Token) error

UpdateTokenError update error field for token

type KMSClient

type KMSClient struct {
	*kms.KMS
}

KMSClient kms client struct

func NewKMSClient

func NewKMSClient() *KMSClient

NewKMSClient new instance of the kms client

func (KMSClient) Decrypt

func (k KMSClient) Decrypt(token string) (string, error)

Decrypt decrypt kms token

func (KMSClient) Encrypt

func (k KMSClient) Encrypt(token string) (string, error)

Encrypt key

type Networth

type Networth struct {
	Networth    float64 `json:"networth"`
	Assets      float64 `json:"assets"`
	Liabilities float64 `json:"liabilities"`
	DateTime    string  `json:"sort"`
	UpdatedAt   string  `json:"updated_at"`
}

Networth struct

type PlaidClient

type PlaidClient struct {
	*plaid.Client
}

PlaidClient plaid client

func NewPlaidClient

func NewPlaidClient(clientID string, secret string, publicKey string, environment string) *PlaidClient

NewPlaidClient new Plaid client

type SlackBody

type SlackBody struct {
	Text     string `json:"text"`
	Username string `json:"username"`
	IconURL  string `json:"icon_url"`
	Channel  string `json:"channel"`
}

SlackBody struct

type Token

type Token struct {
	ID              string   `json:"id"`
	Sort            string   `json:"sort"`
	ItemID          string   `json:"item_id"`
	AccessToken     string   `json:"access_token"`
	AccountID       string   `json:"account_id"`
	InstitutionID   string   `json:"institution_id"`
	InstitutionName string   `json:"institution_name"`
	Accounts        []string `json:"accounts"`
	Username        string   `json:"username"`
	Error           string   `json:"error"`
}

Token holds the structure single token

type Transaction

type Transaction struct {
	plaid.Transaction
}

Transaction struct

type Webhook

type Webhook struct {
	WebhookType         string       `json:"webhook_type"`         // "TRANSACTIONS",
	WebhookCode         string       `json:"webhook_code"`         // INITIAL_UPDATE HISTORICAL_UPDATE DEFAULT_UPDATE TRANSACTIONS_REMOVED
	ItemID              string       `json:"item_id"`              // "wz666MBjYWTp2PDzzggYhM6oWWmBb",
	Error               WebhookError `json:"error"`                // null,
	NewTransactions     int          `json:"new_transactions"`     //19
	RemovedTransactions []string     `json:"removed_transactions"` // ["yBVBEwrPyJs8GvR77N7QTxnGg6wG74H7dEDN6", "kgygNvAVPzSX9KkddNdWHaVGRVex1MHm3k9no"],
	Username            string       `json:"username"`
}

Webhook body

type WebhookError

type WebhookError struct {
	DisplayMessage string `json:"display_message"` //: "The provided credentials were not correct. Please try again.",
	ErrorCode      string `json:"error_code"`      //: "ITEM_LOGIN_REQUIRED",
	ErrorMessage   string `json:"error_message"`   //: "the provided credentials were not correct",
	ErrorType      string `json:"error_type"`      //: "ITEM_ERROR",
	Status         int    `json:"status"`          //: 400
}

WebhookError struct contains error fields from webhook

Jump to

Keyboard shortcuts

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