-
Notifications
You must be signed in to change notification settings - Fork 4
/
cardioscore.go
48 lines (40 loc) · 1.55 KB
/
cardioscore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package fitbit
import (
"encoding/json"
"fmt"
)
// CardioFitnessScoreLog contains the cardio fitness score (VO2Max) for a given date
type CardioFitnessScoreLog struct {
CardioScore []struct {
DateTime string `json:"dateTime"`
Value struct {
Vo2Max string `json:"vo2Max"` // VO2 Max in mL/kg/min
} `json:"value"`
} `json:"cardioScore"`
}
// CardioFitnessScoreByDay returns the cardio fitness score (VO2Max) for a given date
// date must be in the format yyyy-MM-dd, scope ScopeCardioFitness must be granted
func (m *Session) CardioFitnessScoreByDay(date string) (CardioFitnessScoreLog, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/cardioscore/date/%s.json", date))
if err != nil {
return CardioFitnessScoreLog{}, err
}
summary := CardioFitnessScoreLog{}
if err := json.Unmarshal(contents, &summary); err != nil {
return CardioFitnessScoreLog{}, err
}
return summary, nil
}
// CardioFitnessScoreByDateRange returns the cardio fitness score (VO2Max) for the given date range
// date must be in the format yyyy-MM-dd, scope ScopeCardioFitness must be granted
func (m *Session) CardioFitnessScoreByDateRange(startDate, endDate string) (CardioFitnessScoreLog, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/cardioscore/date/%s/%s.json", startDate, endDate))
if err != nil {
return CardioFitnessScoreLog{}, err
}
summary := CardioFitnessScoreLog{}
if err := json.Unmarshal(contents, &summary); err != nil {
return CardioFitnessScoreLog{}, err
}
return summary, nil
}