whoop

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package whoop provides utilties for interfacing with the WHOOP API.

Index

Constants

This section is empty.

Variables

View Source
var Sports map[int]string = map[int]string{
	-1:  "Activity",
	0:   "Running",
	1:   "Cycling",
	16:  "Baseball",
	17:  "Basketball",
	18:  "Rowing",
	19:  "Fencing",
	20:  "Field Hockey",
	21:  "Football",
	22:  "Golf",
	24:  "Ice Hockey",
	25:  "Lacrosse",
	27:  "Rugby",
	28:  "Sailing",
	29:  "Skiing",
	30:  "Soccer",
	31:  "Softball",
	32:  "Squash",
	33:  "Swimming",
	34:  "Tennis",
	35:  "Track & Field",
	36:  "Volleyball",
	37:  "Water Polo",
	38:  "Wrestling",
	39:  "Boxing",
	42:  "Dance",
	43:  "Pilates",
	44:  "Yoga",
	45:  "Weightlifting",
	47:  "Cross Country Skiing",
	48:  "Functional Fitness",
	49:  "Duathlon",
	51:  "Gymnastics",
	52:  "Hiking/Rucking",
	53:  "Horseback Riding",
	55:  "Kayaking",
	56:  "Martial Arts",
	57:  "Mountain Biking",
	59:  "Powerlifting",
	60:  "Rock Climbing",
	61:  "Paddleboarding",
	62:  "Triathlon",
	63:  "Walking",
	64:  "Surfing",
	65:  "Elliptical",
	66:  "Stairmaster",
	70:  "Meditation",
	71:  "Other",
	73:  "Diving",
	74:  "Operations - Tactical",
	75:  "Operations - Medical",
	76:  "Operations - Flying",
	77:  "Operations - Water",
	82:  "Ultimate",
	83:  "Climber",
	84:  "Jumping Rope",
	85:  "Australian Football",
	86:  "Skateboarding",
	87:  "Coaching",
	88:  "Ice Bath",
	89:  "Commuting",
	90:  "Gaming",
	91:  "Snowboarding",
	92:  "Motocross",
	93:  "Caddying",
	94:  "Obstacle Course Racing",
	95:  "Motor Racing",
	96:  "HIIT",
	97:  "Spin",
	98:  "Jiu Jitsu",
	99:  "Manual Labor",
	100: "Cricket",
	101: "Pickleball",
	102: "Inline Skating",
	103: "Box Fitness",
	104: "Spikeball",
	105: "Wheelchair Pushing",
	106: "Paddle Tennis",
	107: "Barre",
	108: "Stage Performance",
	109: "High Stress Work",
	110: "Parkour",
	111: "Gaelic Football",
	112: "Hurling/Camogie",
	113: "Circus Arts",
	121: "Massage Therapy",
	125: "Watching Sports",
	126: "Assault Bike",
	127: "Kickboxing",
	128: "Stretching",
}

WHOOP sports mapping id to sport name

Functions

This section is empty.

Types

type BodyMeasurement

type BodyMeasurement struct {
	HeightMeter    float64 `json:"height_meter,omitempty"`    // User's height in meters.
	WeightKilogram float64 `json:"weight_kilogram,omitempty"` // User's weight in kilograms.
	MaxHeartRate   int     `json:"max_heart_rate,omitempty"`  // The max heart rate WHOOP calculated for the user.
}

Body measurements about the user, such as their weight and height.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/user#body-measurements

type Client

type Client struct {

	// Services used for talking to different parts of the API.
	Cycle    *CycleService
	Recovery *RecoveryService
	Sleep    *SleepService
	User     *UserService
	Workout  *WorkoutService
	// contains filtered or unexported fields
}

Client manages communication with the WHOOP API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new WHOOP API client. If a nil httpClient is provided, a new http.Client will be used.

To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

type Cycle

