api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL is the default Hevy API base URL
	DefaultBaseURL = "https://api.hevyapp.com/v1"

	// DefaultTimeout is the default request timeout
	DefaultTimeout = 30 * time.Second

	// UserAgent is the user agent string for API requests
	UserAgent = "hevycli/1.0"
)
View Source
const (
	ExitSuccess         = 0
	ExitGeneralError    = 1
	ExitInvalidArgs     = 2
	ExitAuthError       = 3
	ExitRateLimited     = 4
	ExitNetworkError    = 5
	ExitNotFound        = 6
	ExitValidationError = 7
)

Exit codes for different error types

Variables

View Source
var (
	ErrInvalidAPIKey = NewAPIErrorWithDetails(
		"INVALID_API_KEY",
		"The provided API key is invalid or expired",
		"Please verify your API key at https://hevy.com/settings?developer",
	)

	ErrForbidden = NewAPIErrorWithDetails(
		"FORBIDDEN",
		"Access forbidden",
		"Hevy Pro subscription required for API access",
	)

	ErrNotFound = NewAPIError(
		"NOT_FOUND",
		"Resource not found",
	)

	ErrRateLimited = NewAPIError(
		"RATE_LIMITED",
		"Rate limit exceeded. Please try again later",
	)

	ErrNetworkError = NewAPIError(
		"NETWORK_ERROR",
		"Failed to connect to Hevy API",
	)
)

Common API errors

Functions

This section is empty.

Types

type APIError

type APIError struct {
	ErrorCode    string `json:"code"`
	ErrorMessage string `json:"message"`
	ErrorDetails string `json:"details,omitempty"`
}

APIError represents an error from the Hevy API

func NewAPIError

func NewAPIError(code, message string) *APIError

NewAPIError creates a new API error

func NewAPIErrorWithDetails

func NewAPIErrorWithDetails(code, message, details string) *APIError

NewAPIErrorWithDetails creates a new API error with additional details

func (*APIError) Code

func (e *APIError) Code() string

Code returns the error code

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface

func (*APIError) ExitCode

func (e *APIError) ExitCode() int

ExitCode returns the appropriate exit code for this error

type Client

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

Client represents the Hevy API client

func NewClient

func NewClient(apiKey string, opts ...ClientOption) *Client

NewClient creates a new Hevy API client

func (*Client) CreateCustomExercise

func (c *Client) CreateCustomExercise(req *CreateCustomExerciseRequest) (*ExerciseTemplate, error)

CreateCustomExercise creates a new custom exercise template

func (*Client) CreateRoutine

func (c *Client) CreateRoutine(req *CreateRoutineRequest) (*Routine, error)

CreateRoutine creates a new routine

func (*Client) CreateRoutineFolder

func (c *Client) CreateRoutineFolder(req *CreateRoutineFolderRequest) (*RoutineFolder, error)

CreateRoutineFolder creates a new routine folder

func (*Client) CreateWorkout

func (c *Client) CreateWorkout(req *CreateWorkoutRequest) (*Workout, error)

CreateWorkout creates a new workout

func (*Client) DeleteWorkout

func (c *Client) DeleteWorkout(id string) error

DeleteWorkout deletes a workout by ID

func (*Client) GetAllWorkouts

func (c *Client) GetAllWorkouts() ([]Workout, error)

GetAllWorkouts fetches all workouts using pagination

func (*Client) GetExerciseTemplate

func (c *Client) GetExerciseTemplate(id string) (*ExerciseTemplate, error)

GetExerciseTemplate fetches a single exercise template by ID

func (*Client) GetExerciseTemplates

func (c *Client) GetExerciseTemplates(page, pageSize int) (*ExerciseTemplatesResponse, error)

GetExerciseTemplates fetches exercise templates with pagination

func (*Client) GetRoutine

func (c *Client) GetRoutine(id string) (*Routine, error)

GetRoutine fetches a single routine by ID

func (*Client) GetRoutineFolder

func (c *Client) GetRoutineFolder(id string) (*RoutineFolder, error)

GetRoutineFolder fetches a single routine folder by ID

func (*Client) GetRoutineFolders

func (c *Client) GetRoutineFolders(page, pageSize int) (*RoutineFoldersResponse, error)

GetRoutineFolders fetches routine folders

func (*Client) GetRoutines

func (c *Client) GetRoutines(page, pageSize int) (*RoutinesResponse, error)

GetRoutines fetches all routines

func (*Client) GetWorkout

func (c *Client) GetWorkout(id string) (*Workout, error)

GetWorkout fetches a single workout by ID

func (*Client) GetWorkoutCount

func (c *Client) GetWorkoutCount() (int, error)

GetWorkoutCount fetches the total number of workouts

func (*Client) GetWorkouts

func (c *Client) GetWorkouts(page, pageSize int) (*WorkoutsResponse, error)

