plan

package module
v0.0.0-...-a5508f6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingEmail        = errors.New("missing Email")
	ErrMissingProductName  = errors.New("missing product Name")
	ErrMissingProductPrice = errors.New("missing product Price")
	ErrMissingProductURL   = errors.New("missing product URL")
)
View Source
var (
	ErrInvalidFrequency    = errors.New("invalid contribution frequency")
	ErrInvalidAvailability = errors.New("invalid availability calculator")
)

Functions

func Process

func Process(u *User) error

func ProcessDefaults

func ProcessDefaults(u *User) error

func ProcessLastPaycheck

func ProcessLastPaycheck(u *User) error

func ProcessProducts

func ProcessProducts(u *User) error

func ProcessPurchaseAvailability

func ProcessPurchaseAvailability(u *User) error

func ProcessSaved

func ProcessSaved(u *User) error

func ProcessValidation

func ProcessValidation(u *User) error

Types

type AmazonPAPIParser

type AmazonPAPIParser struct {
	URL  string
	Body []byte
	// contains filtered or unexported fields
}

AmazonPAPIParser parses amazon.com links with their Product API.

func (AmazonPAPIParser) Product

func (parser AmazonPAPIParser) Product(ctx context.Context) (Product, error)

type AmazonParser

type AmazonParser struct {
	URL  string
	Body []byte
}

AmazonParser is made specifically for parsing Amazon.com

func (AmazonParser) Product

func (parser AmazonParser) Product(_ context.Context) (Product, error)

Product parses amazon.com html for product information.

type BiWeekly

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

func (BiWeekly) LastPaycheck

func (w BiWeekly) LastPaycheck() (*time.Time, error)

func (BiWeekly) PurchaseDate

func (w BiWeekly) PurchaseDate(p *Purchase) (*time.Time, error)

func (BiWeekly) Saved

func (w BiWeekly) Saved() (int64, error)

type Budget

type Budget struct {
	ID           string
	View         BudgetView
	Start        time.Time
	End          time.Time
	Categories   []Category
	Transactions []Transaction
}

type BudgetView

type BudgetView int

type Category

type Category struct {
	ID    string
	Name  string
	Group string
	Type  CategoryType
	// PlannedInCents represents the planned amount * 100 (12.50 === 1250)
	// This helps avoid floating point issues with float64.
	PlannedInCents int64
}

type CategoryType

type CategoryType string

type DefaultParser

type DefaultParser struct {
	AmazonPAPIParser AmazonPAPIParser
	AmazonParser     AmazonParser
	SchemaOrgParser  SchemaOrgParser
	OpenGraphParser  OpenGraphParser
	HTMLParser       HTMLParser
	MetaTagParser    MetaTagParser
}

DefaultParser combines the above parsers in a single convenient parser.

func NewDefaultParser

func NewDefaultParser(url string, body []byte, c config.C) DefaultParser

NewDefaultParser creates a new parser than combines other parsers.

func (DefaultParser) Product

func (parser DefaultParser) Product(ctx context.Context) (Product, error)

Product returns the result of combining other Producters.

type Frequency

type Frequency interface {
	Saved() (int64, error)
	LastPaycheck() (*time.Time, error)
	PurchaseDate(*Purchase) (*time.Time, error)
}

func NewFrequency

func NewFrequency(u *User) (Frequency, error)

type HTMLParser

type HTMLParser struct {
	URL  string
	Body []byte
}

HTMLParser looks through the HTML for certain values. It's not very accurate but can make a last-ditch attempt.

func (HTMLParser) Product

func (parser HTMLParser) Product(_ context.Context) (Product, error)

Product parses the HTML for a product.

type Merchant

type Merchant struct {
	Name string
}

type MetaTagParser

type MetaTagParser struct {
	URL  string
	Body []byte
}

MetaTagParser is more accurate than HTMLParser but will not be able to gather all info.

func (MetaTagParser) Product

func (parser MetaTagParser) Product(_ context.Context) (Product, error)

Product parses meta tags for product information.

type Monthly

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

func (Monthly) LastPaycheck

func (w Monthly) LastPaycheck() (*time.Time, error)

func (Monthly) PurchaseDate

func (w Monthly) PurchaseDate(p *Purchase) (*time.Time, error)

func (Monthly) Saved

func (w Monthly) Saved() (int64, error)

type OpenGraphParser

type OpenGraphParser struct {
	URL  string
	Body []byte
}

OpenGraphParser is generally very accurate but pricing is not used widely.

func (OpenGraphParser) Product

func (parser OpenGraphParser) Product(_ context.Context) (Product, error)

Product parses opengraph meta tags for product information.

type PAPIRequest

type PAPIRequest struct {
	ItemIds     []string
	PartnerTag  string
	PartnerType string
	Marketplace string
	Operation   string
	Resources   []string
}

type PAPIResponse

type PAPIResponse struct {
	Errors []struct {
		Message string
	}
	ItemsResult struct {
		Items []struct {
			DetailPageURL string
			ItemInfo      struct {
				Title struct {
					DisplayValue string
				}
			}
			Offers struct {
				Listings []struct {
					Price struct {
						Amount float64
					}
				}
			}
			Images struct {
				Primary struct {
					Large struct {
						URL string
					}
				}
			}
		}
	}
}