type Cycle struct {
	ID     int `json:"id"`      // Unique identifier for the physiological cycle.
	UserID int `json:"user_id"` // The User for the physiological cycle.

	CreatedAt *time.Time `json:"created_at,omitempty"` // Time the cycle was recorded.
	UpdatedAt *time.Time `json:"updated_at,omitempty"` // Time the cycle was last updated.
	Start     *time.Time `json:"start,omitempty"`      // Start time bound of the cycle.
	End       *time.Time `json:"end,omitempty"`        // End time bound of the cycle. If not present, the user is currently in this cycle.

	TimezoneOffset *string `json:"timezone_offset,omitempty"` // Timezone offset at the time the cycle was recorded.
	ScoreState     *string `json:"score_state,omitempty"`     // "SCORED", "PENDING_SCORE", or "UNSCORABLE".

	Score struct {
		Strain           float64 `json:"strain,omitempty"`             // Level of strain for the user. Scored from 0 to 21.
		Kilojoule        float64 `json:"kilojoule,omitempty"`          // Kilojoules the user expended during the cycle.
		AverageHeartRate float64 `json:"average_heart_rate,omitempty"` // The user's average heart rate during the cycle.
		MaxHeartRate     float64 `json:"max_heart_rate,omitempty"`     // The user's max heart rate during the cycle.
	} `json:"score,omitempty"`
}

Cycle represents a member's activity in the context of a Physiological Cycle.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/cycle

type CycleListAllResp

type CycleListAllResp struct {
	Records   []Cycle `json:"records"`
	NextToken *string `json:"next_token"`
}

type CycleService

type CycleService service

CycleService handles communication with the Cycle related endpoints of the API.

func (*CycleService) GetOne

func (s *CycleService) GetOne(ctx context.Context, id int) (*Cycle, error)

GetOne retrieves a single physiological cycle record for the specified id.

WHOOP API docs: https://developer.whoop.com/api#tag/Cycle/operation/getCycleById

func (*CycleService) ListAll

func (s *CycleService) ListAll(ctx context.Context, params *RequestParams) (*CycleListAllResp, error)

ListAll lists all physiological cycle records for the authenticated user. Results are paginated and sorted by start time in descending order.

WHOOP API docs: https://developer.whoop.com/api#tag/Cycle/operation/getCycleCollection

type Error

type Error struct {
	Code    int    `json:"code"`    // The HTTP status code.
	Message string `json:"message"` // A short description of the error.
}

Error represents an error returned by the WHOOP API.

func (*Error) Error

func (r *Error) Error() string

type Rate

type Rate struct {
	// The number of remaining requests the client can make within the time window.
	// https://developer.whoop.com/docs/developing/rate-limiting#x-ratelimit-remaining
	Remaining int `json:"remaining"`

	// The time at which the current rate limit will reset.
	Reset time.Time `json:"reset"`
}

Rate represents the rate limit for the current client. After an API key's rate limit has been reached or exceeded, the API will respond with a 429 - Too Many Requests HTTP status code.

For more details on how the API handles rate limits https://developer.whoop.com/docs/developing/rate-limiting#rate-limit-information

type RateLimitError

type RateLimitError struct {
	Rate     Rate           // Rate specifies last known rate limit for the client
	Response *http.Response // HTTP response that caused the error
	Message  string         `json:"message"`
}

RateLimitError occurs when the API returns 429 Too Many Requests response with a rate limit remaining value of 0.

func (*RateLimitError) Error

func (r *RateLimitError) Error() string

func (*RateLimitError) Is

func (r *RateLimitError) Is(target error) bool

Is returns whether the provided error equals this error.

type Recovery