GetWorkouts fetches workouts with pagination

func (*Client) UpdateRoutine

func (c *Client) UpdateRoutine(id string, req *UpdateRoutineRequest) (*Routine, error)

UpdateRoutine updates an existing routine

func (*Client) UpdateWorkout

func (c *Client) UpdateWorkout(id string, req *UpdateWorkoutRequest) (*Workout, error)

UpdateWorkout updates an existing workout

func (*Client) ValidateAuth

func (c *Client) ValidateAuth() error

ValidateAuth tests if the API key is valid by calling /workouts endpoint

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures the client

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets a custom base URL

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets a custom timeout

type CreateCustomExerciseData

type CreateCustomExerciseData struct {
	Title             string            `json:"title"`
	ExerciseType      ExerciseType      `json:"exercise_type"`
	EquipmentCategory EquipmentCategory `json:"equipment_category"`
	MuscleGroup       MuscleGroup       `json:"muscle_group"`
	OtherMuscles      []MuscleGroup     `json:"other_muscles,omitempty"`
}

CreateCustomExerciseData represents the custom exercise data for creation

type CreateCustomExerciseRequest

type CreateCustomExerciseRequest struct {
	Exercise CreateCustomExerciseData `json:"exercise"`
}

CreateCustomExerciseRequest represents the request body for POST /exercise_templates

type CreateRoutineData

type CreateRoutineData struct {
	Title     string                  `json:"title"`
	FolderID  *int                    `json:"folder_id,omitempty"`
	Notes     *string                 `json:"notes,omitempty"`
	Exercises []CreateRoutineExercise `json:"exercises"`
}

CreateRoutineData represents the routine data for creation

type CreateRoutineExercise

type CreateRoutineExercise struct {
	ExerciseTemplateID string             `json:"exercise_template_id"`
	SupersetID         *int               `json:"superset_id,omitempty"`
	RestSeconds        *int               `json:"rest_seconds,omitempty"`
	Notes              *string            `json:"notes,omitempty"`
	Sets               []CreateRoutineSet `json:"sets"`
}

CreateRoutineExercise represents an exercise in a routine creation request

type CreateRoutineFolderData

type CreateRoutineFolderData struct {
	Title string `json:"title"`
}

CreateRoutineFolderData represents the folder data for creation

type CreateRoutineFolderRequest

type CreateRoutineFolderRequest struct {
	RoutineFolder CreateRoutineFolderData `json:"routine_folder"`
}

CreateRoutineFolderRequest represents the request body for POST /routine_folders

type CreateRoutineRequest

type CreateRoutineRequest struct {
	Routine CreateRoutineData `json:"routine"`
}

CreateRoutineRequest represents the request body for POST /routines

type CreateRoutineSet

type CreateRoutineSet struct {
	Type            SetType   `json:"type"`
	WeightKg        *float64  `json:"weight_kg,omitempty"`
	Reps            *int      `json:"reps,omitempty"`
	DistanceMeters  *int      `json:"distance_meters,omitempty"`
	DurationSeconds *int      `json:"duration_seconds,omitempty"`
	CustomMetric    *float64  `json:"custom_metric,omitempty"`
	RepRange        *RepRange `json:"rep_range,omitempty"`
}

CreateRoutineSet represents a set in a routine creation request

type CreateWorkoutData

type CreateWorkoutData struct {
	Title       string                  `json:"title"`
	Description *string                 `json:"description,omitempty"`
	StartTime   string                  `json:"start_time"`
	EndTime     string                  `json:"end_time"`
	IsPrivate   bool                    `json:"is_private,omitempty"`
	Exercises   []CreateWorkoutExercise `json:"exercises"`
}

CreateWorkoutData represents the workout data for creation

type CreateWorkoutExercise

type CreateWorkoutExercise struct {
	ExerciseTemplateID string             `json:"exercise_template_id"`
	SupersetID         *int               `json:"superset_id,omitempty"`
	Notes              *string            `json:"notes,omitempty"`
	Sets               []CreateWorkoutSet `json:"sets"`
}

CreateWorkoutExercise represents an exercise in a workout creation request

type CreateWorkoutRequest

type CreateWorkoutRequest struct {
	Workout CreateWorkoutData `json:"workout"`
}

CreateWorkoutRequest represents the request body for POST /workouts

type CreateWorkoutSet

type CreateWorkoutSet struct {
	Type            SetType  `json:"type"`
	WeightKg        *float64 `json:"weight_kg,omitempty"`
	Reps            *int     `json:"reps,omitempty"`
	DistanceMeters  *int     `json:"distance_meters,omitempty"`
	DurationSeconds *int     `json:"duration_seconds,omitempty"`
	CustomMetric    *float64 `json:"custom_metric,omitempty"`
	RPE             *float64 `json:"rpe,omitempty"`
}