type Processor

type Processor func(*User) error

type Product

type Product struct {
	Name          string `datastore:",noindex" json:"name"`
	Description   string `datastore:",noindex" json:"description"`
	Price         int64  `json:"price"`
	URL           string `datastore:",noindex" json:"url"`
	AffiliateURL  string `datastore:",noindex" json:"affiliateURL"`
	Image         string `datastore:",noindex" json:"image"`
	OriginalImage string `datastore:",noindex" json:"originalImage"`
}

Product contains information about the thing a User wants to buy.

func (Product) Normalize

func (p Product) Normalize(requestURL string) (Product, error)

type Producter

type Producter interface {
	// Product returns a Product and an error.
	Product(ctx context.Context) (Product, error)
}

Producter is an interface for retrieving products.

type Purchase

type Purchase struct {
	ID          string     `json:"id"`
	Deleted     bool       `json:"deleted"`
	Purchased   bool       `json:"purchased"`
	PurchasedAt *time.Time `json:"purchasedAt"`
	Date        *time.Time `json:"date"`
	Product     Product    `json:"product"`
	Quantity    int64      `json:"quantity"`
	Notified    bool       `json:"notified"`
}

Purchase is something a User wants to buy.

func (Purchase) CanNotify

func (p Purchase) CanNotify() bool

type PushNotificationToken

type PushNotificationToken struct {
	// DeviceToken is the IOS or Android device's push notification token.
	DeviceToken string `datastore:",noindex" json:"deviceToken,omitempty"`
	// DeviceTokenType is "ios" or "android"
	DeviceTokenType string `datastore:",noindex" json:"deviceTokenType,omitempty"`
	// Expo token is used to send messages with expo's push notification service.
	ExpoToken string `datastore:",noindex" json:"expoToken,omitempty"`
}

PushNotificationToken is used to save a user's device and expo push tokens. It also stores the type of push token, which determines where to send manual push notifications to if expo notifications don't work.

type SchemaOrgParser

type SchemaOrgParser struct {
	URL  string
	Body []byte
}

SchemaOrgParser is VERY accurate because it's what is intended to be shown On search engines.

func (SchemaOrgParser) Product

func (parser SchemaOrgParser) Product(_ context.Context) (Product, error)

Product parses schema org JSON for data about a product.

type Tracking

type Tracking struct {
	// UserID, if available, is the ID of the current user
	UserID string
	// PageviewID is a random ID for the current page view
	PageViewID string
	// Type is the type of tracking, such as a view or a click
	Type string
	// Name is some human-readable name to inform which event is happening
	Name string
	// Time is when the tracking happened
	Time time.Time
	// URL is the URL where the tracking happened
	URL string
	// UserAgent is the User-Agent header set in the request
	UserAgent string
	// Host is the Host header set in the request
	Host string
	// Referer is the Referer header set in the request
	Referer string
	// Country is the country where the request originated
	Country string
	// Region is the region where the request originated (ex. CA = California in the US)
	Region string
	// Trace is the unique ID for the request
	Trace string
}

type Transaction

type Transaction struct {
	ID         string
	CategoryID string
	// AmountInCents represents the price * 100 (12.50 === 1250)
	// This helps avoid floating point issues with float64.
	AmountInCents int64
	Time          TransactionTime
	Merchant      Merchant
}

type TransactionTime

type TransactionTime struct {
	Created   time.Time
	Completed time.Time
}

type TwiceMonthly

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

func (TwiceMonthly) LastPaycheck

func (w TwiceMonthly) LastPaycheck() (*time.Time, error)

func (TwiceMonthly) PurchaseDate

func (w TwiceMonthly) PurchaseDate(p *Purchase) (*time.Time, error)

func (TwiceMonthly) Saved

func (w TwiceMonthly) Saved() (int64, error)

type User

type User struct {
	ID                     string                  `json:"id"`
	Issuer                 string                  `json:"issuer"`
	Email                  string                  `json:"email"`
	Saved                  int64                   `json:"saved,omitempty"`
	Contributions          int64                   `json:"contributions,omitempty"`
	Frequency              frequency               `json:"frequency,omitempty"`
	LastPaycheck           *time.Time              `json:"lastPaycheck,omitempty"`
	Purchases              []Purchase              `json:"purchases,omitempty"`
	PushNotificationTokens []PushNotificationToken `json:"pushNotificationTokens,omitempty"`
	Budgets                []Budget
}

User is the top level struct for, you guessed it, user data. The data is stored in an object database, so purchases Are stored as a property on the user, rather than by association.

type Weekly

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

func (Weekly) LastPaycheck

func (w Weekly) LastPaycheck() (*time.Time, error)

func (Weekly) PurchaseDate

func (w Weekly) PurchaseDate(p *Purchase) (*time.Time, error)

func (Weekly) Saved

func (w Weekly) Saved() (int64, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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