type Recovery struct {
	CycleID int `json:"cycle_id"` // Unique identifier for the sleep activity.
	SleepID int `json:"sleep_id"` // ID of the Sleep associated with the Recovery.
	UserID  int `json:"user_id"`  // The User for the recovery.

	CreatedAt *time.Time `json:"created_at,omitempty"` // Time the recovery was recorded.
	UpdatedAt *time.Time `json:"updated_at,omitempty"` // Time the recovery was last updated.

	ScoreState *string `json:"score_state,omitempty"` // "SCORED", "PENDING_SCORE", or "UNSCORABLE".

	Score struct {
		UserCalibrating  bool    `json:"user_calibrating,omitempty"`   // True if user is calibrating.
		RecoveryScore    float64 `json:"recovery_score,omitempty"`     // Percentage that reflects how well prepared the user's body is to take on Strain.
		RestingHeartRate float64 `json:"resting_heart_rate,omitempty"` // User's resting heart rate.
		HrvRmssdMilli    float64 `json:"hrv_rmssd_milli,omitempty"`    // User's heart rate variability in milliseconds.
		Spo2Percentage   float64 `json:"spo2_percentage,omitempty"`    // Percentage of oxygen in the user's blood.
		SkinTempCelsius  float64 `json:"skin_temp_celsius,omitempty"`  // Skin temperature, in Celsius.
	} `json:"score,omitempty"`
}

Recovery represents a member's recovery score in the context of a Physiological Cycle.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/recovery

type RecoveryListAllResp

type RecoveryListAllResp struct {
	Records   []Recovery `json:"records"`
	NextToken *string    `json:"next_token"`
}

type RecoveryService

type RecoveryService service

RecoveryService handles communication with the Reovery related endpoints of the API.

func (*RecoveryService) GetOneByCycleId

func (s *RecoveryService) GetOneByCycleId(ctx context.Context, id int) (*Recovery, error)

GetOneByCycleId retrieves a single recovery record for the specified cycle id.

WHOOP API docs: https://developer.whoop.com/api#tag/Cycle/operation/getCycleById

func (*RecoveryService) ListAll

ListAll lists all recovery records for the authenticated user. Results are paginated and sorted by start time in descending order.

WHOOP API docs: https://developer.whoop.com/api#tag/Recovery/operation/getRecoveryCollection

type RequestParams

type RequestParams struct {
	Start     time.Time // Start time query filter
	End       time.Time // End time query filter
	NextToken string    // Token to retrieve next page of records if any
	Limit     int       // Limit the number of records returned by the API
}

RequestParams represents a GET requests query parameters

type Response

type Response struct {
	*http.Response

	// The WHOOP API implements pagination through cursors.
	// This means that a token points directly to the next set of records.
	// For more details check https://developer.whoop.com/docs/developing/pagination
	NextPageToken string

	Rate Rate
}

Response is a WHOOP API response. This wraps the standard http.Response returned from the API and provides convenient access to things like pagination tokens and rate limits.

type Sleep