CreateWorkoutSet represents a set in a workout creation request

type EquipmentCategory

type EquipmentCategory string

EquipmentCategory represents equipment types

const (
	EquipmentNone           EquipmentCategory = "none"
	EquipmentBarbell        EquipmentCategory = "barbell"
	EquipmentDumbbell       EquipmentCategory = "dumbbell"
	EquipmentKettlebell     EquipmentCategory = "kettlebell"
	EquipmentMachine        EquipmentCategory = "machine"
	EquipmentPlate          EquipmentCategory = "plate"
	EquipmentResistanceBand EquipmentCategory = "resistance_band"
	EquipmentSuspension     EquipmentCategory = "suspension"
	EquipmentOther          EquipmentCategory = "other"
)

type EventType

type EventType string

EventType represents the type of workout event

const (
	EventTypeUpdated EventType = "updated"
	EventTypeDeleted EventType = "deleted"
)

type Exercise

type Exercise struct {
	Index              int    `json:"index"`
	Title              string `json:"title"`
	Notes              string `json:"notes,omitempty"`
	ExerciseTemplateID string `json:"exercise_template_id"`
	SupersetID         *int   `json:"superset_id,omitempty"`
	Sets               []Set  `json:"sets"`
}

Exercise represents an exercise within a workout

type ExerciseTemplate

type ExerciseTemplate struct {
	ID                    string   `json:"id"`
	Title                 string   `json:"title"`
	Type                  string   `json:"type,omitempty"`
	PrimaryMuscleGroup    string   `json:"primary_muscle_group"`
	SecondaryMuscleGroups []string `json:"secondary_muscle_groups,omitempty"`
	Equipment             string   `json:"equipment,omitempty"`
	IsCustom              bool     `json:"is_custom"`
}

ExerciseTemplate represents an exercise definition from the Hevy database

type ExerciseTemplateResponse

type ExerciseTemplateResponse struct {
	ExerciseTemplate ExerciseTemplate `json:"exercise_template"`
}

ExerciseTemplateResponse represents the response from POST /exercise_templates

type ExerciseTemplatesResponse

type ExerciseTemplatesResponse struct {
	Page              int                `json:"page"`
	PageCount         int                `json:"page_count"`
	ExerciseTemplates []ExerciseTemplate `json:"exercise_templates"`
}

ExerciseTemplatesResponse represents the /exercise_templates endpoint response

type ExerciseType

type ExerciseType string

ExerciseType represents the type of exercise tracking

const (
	ExerciseTypeWeightReps          ExerciseType = "weight_reps"
	ExerciseTypeRepsOnly            ExerciseType = "reps_only"
	ExerciseTypeBodyweightReps      ExerciseType = "bodyweight_reps"
	ExerciseTypeBodyweightAssisted  ExerciseType = "bodyweight_assisted_reps"
	ExerciseTypeDuration            ExerciseType = "duration"
	ExerciseTypeWeightDuration      ExerciseType = "weight_duration"
	ExerciseTypeDistanceDuration    ExerciseType = "distance_duration"
	ExerciseTypeShortDistanceWeight ExerciseType = "short_distance_weight"
)

type MuscleGroup

type MuscleGroup string

MuscleGroup represents muscle groups for exercises

const (
	MuscleGroupAbdominals MuscleGroup = "abdominals"
	MuscleGroupShoulders  MuscleGroup = "shoulders"
	MuscleGroupBiceps     MuscleGroup = "biceps"
	MuscleGroupTriceps    MuscleGroup = "triceps"
	MuscleGroupForearms   MuscleGroup = "forearms"
	MuscleGroupQuadriceps MuscleGroup = "quadriceps"
	MuscleGroupHamstrings MuscleGroup = "hamstrings"
	MuscleGroupCalves     MuscleGroup = "calves"
	MuscleGroupGlutes     MuscleGroup = "glutes"
	MuscleGroupAbductors  MuscleGroup = "abductors"
	MuscleGroupAdductors  MuscleGroup = "adductors"
	MuscleGroupLats       MuscleGroup = "lats"
	MuscleGroupUpperBack  MuscleGroup = "upper_back"
	MuscleGroupTraps      MuscleGroup = "traps"
	MuscleGroupLowerBack  MuscleGroup = "lower_back"
	MuscleGroupChest      MuscleGroup = "chest"
	MuscleGroupCardio     MuscleGroup = "cardio"
	MuscleGroupNeck       MuscleGroup = "neck"
	MuscleGroupFullBody   MuscleGroup = "full_body"
	MuscleGroupOther      MuscleGroup = "other"
)

type RepRange

type RepRange struct {
	Start *int `json:"start,omitempty"`
	End   *int `json:"end,omitempty"`
}

RepRange represents a range of reps for a set

type Routine

