mirror of
https://github.com/sstent/go-garth.git
synced 2025-12-06 08:01:42 +00:00
sync - build broken
This commit is contained in:
@@ -8,7 +8,8 @@ import (
|
||||
|
||||
internalClient "go-garth/internal/api/client"
|
||||
"go-garth/internal/errors"
|
||||
"go-garth/internal/types"
|
||||
types "go-garth/internal/models/types"
|
||||
shared "go-garth/shared/interfaces"
|
||||
)
|
||||
|
||||
// Client is the main Garmin Connect client type
|
||||
@@ -16,6 +17,8 @@ type Client struct {
|
||||
Client *internalClient.Client
|
||||
}
|
||||
|
||||
var _ shared.APIClient = (*Client)(nil)
|
||||
|
||||
// NewClient creates a new Garmin Connect client
|
||||
func NewClient(domain string) (*Client, error) {
|
||||
c, err := internalClient.NewClient(domain)
|
||||
@@ -25,6 +28,35 @@ func NewClient(domain string) (*Client, error) {
|
||||
return &Client{Client: c}, nil
|
||||
}
|
||||
|
||||
func (c *Client) InternalClient() *internalClient.Client {
|
||||
return c.Client
|
||||
}
|
||||
|
||||
// ConnectAPI implements the APIClient interface
|
||||
func (c *Client) ConnectAPI(path string, method string, params url.Values, body io.Reader) ([]byte, error) {
|
||||
return c.Client.ConnectAPI(path, method, params, body)
|
||||
}
|
||||
|
||||
// GetUsername implements the APIClient interface
|
||||
func (c *Client) GetUsername() string {
|
||||
return c.Client.GetUsername()
|
||||
}
|
||||
|
||||
// GetUserSettings implements the APIClient interface
|
||||
func (c *Client) GetUserSettings() (*types.UserSettings, error) {
|
||||
return c.Client.GetUserSettings()
|
||||
}
|
||||
|
||||
// GetUserProfile implements the APIClient interface
|
||||
func (c *Client) GetUserProfile() (*types.UserProfile, error) {
|
||||
return c.Client.GetUserProfile()
|
||||
}
|
||||
|
||||
// GetWellnessData implements the APIClient interface
|
||||
func (c *Client) GetWellnessData(startDate, endDate time.Time) ([]types.WellnessData, error) {
|
||||
return c.Client.GetWellnessData(startDate, endDate)
|
||||
}
|
||||
|
||||
// Login authenticates to Garmin Connect
|
||||
func (c *Client) Login(email, password string) error {
|
||||
return c.Client.Login(email, password)
|
||||
@@ -133,13 +165,13 @@ func (c *Client) SearchActivities(query string) ([]Activity, error) {
|
||||
}
|
||||
|
||||
// GetSleepData retrieves sleep data for a specified date range
|
||||
func (c *Client) GetSleepData(startDate, endDate time.Time) ([]types.SleepData, error) {
|
||||
return c.Client.GetSleepData(startDate, endDate)
|
||||
func (c *Client) GetSleepData(date time.Time) (*types.DetailedSleepData, error) {
|
||||
return c.Client.GetDetailedSleepData(date)
|
||||
}
|
||||
|
||||
// GetHrvData retrieves HRV data for a specified number of days
|
||||
func (c *Client) GetHrvData(days int) ([]types.HrvData, error) {
|
||||
return c.Client.GetHrvData(days)
|
||||
func (c *Client) GetHrvData(date time.Time) (*types.DailyHRVData, error) {
|
||||
return c.Client.GetDailyHRVData(date)
|
||||
}
|
||||
|
||||
// GetStressData retrieves stress data
|
||||
@@ -148,8 +180,8 @@ func (c *Client) GetStressData(startDate, endDate time.Time) ([]types.StressData
|
||||
}
|
||||
|
||||
// GetBodyBatteryData retrieves Body Battery data
|
||||
func (c *Client) GetBodyBatteryData(startDate, endDate time.Time) ([]types.BodyBatteryData, error) {
|
||||
return c.Client.GetBodyBatteryData(startDate, endDate)
|
||||
func (c *Client) GetBodyBatteryData(date time.Time) (*types.DetailedBodyBatteryData, error) {
|
||||
return c.Client.GetDetailedBodyBatteryData(date)
|
||||
}
|
||||
|
||||
// GetStepsData retrieves steps data for a specified date range
|
||||
@@ -182,6 +214,21 @@ func (c *Client) GetWellnessData(startDate, endDate time.Time) ([]types.Wellness
|
||||
return c.Client.GetWellnessData(startDate, endDate)
|
||||
}
|
||||
|
||||
// GetTrainingStatus retrieves current training status
|
||||
func (c *Client) GetTrainingStatus(date time.Time) (*types.TrainingStatus, error) {
|
||||
return c.Client.GetTrainingStatus(date)
|
||||
}
|
||||
|
||||
// GetTrainingLoad retrieves training load data
|
||||
func (c *Client) GetTrainingLoad(date time.Time) (*types.TrainingLoad, error) {
|
||||
return c.Client.GetTrainingLoad(date)
|
||||
}
|
||||
|
||||
// GetFitnessAge retrieves fitness age calculation
|
||||
func (c *Client) GetFitnessAge() (*types.FitnessAge, error) {
|
||||
return c.Client.GetFitnessAge()
|
||||
}
|
||||
|
||||
// OAuth1Token returns the OAuth1 token
|
||||
func (c *Client) OAuth1Token() *types.OAuth1Token {
|
||||
return c.Client.OAuth1Token
|
||||
@@ -190,4 +237,4 @@ func (c *Client) OAuth1Token() *types.OAuth1Token {
|
||||
// OAuth2Token returns the OAuth2 token
|
||||
func (c *Client) OAuth2Token() *types.OAuth2Token {
|
||||
return c.Client.OAuth2Token
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,88 @@
|
||||
package garmin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
internalClient "go-garth/internal/api/client"
|
||||
"go-garth/internal/models/types"
|
||||
)
|
||||
|
||||
// SleepData represents sleep summary data
|
||||
type SleepData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
SleepScore int `json:"sleepScore"`
|
||||
TotalSleepSeconds int `json:"totalSleepSeconds"`
|
||||
DeepSleepSeconds int `json:"deepSleepSeconds"`
|
||||
LightSleepSeconds int `json:"lightSleepSeconds"`
|
||||
RemSleepSeconds int `json:"remSleepSeconds"`
|
||||
AwakeSleepSeconds int `json:"awakeSleepSeconds"`
|
||||
// Add more fields as needed
|
||||
func (c *Client) GetDailyHRVData(date time.Time) (*types.DailyHRVData, error) {
|
||||
return getDailyHRVData(date, c.Client)
|
||||
}
|
||||
|
||||
// HrvData represents Heart Rate Variability data
|
||||
type HrvData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
HrvValue float64 `json:"hrvValue"`
|
||||
// Add more fields as needed
|
||||
func getDailyHRVData(day time.Time, client *internalClient.Client) (*types.DailyHRVData, error) {
|
||||
dateStr := day.Format("2006-01-02")
|
||||
path := fmt.Sprintf("/wellness-service/wellness/dailyHrvData/%s?date=%s",
|
||||
client.Username, dateStr)
|
||||
|
||||
data, err := client.ConnectAPI(path, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get HRV data: %w", err)
|
||||
}
|
||||
|
||||
if len(data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var response struct {
|
||||
HRVSummary types.DailyHRVData `json:"hrvSummary"`
|
||||
HRVReadings []types.HRVReading `json:"hrvReadings"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse HRV response: %w", err)
|
||||
}
|
||||
|
||||
// Combine summary and readings
|
||||
response.HRVSummary.HRVReadings = response.HRVReadings
|
||||
return &response.HRVSummary, nil
|
||||
}
|
||||
|
||||
// StressData represents stress level data
|
||||
type StressData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
StressLevel int `json:"stressLevel"`
|
||||
RestStressLevel int `json:"restStressLevel"`
|
||||
// Add more fields as needed
|
||||
func (c *Client) GetDetailedSleepData(date time.Time) (*types.DetailedSleepData, error) {
|
||||
return getDetailedSleepData(date, c.Client)
|
||||
}
|
||||
|
||||
// BodyBatteryData represents Body Battery data
|
||||
type BodyBatteryData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
BatteryLevel int `json:"batteryLevel"`
|
||||
Charge int `json:"charge"`
|
||||
Drain int `json:"drain"`
|
||||
// Add more fields as needed
|
||||
}
|
||||
func getDetailedSleepData(day time.Time, client *internalClient.Client) (*types.DetailedSleepData, error) {
|
||||
dateStr := day.Format("2006-01-02")
|
||||
path := fmt.Sprintf("/wellness-service/wellness/dailySleepData/%s?date=%s&nonSleepBufferMinutes=60",
|
||||
client.Username, dateStr)
|
||||
|
||||
// VO2MaxData represents VO2 max data
|
||||
type VO2MaxData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
VO2MaxRunning float64 `json:"vo2MaxRunning"`
|
||||
VO2MaxCycling float64 `json:"vo2MaxCycling"`
|
||||
// Add more fields as needed
|
||||
}
|
||||
data, err := client.ConnectAPI(path, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get detailed sleep data: %w", err)
|
||||
}
|
||||
|
||||
// HeartRateZones represents heart rate zone data
|
||||
type HeartRateZones struct {
|
||||
RestingHR int `json:"resting_hr"`
|
||||
MaxHR int `json:"max_hr"`
|
||||
LactateThreshold int `json:"lactate_threshold"`
|
||||
Zones []HRZone `json:"zones"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// HRZone represents a single heart rate zone
|
||||
type HRZone struct {
|
||||
Zone int `json:"zone"`
|
||||
MinBPM int `json:"min_bpm"`
|
||||
MaxBPM int `json:"max_bpm"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var response struct {
|
||||
DailySleepDTO *types.DetailedSleepData `json:"dailySleepDTO"`
|
||||
SleepMovement []types.SleepMovement `json:"sleepMovement"`
|
||||
RemSleepData bool `json:"remSleepData"`
|
||||
SleepLevels []types.SleepLevel `json:"sleepLevels"`
|
||||
SleepRestlessMoments []interface{} `json:"sleepRestlessMoments"`
|
||||
RestlessMomentsCount int `json:"restlessMomentsCount"`
|
||||
WellnessSpO2SleepSummaryDTO interface{} `json:"wellnessSpO2SleepSummaryDTO"`
|
||||
WellnessEpochSPO2DataDTOList []interface{} `json:"wellnessEpochSPO2DataDTOList"`
|
||||
WellnessEpochRespirationDataDTOList []interface{} `json:"wellnessEpochRespirationDataDTOList"`
|
||||
SleepStress interface{} `json:"sleepStress"`
|
||||
}
|
||||
|
||||
// WellnessData represents additional wellness metrics
|
||||
type WellnessData struct {
|
||||
Date time.Time `json:"calendarDate"`
|
||||
RestingHR *int `json:"resting_hr"`
|
||||
Weight *float64 `json:"weight"`
|
||||
BodyFat *float64 `json:"body_fat"`
|
||||
BMI *float64 `json:"bmi"`
|
||||
BodyWater *float64 `json:"body_water"`
|
||||
BoneMass *float64 `json:"bone_mass"`
|
||||
MuscleMass *float64 `json:"muscle_mass"`
|
||||
// Add more fields as needed
|
||||
}
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse detailed sleep response: %w", err)
|
||||
}
|
||||
|
||||
if response.DailySleepDTO == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Populate additional data
|
||||
response.DailySleepDTO.SleepMovement = response.SleepMovement
|
||||
response.DailySleepDTO.SleepLevels = response.SleepLevels
|
||||
|
||||
return response.DailySleepDTO, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package garmin
|
||||
|
||||
import "go-garth/internal/types"
|
||||
import types "go-garth/internal/models/types"
|
||||
|
||||
// GarminTime represents Garmin's timestamp format with custom JSON parsing
|
||||
type GarminTime = types.GarminTime
|
||||
@@ -24,4 +24,67 @@ type UserProfile = types.UserProfile
|
||||
type OAuth1Token = types.OAuth1Token
|
||||
|
||||
// OAuth2Token represents OAuth2 token response
|
||||
type OAuth2Token = types.OAuth2Token
|
||||
type OAuth2Token = types.OAuth2Token
|
||||
|
||||
// DetailedSleepData represents comprehensive sleep data
|
||||
type DetailedSleepData = types.DetailedSleepData
|
||||
|
||||
// SleepLevel represents different sleep stages
|
||||
type SleepLevel = types.SleepLevel
|
||||
|
||||
// SleepMovement represents movement during sleep
|
||||
type SleepMovement = types.SleepMovement
|
||||
|
||||
// SleepScore represents detailed sleep scoring
|
||||
type SleepScore = types.SleepScore
|
||||
|
||||
// SleepScoreBreakdown represents breakdown of sleep score
|
||||
type SleepScoreBreakdown = types.SleepScoreBreakdown
|
||||
|
||||
// HRVBaseline represents HRV baseline data
|
||||
type HRVBaseline = types.HRVBaseline
|
||||
|
||||
// DailyHRVData represents comprehensive daily HRV data
|
||||
type DailyHRVData = types.DailyHRVData
|
||||
|
||||
// BodyBatteryEvent represents events that impact Body Battery
|
||||
type BodyBatteryEvent = types.BodyBatteryEvent
|
||||
|
||||
// DetailedBodyBatteryData represents comprehensive Body Battery data
|
||||
type DetailedBodyBatteryData = types.DetailedBodyBatteryData
|
||||
|
||||
// TrainingStatus represents current training status
|
||||
type TrainingStatus = types.TrainingStatus
|
||||
|
||||
// TrainingLoad represents training load data
|
||||
type TrainingLoad = types.TrainingLoad
|
||||
|
||||
// FitnessAge represents fitness age calculation
|
||||
type FitnessAge = types.FitnessAge
|
||||
|
||||
// VO2MaxData represents VO2 max data
|
||||
type VO2MaxData = types.VO2MaxData
|
||||
|
||||
// VO2MaxEntry represents a single VO2 max entry
|
||||
type VO2MaxEntry = types.VO2MaxEntry
|
||||
|
||||
// HeartRateZones represents heart rate zone data
|
||||
type HeartRateZones = types.HeartRateZones
|
||||
|
||||
// HRZone represents a single heart rate zone
|
||||
type HRZone = types.HRZone
|
||||
|
||||
// WellnessData represents additional wellness metrics
|
||||
type WellnessData = types.WellnessData
|
||||
|
||||
// SleepData represents sleep summary data
|
||||
type SleepData = types.SleepData
|
||||
|
||||
// HrvData represents Heart Rate Variability data
|
||||
type HrvData = types.HrvData
|
||||
|
||||
// StressData represents stress level data
|
||||
type StressData = types.StressData
|
||||
|
||||
// BodyBatteryData represents Body Battery data
|
||||
type BodyBatteryData = types.BodyBatteryData
|
||||
|
||||
Reference in New Issue
Block a user