whoop

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	RetryAfter time.Duration
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsRateLimited

func (e *APIError) IsRateLimited() bool

type BodyMeasurement

type BodyMeasurement struct {
	HeightMeter    float64 `json:"height_meter"`
	WeightKilogram float64 `json:"weight_kilogram"`
	MaxHeartRate   int     `json:"max_heart_rate"`
}

type Client

type Client struct {
	User     UserService
	Cycle    CycleService
	Recovery RecoveryService
	Sleep    SleepService
	Workout  WorkoutService
	// contains filtered or unexported fields
}

func New

func New(tokenSource oauth2.TokenSource, opts ...Option) *Client

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(apiKey string)

type Cycle

type Cycle struct {
	ID             int64       `json:"id"`
	UserID         int64       `json:"user_id"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	Start          time.Time   `json:"start"`
	End            *time.Time  `json:"end"`
	TimezoneOffset string      `json:"timezone_offset"`
	ScoreState     ScoreState  `json:"score_state"`
	Score          *CycleScore `json:"score"`
}

type CycleScore

type CycleScore struct {
	Strain           float64 `json:"strain"`
	Kilojoule        float64 `json:"kilojoule"`
	AverageHeartRate int     `json:"average_heart_rate"`
	MaxHeartRate     int     `json:"max_heart_rate"`
}

type CycleService

type CycleService interface {
	Get(ctx context.Context, id int64) (*Cycle, error)
	List(ctx context.Context, params *ListParams) (*PaginatedResponse[Cycle], error)
	GetSleep(ctx context.Context, cycleID int64) (*Sleep, error)
	GetRecovery(ctx context.Context, cycleID int64) (*Recovery, error)
}

type ListParams

type ListParams struct {
	Limit     int
	Start     *time.Time
	End       *time.Time
	NextToken *string
}

type Option

type Option func(*clientConfig)

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithLogger

func WithLogger(logger *slog.Logger) Option

func WithProxyURL

func WithProxyURL(baseURL string) Option

func WithSessionID

func WithSessionID(sessionID string) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Records   []T     `json:"records"`
	NextToken *string `json:"next_token,omitempty"`
}

func (*PaginatedResponse[T]) HasMore

func (p *PaginatedResponse[T]) HasMore() bool

type RateLimitInfo

type RateLimitInfo struct {
	Limit     int           // Requests allowed in current window
	Remaining int           // Requests remaining in current window
	Reset     time.Duration // Duration until the rate limit resets
}

RateLimitInfo contains parsed rate limit information from WHOOP API headers. See https://developer.whoop.com/docs/developing/rate-limiting/

func ParseRateLimitHeaders

func ParseRateLimitHeaders(headers http.Header) (*RateLimitInfo, error)

type Recovery

type Recovery struct {
	CycleID    int64          `json:"cycle_id"`
	SleepID    string         `json:"sleep_id"`
	UserID     int64          `json:"user_id"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
	ScoreState ScoreState     `json:"score_state"`
	Score      *RecoveryScore `json:"score"`
}

type RecoveryScore

type RecoveryScore struct {
	UserCalibrating  bool    `json:"user_calibrating"`
	RecoveryScore    float64 `json:"recovery_score"`
	RestingHeartRate float64 `json:"resting_heart_rate"`
	HRVRmssdMilli    float64 `json:"hrv_rmssd_milli"`
	SpO2Percentage   float64 `json:"spo2_percentage"`
	SkinTempCelsius  float64 `json:"skin_temp_celsius"`
}

type RecoveryService

type RecoveryService interface {
	List(ctx context.Context, params *ListParams) (*PaginatedResponse[Recovery], error)
}

type ScoreState

type ScoreState string
const (
	ScoreStateScored       ScoreState = "SCORED"
	ScoreStatePendingScore ScoreState = "PENDING_SCORE"
	ScoreStateUnscorable   ScoreState = "UNSCORABLE"
)

type Sleep

type Sleep struct {
	ID             string      `json:"id"`
	CycleID        int64       `json:"cycle_id"`
	V1ID           *int64      `json:"v1_id"`
	UserID         int64       `json:"user_id"`
	CreatedAt      time.Time   `json:"created_at"`
	UpdatedAt      time.Time   `json:"updated_at"`
	Start          time.Time   `json:"start"`
	End            time.Time   `json:"end"`
	TimezoneOffset string      `json:"timezone_offset"`
	Nap            bool        `json:"nap"`
	ScoreState     ScoreState  `json:"score_state"`
	Score          *SleepScore `json:"score"`
}