type Routine struct {
	ID        string     `json:"id"`
	Title     string     `json:"title"`
	FolderID  *string    `json:"folder_id,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	Exercises []Exercise `json:"exercises"`
}

Routine represents a workout routine template

type RoutineFolder

type RoutineFolder struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	Index     int       `json:"index"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

RoutineFolder represents a folder for organizing routines

type RoutineFolderResponse

type RoutineFolderResponse struct {
	RoutineFolder RoutineFolder `json:"routine_folder"`
}

RoutineFolderResponse represents the response from POST /routine_folders

type RoutineFoldersResponse

type RoutineFoldersResponse struct {
	Page           int             `json:"page"`
	PageCount      int             `json:"page_count"`
	RoutineFolders []RoutineFolder `json:"routine_folders"`
}

RoutineFoldersResponse represents the /routine_folders endpoint response

type RoutineResponse

type RoutineResponse struct {
	Routine Routine `json:"routine"`
}

RoutineResponse represents the response from POST/PUT /routines

type RoutinesResponse

type RoutinesResponse struct {
	Page      int       `json:"page"`
	PageCount int       `json:"page_count"`
	Routines  []Routine `json:"routines"`
}

RoutinesResponse represents the /routines endpoint response

type Set

type Set struct {
	Index           int      `json:"index"`
	SetType         SetType  `json:"type"`
	WeightKg        *float64 `json:"weight_kg,omitempty"`
	Reps            *int     `json:"reps,omitempty"`
	DistanceMeters  *float64 `json:"distance_meters,omitempty"`
	DurationSeconds *int     `json:"duration_seconds,omitempty"`
	RPE             *float64 `json:"rpe,omitempty"`
}

Set represents a single set of an exercise

type SetType

type SetType string

SetType represents the type of set

const (
	SetTypeNormal  SetType = "normal"
	SetTypeWarmup  SetType = "warmup"
	SetTypeDropset SetType = "dropset"
	SetTypeFailure SetType = "failure"
)

type UpdateRoutineData

type UpdateRoutineData struct {
	Title     string                  `json:"title"`
	Notes     *string                 `json:"notes,omitempty"`
	Exercises []CreateRoutineExercise `json:"exercises"`
}

UpdateRoutineData represents the routine data for update

type UpdateRoutineRequest

type UpdateRoutineRequest struct {
	Routine UpdateRoutineData `json:"routine"`
}

UpdateRoutineRequest represents the request body for PUT /routines/{id}

type UpdateWorkoutData

type UpdateWorkoutData struct {
	Title       string                  `json:"title"`
	Description *string                 `json:"description,omitempty"`
	StartTime   string                  `json:"start_time"`
	EndTime     string                  `json:"end_time"`
	Exercises   []CreateWorkoutExercise `json:"exercises"`
}

UpdateWorkoutData represents the workout data for update

type UpdateWorkoutRequest

type UpdateWorkoutRequest struct {
	Workout UpdateWorkoutData `json:"workout"`
}

UpdateWorkoutRequest represents the request body for PUT /workouts/{id}

type Workout

type Workout struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	Description string     `json:"description,omitempty"`
	StartTime   time.Time  `json:"start_time"`
	EndTime     time.Time  `json:"end_time"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	Exercises   []Exercise `json:"exercises"`
}

Workout represents a workout session

func (*Workout) Duration

func (w *Workout) Duration() time.Duration

Duration returns the workout duration

func (*Workout) ExerciseCount

func (w *Workout) ExerciseCount() int

ExerciseCount returns the number of exercises in the workout

func (*Workout) TotalSets

func (w *Workout) TotalSets() int

TotalSets returns the total number of sets across all exercises

type WorkoutCountResponse

type WorkoutCountResponse struct {
	WorkoutCount int `json:"workout_count"`
}

WorkoutCountResponse represents the /workouts/count endpoint response

type WorkoutEvent

type WorkoutEvent struct {
	ID        string    `json:"id"`
	Type      EventType `json:"type"`
	WorkoutID string    `json:"workout_id"`
	Timestamp time.Time `json:"timestamp"`
}

WorkoutEvent represents a change event for workout sync

type WorkoutEventsResponse

type WorkoutEventsResponse struct {
	Page          int            `json:"page"`
	PageCount     int            `json:"page_count"`
	WorkoutEvents []WorkoutEvent `json:"workout_events"`
}

WorkoutEventsResponse represents the /workouts/events endpoint response

type WorkoutResponse

type WorkoutResponse struct {
	Workout Workout `json:"workout"`
}

WorkoutResponse represents the response from POST/PUT /workouts

type WorkoutsResponse

type WorkoutsResponse struct {
	Page      int       `json:"page"`
	PageCount int       `json:"page_count"`
	Workouts  []Workout `json:"workouts"`
}

WorkoutsResponse represents the /workouts endpoint response

Jump to

Keyboard shortcuts

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