strengthlevel

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

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

View Source
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).

View Source
const DefaultBase = "https://my.strengthlevel.com"

DefaultBase is the Strength Level web app.

Provider is the provider's name: the first part of its kinds.

Variables

View Source
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) Add

Add creates the entry of one day. Body fat is left out when there is none.

func (*Client) List

func (c *Client) List(ctx context.Context) (map[string]Day, error)

List returns the existing entries by date.

func (*Client) Login

func (c *Client) Login(ctx context.Context, email, password string) error

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.

func (*Client) Update

func (c *Client) Update(ctx context.Context, old Day, e workerapi.ExportEntry) error

Update changes the existing entry of a day the way the web app's edit form does. The entry keeps its time zone, and keeps its body fat when e has none.

func (*Client) Upsert

func (c *Client) Upsert(ctx context.Context, e workerapi.ExportEntry) (Outcome, error)

Upsert adds the day, or updates it when it exists with other values.

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 Outcome

type Outcome string

Outcome is what Upsert did.

const (
	Added     Outcome = "added"
	Updated   Outcome = "updated"
	Unchanged Outcome = "unchanged"
)

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.

type Worker

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

Worker runs the Strength Level kinds of job. The user's login comes with each job and is used for that job only.

func New

func New(cfg Config, client *http.Client) *Worker

New returns a worker. A nil client gets a default one.

func (*Worker) Handlers

func (w *Worker) Handlers() map[string]runner.Handler

Handlers returns the handler of each kind, for runner.Runner.Handle.

Jump to

Keyboard shortcuts

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