Documentation ¶
Index ¶
- Constants
- func CheckConfigFile(filePath string) (bool, string)
- func ConvertToExcel(userData User) ([]byte, error)
- func CreateHTTPClient() *http.Client
- func FormatTimeWithOffset(t time.Time, offsetStr string) string
- func GenerateLast24HoursString() (string, string)
- func GenerateStateOauthCookie() (string, error)
- func GetAccessToken(auth oauth2.Config, code string) (*oauth2.Token, error)
- func GetAuthURL(auth oauth2.Config, state string) string
- func GetCurrentDate() string
- func LogError(err error)
- func ReadTokenFromFile(filePath string) (oauth2.Token, error)
- func RefreshToken(ctx context.Context, auth AuthRequest) (oauth2.Token, error)
- func VerfyToken(filePath string) (bool, oauth2.Token, error)
- func WriteLocalToken(filePath string, token *oauth2.Token) error
- type AuthCredentials
- type AuthRequest
- type ConfigExport
- type ConfigurationData
- type Credentials
- type CycleCollection
- type CycleRecords
- type CycleScore
- type Event
- type Export
- type Notification
- type NotificationConfig
- type RecoveryCollection
- type RecoveryRecords
- type RecoveryScore
- type Score
- type Server
- type SleepCollection
- type SleepCollectionRecords
- type SleepNeeded
- type StageSummary
- type User
- func (u User) GetCycleCollection(ctx context.Context, client *http.Client, url, authToken, filters, ua string) (*CycleCollection, error)
- func (u User) GetRecoveryCollection(ctx context.Context, client *http.Client, url, authToken, filters, ua string) (*RecoveryCollection, error)
- func (u User) GetSleepCollection(ctx context.Context, client *http.Client, url, authToken, filters, ua string) (*SleepCollection, error)
- func (u User) GetUserMeasurements(ctx context.Context, client *http.Client, url, authToken, ua string) (*UserMesaurements, error)
- func (u User) GetUserProfileData(ctx context.Context, client *http.Client, url, authToken, ua string) (*UserData, error)
- func (u User) GetWorkoutCollection(ctx context.Context, client *http.Client, url, authToken, filters, ua string) (*WorkoutCollection, error)
- type UserData
- type UserMesaurements
- type WorkoutCollection
- type WorkoutRecords
- type WorkoutScore
- type ZoneDuration
Constants ¶
const ( // AccessTokenURL is the URL to get an access token from the Whoop API DEFAULT_ACCESS_TOKEN_URL string = "https://api.prod.whoop.com/oauth/oauth2/token" // AuthURL is the URL to authenticate with the Whoop API DEFAULT_AUTHENTICATION_URL string = "https://api.prod.whoop.com/oauth/oauth2/auth" // DEFAULT_REDIRECT_URL is the URL to redirect to after authentication DEFAULT_REDIRECT_URL string = "http://localhost:8080/oauth/redirect" // DEFAULT_CREDENTIALS_FILE is the default file to store the credentials DEFAULT_CREDENTIALS_FILE string = "token.json" // DEFAULT_CONFIG_FILE is the default file to store the configuration DEFAULT_CONFIG_FILE string = ".mywhoop.yaml" // Retry/Backoff constants DEFAULT_RETRY_MAX_ELAPSED_TIME time.Duration = 5 * time.Minute DEFAULT_RETRY_MULTIPLIER float64 = 1.5 DEFAULT_RETRY_RANDOMIZATION float64 = 0.5 DEFAULT_RETRY_INITIAL_INTERVAL time.Duration = 500 * time.Millisecond // DEFAULT_WHOOP_API_USER_DATA_URL is the URL to get the user data from the Whoop API DEFAULT_WHOOP_API_USER_DATA_URL = "https://api.prod.whoop.com/developer/v1/user/profile/basic" // DEFAULT_WHOOP_API_USER_MEASUREMENT_DATA_URL is the URL to get the user measurement data from the Whoop API DEFAULT_WHOOP_API_USER_MEASUREMENT_DATA_URL = "https://api.prod.whoop.com/developer/v1/user/measurement/body" // DEFAULT_WHOOP_API_USER_SLEEP_DATA_URL is the URL to get the user sleep data from the Whoop API DEFAULT_WHOOP_API_USER_SLEEP_DATA_URL = "https://api.prod.whoop.com/developer/v1/activity/sleep?" // DEFAULT_WHOPP_API_RECOVERY_DATA_URL is the URL to get the user recovery data from the Whoop API DEFAULT_WHOOP_API_RECOVERY_DATA_URL = "https://api.prod.whoop.com/developer/v1/recovery?" //DEFAULT_WHOPP_API_WORKOUT_DATA_URL is the URL to get the user workout data from the Whoop API DEFAULT_WHOOP_API_WORKOUT_DATA_URL = "https://api.prod.whoop.com/developer/v1/activity/workout?" // DEFAULT_WHOOP_API_CYCLE_DATA_URL is the URL to get the user cycle data from the Whoop API DEFAULT_WHOOP_API_CYCLE_DATA_URL = "https://api.prod.whoop.com/developer/v1/cycle?" // DEFAULT_SERVER_CRON_SCHEDULE is the default cron schedule for the server. Everyday at 1:00 PM OR 1300 hours. DEFAULT_SERVER_CRON_SCHEDULE string = "0 13 * * *" // DEFAULT_SERVER_TOKEN_REFRESH_CRON_SCHEDULE is the default cron schedule for the token refresh. Every 45 minutes. DEFAULT_SERVER_TOKEN_REFRESH_CRON_SCHEDULE time.Duration = 45 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func CheckConfigFile ¶
func ConvertToExcel ¶ added in v0.1.1
ConvertToExcel converts the user data to a temporary CSV file
func CreateHTTPClient ¶
createHTTPClient creates an HTTP client with TLS
func FormatTimeWithOffset ¶ added in v0.1.1
FormatTimeWithOffset formats a time.Time object with a given offset string The offset string should be in the format "+HH:MM" or "-HH:MM"
func GenerateLast24HoursString ¶
GenerateLast24HoursString generates a string that represents the last 24 hours Used for querying the Whoop API with a filter string
func GenerateStateOauthCookie ¶ added in v0.1.2
GenerateStateOauthCookie generates a random state string
func GetAccessToken ¶ added in v0.0.4
GetAccessToken exchanges the access code returned from the authorization flow for an access token
func GetAuthURL ¶ added in v0.0.4
GetAuthURL returns the URL to authenticate with the Whoop API
func GetCurrentDate ¶
func GetCurrentDate() string
getCurrentDate returns the current date in the format "YYYY-MM-DD"
func LogError ¶
func LogError(err error)
LogError logs the error and the file, line, and function where the error occurred
func ReadTokenFromFile ¶
readTokenFromFile reads a token from a file and returns it as an oauth2.Token
func RefreshToken ¶
RefreshToken refreshes the access token
func VerfyToken ¶
VerifyToken validates that the file containing the Whoop autentication token is valid.
Types ¶
type AuthCredentials ¶
type AuthRequest ¶
type AuthRequest struct { // Authorization URL for the Whoop API AuthorizationURL string // AuthToken is the OAuth2 token for the Whoop API AuthToken string // RefreshToken is the OAuth2 refresh token for the Whoop API RefreshToken string // client is the HTTP client to use for making requests Client *http.Client // The client ID for the Whoop API ClientID string // The client secret for the Whoop API ClientSecret string //Token URL for the Whoop API TokenURL string }
type ConfigExport ¶
type ConfigExport struct { Method string `yaml:"method" validate:"oneof=file s3"` FileExport export.FileExport `yaml:"fileExport" validate:"required_if=Method file"` AWSS3 export.AWS_S3 `yaml:"awsS3" validate:"required_if=Method s3"` }
type ConfigurationData ¶
type ConfigurationData struct { // Credentials is the configuration settings for Whoop API authentication credentials Credentials Credentials `yaml:"credentials"` // Debug flag. Allowed values are DEBUG, WARN, INFO, TRACE Debug string `yaml:"debug"` // Export is the configuration block for setting up data exporters Export ConfigExport `yaml:"export" validate:"required"` // Notification is the configuration block for setting up notifications Notification NotificationConfig `yaml:"notification"` // Server is the configuration settings for server mode Server Server `yaml:"server"` }
func ExtractEnvVariables ¶
func ExtractEnvVariables() (ConfigurationData, error)
checkRequiredEnvVars checks if the required environment variables are set A ConfigurationData struct is returned with the values of the environment variables
func GenerateConfigStruct ¶
func GenerateConfigStruct(filePath string) (ConfigurationData, error)
GenerateLambdaDeleteList is a function that takes a file path as input and returns a list of Lambdas to be deleted
type Credentials ¶
type Credentials struct { // The file path to the credentials file. By default, a local file by the name of "token.json" is looked for. CredentialsFile string `yaml:"credentialsFile"` }
type CycleCollection ¶
type CycleCollection struct { Records []CycleRecords `json:"records" csv:"records"` NextToken *string `json:"next_token,omitempty" csv:"next_token,omitempty"` }
type CycleRecords ¶
type CycleRecords struct { ID int `json:"id" csv:"id"` UserID int `json:"user_id" csv:"user_id"` CreatedAt time.Time `json:"created_at" csv:"created_at"` UpdatedAt time.Time `json:"updated_at" csv:"updated_at"` Start time.Time `json:"start" csv:"start"` End time.Time `json:"end" csv:"end"` TimezoneOffset string `json:"timezone_offset" csv:"timezone_offset"` ScoreState string `json:"score_state" csv:"score_state"` Score CycleScore `json:"score" csv:"score"` }
type CycleScore ¶
type Event ¶
type Event string
func EventFromString ¶
eventFromString converts a string to an Event type.
type Notification ¶
type Notification interface { // SetUp sets up the notification service and returns an error if the setup fails. SetUp() error // Send sends a notification using the notification service with the provided data and event. Publish(client *http.Client, data []byte, event string) error }
Notification is an interface that defines the methods for a notification service. It requires two method functions SetUp and Send. Consumers can use the Publish method to send notifications using the notification service.
type NotificationConfig ¶
type NotificationConfig struct { // Method is the notification method to use. If no method is specified, then no external notification is sent. Method string `yaml:"method" validate:"oneof=ntfy ''"` // Ntfy is the configuration settings for the Ntfy notification service. Ntfy notifications.Ntfy `yaml:"ntfy" validate:"required_if=Method ntfy"` }
type RecoveryCollection ¶
type RecoveryCollection struct { RecoveryRecords []RecoveryRecords `json:"records" csv:"records"` NextToken *string `json:"next_token,omitempty"` }
type RecoveryRecords ¶
type RecoveryRecords struct { CycleID int `json:"cycle_id" csv:"cycle_id"` SleepID int `json:"sleep_id" csv:"sleep_id"` UserID int `json:"user_id" csv:"user_id"` CreatedAt time.Time `json:"created_at" csv:"created_at"` UpdatedAt time.Time `json:"updated_at" csv:"updated_at"` ScoreState string `json:"score_state" csv:"score_state"` Score RecoveryScore `json:"score" csv:"score"` }
type RecoveryScore ¶
type RecoveryScore struct { UserCalibrating bool `json:"user_calibrating" csv:"user_calibrating"` RecoveryScore float64 `json:"recovery_score" csv:"recovery_score"` RestingHeartRate float64 `json:"resting_heart_rate" csv:"resting_heart_rate"` HrvRmssdMilli float64 `json:"hrv_rmssd_milli" csv:"hrv_rmssd_milli"` Spo2Percentage float64 `json:"spo2_percentage" csv:"spo2_percentage"` SkinTempCelsius float64 `json:"skin_temp_celsius" csv:"skin_temp_celsius"` }
type Score ¶
type Score struct { StageSummary StageSummary `json:"stage_summary" csv:"stage_summary"` SleepNeeded SleepNeeded `json:"sleep_needed" csv:"sleep_needed"` RespiratoryRate float64 `json:"respiratory_rate" csv:"respiratory_rate"` SleepPerformancePercentage float64 `json:"sleep_performance_percentage" csv:"sleep_performance_percentage"` SleepConsistencyPercentage float64 `json:"sleep_consistency_percentage" csv:"sleep_consistency_percentage"` SleepEfficiencyPercentage float64 `json:"sleep_efficiency_percentage" csv:"sleep_efficiency_percentage"` }
type Server ¶
type Server struct { // Set to true to enable server mode. Default is false. Enabled bool `yaml:"enabled"` // A cron tab string to schedule the server to run at specific times. Default is every 24 hours at 1300 hours - 0 13 * * *. Crontab string `yaml:"crontab"` //JWTRefreshDuration is the duration to refresh the JWT token in minutes. Default is 45 minutes. This value must be greater than 0 and less than 59 minutes. JWTRefreshDuration int `yaml:"jwtRefreshDuration"` }
type SleepCollection ¶
type SleepCollection struct { SleepCollectionRecords []SleepCollectionRecords `json:"records" csv:"records"` NextToken *string `json:"next_token,omitempty" csv:"next_token,omitempty"` }
type SleepCollectionRecords ¶
type SleepCollectionRecords struct { ID int `json:"id" csv:"id"` UserID int `json:"user_id" csv:"user_id"` CreatedAt time.Time `json:"created_at" csv:"created_at"` UpdatedAt time.Time `json:"updated_at" csv:"updated_at"` Start time.Time `json:"start" csv:"start"` End time.Time `json:"end" csv:"end"` TimezoneOffset string `json:"timezone_offset" csv:"timezone_offset"` Nap bool `json:"nap" csv:"nap"` ScoreState string `json:"score_state" csv:"score_state"` Score Score `json:"score" csv:"score"` }
type SleepNeeded ¶
type SleepNeeded struct { BaselineMilli int `json:"baseline_milli" csv:"baseline_milli"` NeedFromSleepDebtMilli int `json:"need_from_sleep_debt_milli" csv:"need_from_sleep_debt_milli"` NeedFromRecentStrainMilli int `json:"need_from_recent_strain_milli" csv:"need_from_recent_strain_milli"` NeedFromRecentNapMilli int `json:"need_from_recent_nap_milli" csv:"need_from_recent_nap_milli"` }
type StageSummary ¶
type StageSummary struct { TotalInBedTimeMilli int `json:"total_in_bed_time_milli" csv:"total_in_bed_time_milli"` TotalAwakeTimeMilli int `json:"total_awake_time_milli" csv:"total_awake_time_milli"` TotalNoDataTimeMilli int `json:"total_no_data_time_milli" csv:"total_no_data_time_milli"` TotalLightSleepTimeMilli int `json:"total_light_sleep_time_milli" csv:"total_light_sleep_time_milli"` TotalSlowWaveSleepTimeMilli int `json:"total_slow_wave_sleep_time_milli" csv:"total_slow_wave_sleep_time_milli"` TotalRemSleepTimeMilli int `json:"total_rem_sleep_time_milli" csv:"total_rem_sleep_time_milli"` SleepCycleCount int `json:"sleep_cycle_count" csv:"sleep_cycle_count"` DisturbanceCount int `json:"disturbance_count" csv:"disturbance_count"` }
type User ¶
type User struct { UserData UserData `json:"user_data,omitempty" csv:"user_data"` UserMesaurements UserMesaurements `json:"user_mesaurements,omitempty" csv:"user_mesaurements"` SleepCollection SleepCollection `json:"sleep_collection" csv:"sleep_collection"` RecoveryCollection RecoveryCollection `json:"recovery_collection" csv:"recovery_collection"` WorkoutCollection WorkoutCollection `json:"workout_collection" csv:"workout_collection"` CycleCollection CycleCollection `json:"cycle_collection" csv:"cycle_collection"` }
func (User) GetCycleCollection ¶
func (User) GetRecoveryCollection ¶
func (User) GetSleepCollection ¶
func (u User) GetSleepCollection(ctx context.Context, client *http.Client, url, authToken, filters, ua string) (*SleepCollection, error)
GetSleepCollection returns the sleep collection from the Whoop API filters is a string of filters to apply to the request Pagination is enabled by default so as a result all available sleep collection records will be returned
func (User) GetUserMeasurements ¶
func (u User) GetUserMeasurements(ctx context.Context, client *http.Client, url, authToken, ua string) (*UserMesaurements, error)
GetUserMeasurements returns the user measurements provided by the user from the Whoop API
func (User) GetUserProfileData ¶
func (u User) GetUserProfileData(ctx context.Context, client *http.Client, url, authToken, ua string) (*UserData, error)
getUserProfile returns the user profile from the Whoop API
func (User) GetWorkoutCollection ¶
type UserMesaurements ¶
type WorkoutCollection ¶
type WorkoutCollection struct { Records []WorkoutRecords `json:"records" csv:"records"` NextToken *string `json:"next_token,omitempty"` }
type WorkoutRecords ¶
type WorkoutRecords struct { ID int `json:"id" csv:"id"` UserID int `json:"user_id" csv:"user_id"` CreatedAt time.Time `json:"created_at" csv:"created_at"` UpdatedAt time.Time `json:"updated_at" csv:"updated_at"` Start time.Time `json:"start" csv:"start"` End time.Time `json:"end" csv:"end"` TimezoneOffset string `json:"timezone_offset" csv:"timezone_offset"` SportID int `json:"sport_id" csv:"sport_id"` ScoreState string `json:"score_state" csv:"score_state"` Score WorkoutScore `json:"score" csv:"score"` }
type WorkoutScore ¶
type WorkoutScore struct { Strain float64 `json:"strain" csv:"strain"` AverageHeartRate int `json:"average_heart_rate" csv:"average_heart_rate"` MaxHeartRate int `json:"max_heart_rate" csv:"max_heart_rate"` Kilojoule float64 `json:"kilojoule" csv:"kilojoule"` PercentRecorded float64 `json:"percent_recorded" csv:"percent_recorded"` DistanceMeter float64 `json:"distance_meter" csv:"distance_meter"` AltitudeGainMeter float64 `json:"altitude_gain_meter" csv:"altitude_gain_meter"` AltitudeChangeMeter float64 `json:"altitude_change_meter" csv:"altitude_change_meter"` ZoneDuration ZoneDuration `json:"zone_duration" csv:"zone_duration"` }
type ZoneDuration ¶
type ZoneDuration struct { ZoneZeroMilli int `json:"zone_zero_milli" csv:"zone_zero_milli"` ZoneOneMilli int `json:"zone_one_milli" csv:"zone_one_milli"` ZoneTwoMilli int `json:"zone_two_milli" csv:"zone_two_milli"` ZoneThreeMilli int `json:"zone_three_milli" csv:"zone_three_milli"` ZoneFourMilli int `json:"zone_four_milli" csv:"zone_four_milli"` ZoneFiveMilli int `json:"zone_five_milli" csv:"zone_five_milli"` }