type Sleep struct {
	ID     int `json:"id"`      // Unique identifier for the sleep activity
	UserID int `json:"user_id"` // User who performed the sleep activity

	CreatedAt *time.Time `json:"created_at,omitempty"` // Time the sleep was recorded.
	UpdatedAt *time.Time `json:"updated_at,omitempty"` // Time the sleep was last updated.
	Start     *time.Time `json:"start,omitempty"`      // Start time bound of the sleep.
	End       *time.Time `json:"end,omitempty"`        // End time bound of the sleep.

	TimezoneOffset *string `json:"timezone_offset,omitempty"` // // Timezone offset at the time the sleep was recorded.
	Nap            bool    `json:"nap,omitempty"`             // If true, this sleep activity was a nap for the user.
	ScoreState     *string `json:"score_state,omitempty"`     // "SCORED", "PENDING_SCORE", or "UNSCORABLE".

	Score struct {
		StageSummary struct {
			TotalInBedTimeMilli         int `json:"total_in_bed_time_milli,omitempty"`          // Total time the user spent in bed, in milliseconds.
			TotalAwakeTimeMilli         int `json:"total_awake_time_milli,omitempty"`           // Total time the user spent awake, in milliseconds.
			TotalNoDataTimeMilli        int `json:"total_no_data_time_milli,omitempty"`         // Total time WHOOP did not receive data from the user during the sleep, in milliseconds.
			TotalLightSleepTimeMilli    int `json:"total_light_sleep_time_milli,omitempty"`     // Total time the user spent in light sleep, in milliseconds.
			TotalSlowWaveSleepTimeMilli int `json:"total_slow_wave_sleep_time_milli,omitempty"` // Total time the user spent in Slow Wave Sleep, in milliseconds.
			TotalRemSleepTimeMilli      int `json:"total_rem_sleep_time_milli,omitempty"`       // Total time the user spent in Rapid Eye Movement (REM) sleep, in milliseconds.
			SleepCycleCount             int `json:"sleep_cycle_count,omitempty"`                // Number of sleep cycles during the user's sleep.
			DisturbanceCount            int `json:"disturbance_count,omitempty"`                // Number of times the user was disturbed during sleep
		} `json:"stage_summary,omitempty"`
		SleepNeeded struct {
			BaselineMilli             int `json:"baseline_milli,omitempty"`                // Amount of sleep a user needed based on historical trends.
			NeedFromSleepDebtMilli    int `json:"need_from_sleep_debt_milli,omitempty"`    // Difference between the amount of sleep the user's body required and the amount the user actually got.
			NeedFromRecentStrainMilli int `json:"need_from_recent_strain_milli,omitempty"` // Additional sleep need accrued based on the user's strain.
			NeedFromRecentNapMilli    int `json:"need_from_recent_nap_milli,omitempty"`    // Reduction in sleep need accrued based on the user's recent nap activity (negative value or zero).
		} `json:"sleep_needed,omitempty"`
		RespiratoryRate            float64 `json:"respiratory_rate,omitempty"`             // User's respiratory rate during the sleep.
		SleepPerformancePercentage float64 `json:"sleep_performance_percentage,omitempty"` // Percentage of time user is asleep over the amount of sleep the user needed.
		SleepConsistencyPercentage float64 `json:"sleep_consistency_percentage,omitempty"` // Percentage of how similar this sleep and wake times compared to the previous day.
		SleepEfficiencyPercentage  float64 `json:"sleep_efficiency_percentage,omitempty"`  // Percentage of time user spends in bed that user is actually asleep.
	} `json:"score,omitempty"`
}

Sleep represents a sleep performance for a given user.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/sleep

type SleepListAllResp

type SleepListAllResp struct {
	Records   []Sleep `json:"records"`
	NextToken *string `json:"next_token"`
}

type SleepService

type SleepService service

SleepService handles communication with the Sleep related endpoints of the API.

func (*SleepService) GetOne

func (s *SleepService) GetOne(ctx context.Context, id int) (*Sleep, error)

GetOne retrieves a single sleep record for the specified id.

WHOOP API docs: https://developer.whoop.com/api#tag/Sleep/operation/getSleepById

func (*SleepService) ListAll

func (s *SleepService) ListAll(ctx context.Context, params *RequestParams) (*SleepListAllResp, error)

ListAll lists all sleep records for the authenticated user. Results are paginated and sorted by start time in descending order.

WHOOP API docs: https://developer.whoop.com/api#tag/Sleep/operation/getSleepCollection

type UserProfile

type UserProfile struct {
	ID        int     `json:"user_id"`              // The WHOOP User.
	Email     *string `json:"email,omitempty"`      // User's Email.
	FirstName *string `json:"first_name,omitempty"` // User's First Name.
	LastName  *string `json:"last_name,omitempty"`  // User's Last Name
}

UserProfile represents a member's user profile.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/user

type UserService

type UserService service

UserService handles communication with the User related endpoints of the API.

func (*UserService) GetBodyMeasurement

func (s *UserService) GetBodyMeasurement(ctx context.Context) (*BodyMeasurement, error)

GetBodyMeasurement retrieves the body measurements for the authenticated user.

WHOOP API docs: https://developer.whoop.com/api#tag/User/operation/getBodyMeasurement

func (*UserService) GetProfile

func (s *UserService) GetProfile(ctx context.Context) (*UserProfile, error)

GetProfile retrieves the profile for the authenticated user.

WHOOP API docs: https://developer.whoop.com/api#tag/User/operation/getProfileBasic