type SleepNeeded

type SleepNeeded struct {
	BaselineMilli             int `json:"baseline_milli"`
	NeedFromSleepDebtMilli    int `json:"need_from_sleep_debt_milli"`
	NeedFromRecentStrainMilli int `json:"need_from_recent_strain_milli"`
	NeedFromRecentNapMilli    int `json:"need_from_recent_nap_milli"`
}

type SleepScore

type SleepScore struct {
	StageSummary               SleepStages `json:"stage_summary"`
	SleepNeeded                SleepNeeded `json:"sleep_needed"`
	RespiratoryRate            float64     `json:"respiratory_rate"`
	SleepPerformancePercentage float64     `json:"sleep_performance_percentage"`
	SleepConsistencyPercentage float64     `json:"sleep_consistency_percentage"`
	SleepEfficiencyPercentage  float64     `json:"sleep_efficiency_percentage"`
}

type SleepService

type SleepService interface {
	Get(ctx context.Context, id string) (*Sleep, error)
	List(ctx context.Context, params *ListParams) (*PaginatedResponse[Sleep], error)
}

type SleepStages

type SleepStages struct {
	TotalInBedTimeMilli         int `json:"total_in_bed_time_milli"`
	TotalAwakeTimeMilli         int `json:"total_awake_time_milli"`
	TotalNoDataTimeMilli        int `json:"total_no_data_time_milli"`
	TotalLightSleepTimeMilli    int `json:"total_light_sleep_time_milli"`
	TotalSlowWaveSleepTimeMilli int `json:"total_slow_wave_sleep_time_milli"`
	TotalREMSleepTimeMilli      int `json:"total_rem_sleep_time_milli"`
	SleepCycleCount             int `json:"sleep_cycle_count"`
	DisturbanceCount            int `json:"disturbance_count"`
}

type UserProfile

type UserProfile struct {
	UserID    int64  `json:"user_id"`
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

type UserService

type UserService interface {
	GetProfile(ctx context.Context) (*UserProfile, error)
	GetBodyMeasurement(ctx context.Context) (*BodyMeasurement, error)
	RevokeAccess(ctx context.Context) error
}

type Workout

type Workout struct {
	ID             string        `json:"id"`
	V1ID           *int64        `json:"v1_id"`
	UserID         int64         `json:"user_id"`
	CreatedAt      time.Time     `json:"created_at"`
	UpdatedAt      time.Time     `json:"updated_at"`
	Start          time.Time     `json:"start"`
	End            time.Time     `json:"end"`
	TimezoneOffset string        `json:"timezone_offset"`
	SportName      string        `json:"sport_name"`
	ScoreState     ScoreState    `json:"score_state"`
	Score          *WorkoutScore `json:"score"`
}

type WorkoutScore

type WorkoutScore struct {
	Strain              float64      `json:"strain"`
	AverageHeartRate    int          `json:"average_heart_rate"`
	MaxHeartRate        int          `json:"max_heart_rate"`
	Kilojoule           float64      `json:"kilojoule"`
	PercentRecorded     float64      `json:"percent_recorded"`
	DistanceMeter       *float64     `json:"distance_meter"`
	AltitudeGainMeter   *float64     `json:"altitude_gain_meter"`
	AltitudeChangeMeter *float64     `json:"altitude_change_meter"`
	ZoneDurations       WorkoutZones `json:"zone_durations"`
}

type WorkoutService

type WorkoutService interface {
	Get(ctx context.Context, id string) (*Workout, error)
	List(ctx context.Context, params *ListParams) (*PaginatedResponse[Workout], error)
}

type WorkoutZones

type WorkoutZones struct {
	ZoneZeroMilli  int `json:"zone_zero_milli"`
	ZoneOneMilli   int `json:"zone_one_milli"`
	ZoneTwoMilli   int `json:"zone_two_milli"`
	ZoneThreeMilli int `json:"zone_three_milli"`
	ZoneFourMilli  int `json:"zone_four_milli"`
	ZoneFiveMilli  int `json:"zone_five_milli"`
}

Jump to

Keyboard shortcuts

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