Documentation
¶
Overview ¶
Package strengthlevel is the worker for Strength Level. It talks to my.strengthlevel.com the way its own web app does: it signs in with an e-mail address and password and uses the app's JSON bodyweight endpoints. Strength Level publishes no API; use is by agreement with its developer, and only for the user's own account.
Days missing on Strength Level are added. An existing day is changed only by Update, by Upsert, or by Sync with Options.Update set. Nothing is ever deleted.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Add(ctx context.Context, e workerapi.ExportEntry) error
- func (c *Client) List(ctx context.Context) (map[string]Day, error)
- func (c *Client) Login(ctx context.Context, email, password string) error
- func (c *Client) Sync(ctx context.Context, local []workerapi.ExportEntry, since string, opt Options) (Result, error)
- func (c *Client) Update(ctx context.Context, old Day, e workerapi.ExportEntry) error
- func (c *Client) Upsert(ctx context.Context, e workerapi.ExportEntry) (Outcome, error)
- type Config
- type Day
- type Options
- type Outcome
- type Result
- type Worker
Constants ¶
const ( KindCheckLogin = Provider + "." + workerapi.ActionCheckLogin KindDay = Provider + "." + workerapi.ActionDay KindSync = Provider + "." + workerapi.ActionSync )
The kinds this worker runs. It plays the exporter role (see pkg/shared/workerapi).
const DefaultBase = "https://my.strengthlevel.com"
DefaultBase is the Strength Level web app.
const Provider = workerapi.ProviderStrengthLevel
Provider is the provider's name: the first part of its kinds.
Variables ¶
var ( // ErrLogin means Strength Level did not accept the e-mail address and password. ErrLogin = errors.New("strengthlevel: sign-in was refused, check the e-mail address and password") // ErrPage means a page did not have the shape this client expects, so Strength Level probably changed. ErrPage = errors.New("strengthlevel: unexpected page, the site may have changed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Delay is the pause between writes.
Delay time.Duration
// contains filtered or unexported fields
}
Client is one signed-in session. It is not safe for concurrent use.
func (*Client) Login ¶
Login signs in and reads the CSRF token and user id from the page Strength Level lands on.
func (*Client) Sync ¶
func (c *Client) Sync(ctx context.Context, local []workerapi.ExportEntry, since string, opt Options) (Result, error)
Sync writes the entries of local from the given day (YYYY-MM-DD, "" for all) on, oldest first. Days missing on Strength Level are added. Days that exist are left alone, or updated when opt.Update is set. Nothing is ever deleted. It stops at the first error that is not about a single day, such as a canceled context.
type Config ¶
type Config struct {
// Base is the address of Strength Level; empty means the real one.
Base string
}
Config holds what only a test changes.
type Day ¶
type Day struct {
ID string
Date string // YYYY-MM-DD
Weight float64
BodyFat *float64
FatMethod string
Timezone string
OffsetMins int
}
Day is an entry that already exists on Strength Level.
type Options ¶
type Options struct {
// Update also changes days that exist on Strength Level with other values. Without it they are
// left as they are.
Update bool
// Progress is called after each day of the period with the number done and the total.
Progress func(done, total int)
}
Options tune a sync.
type Result ¶
type Result struct {
Added, Updated, Skipped int
Failed []string // one message per day that could not be written
}
Result reports what a sync did.