type Workout

type Workout struct {
	ID     int `json:"id"`      // Unique identifier for the workout activity.
	UserID int `json:"user_id"` // The User for the workout activity.

	CreatedAt *time.Time `json:"created_at,omitempty"` // Time the workout was recorded.
	UpdatedAt *time.Time `json:"updated_at,omitempty"` // Time the workout was last updated.
	Start     *time.Time `json:"start,omitempty"`      // Start time bound of the workout.
	End       *time.Time `json:"end,omitempty"`        // End time bound of the workout.

	TimezoneOffset *string `json:"timezone_offset,omitempty"` // // Timezone offset at the time the workout was recorded.
	SportID        int     `json:"sport_id,omitempty"`        // ID of the Sport performed during the workout
	SportName      *string `json:"sport_name,omitempty"`      // Name of the WHOOP Sport performed during the workout
	ScoreState     *string `json:"score_state,omitempty"`     // "SCORED", "PENDING_SCORE", or "UNSCORABLE".

	Score struct {
		Strain              float64 `json:"strain,omitempty"`                // Level of strain of the workout. Scored from 0 to 21.
		AverageHeartRate    int     `json:"average_heart_rate,omitempty"`    // User's average heart rate during the workout.
		MaxHeartRate        int     `json:"max_heart_rate,omitempty"`        // User's max heart rate during the workout.
		Kilojoule           float64 `json:"kilojoule,omitempty"`             // Kilojoules expended during the workout.
		PercentRecorded     float64 `json:"percent_recorded,omitempty"`      // Percentage of heart rate recorded during the workout.
		DistanceMeter       float64 `json:"distance_meter,omitempty"`        // Distance travelled during the workout.
		AltitudeGainMeter   float64 `json:"altitude_gain_meter,omitempty"`   // Altitude gained during the workout.
		AltitudeChangeMeter float64 `json:"altitude_change_meter,omitempty"` // Altitude difference between start and end points of the workout.

		ZoneDuration struct {
			ZoneZeroMilli  int `json:"zone_zero_milli,omitempty"`  // Time spent with Heart Rate lower than Zone One [0-50%).
			ZoneOneMilli   int `json:"zone_one_milli,omitempty"`   // Time spent in Heart Rate Zone One [50-60%)
			ZoneTwoMilli   int `json:"zone_two_milli,omitempty"`   // Time spent in Heart Rate Zone Two [60-70%).
			ZoneThreeMilli int `json:"zone_three_milli,omitempty"` // Time spent in Heart Rate Zone Three [70-80%).
			ZoneFourMilli  int `json:"zone_four_milli,omitempty"`  // Time spent in Heart Rate Zone Four [80-90%).
			ZoneFiveMilli  int `json:"zone_five_milli,omitempty"`  // Time spent in Heart Rate Zone Five [90-100%).
		} `json:"zone_duration,omitempty"`
	} `json:"score,omitempty"`
}

Workout represents a workout activity for a given user.

WHOOP API docs: https://developer.whoop.com/docs/developing/user-data/workout

type WorkoutListAllResp

type WorkoutListAllResp struct {
	Records   []Workout `json:"records"`
	NextToken *string   `json:"next_token"`
}

type WorkoutService

type WorkoutService service

WorkoutService handles communication with the Workout related endpoints of the API.

func (*WorkoutService) GetOne

func (s *WorkoutService) GetOne(ctx context.Context, id int) (*Workout, error)

GetOne retrieves a single workout record for the specified id.

WHOOP API docs: https://developer.whoop.com/api#tag/Workout/operation/getWorkoutById

func (*WorkoutService) ListAll

func (s *WorkoutService) ListAll(ctx context.Context, params *RequestParams) (*WorkoutListAllResp, error)

ListAll lists all workout records for the authenticated user. Results are paginated and sorted by start time in descending order.

WHOOP API docs: https://developer.whoop.com/api#tag/Workout/operation/getWorkoutCollection

Jump to

Keyboard shortcuts

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