-
Notifications
You must be signed in to change notification settings - Fork 4
/
temperature.go
92 lines (76 loc) · 2.85 KB
/
temperature.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package fitbit
import (
"encoding/json"
"fmt"
)
// ! ATTENTION !
// As of writing this file, there was no official Swagger documentation available.
// Most parts of this file are based on the not very accurate documentation which may provide different data.
// https://dev.fitbit.com/build/reference/web-api/temperature/
type TemperatureCore struct {
TempCore []struct {
DateTime string `json:"dateTime"`
Value float64 `json:"value"`
} `json:"tempCore"`
}
// TemperatureCoreByDay returns the core temperature data for a given date
// date must be in the format yyyy-MM-dd or today
func (m *Session) TemperatureCoreByDay(day string) (TemperatureCore, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/temp/core/date/%s.json", day))
if err != nil {
return TemperatureCore{}, err
}
temperature := TemperatureCore{}
if err := json.Unmarshal(contents, &temperature); err != nil {
return TemperatureCore{}, err
}
return temperature, nil
}
// TemperatureCoreByDateRange returns the core temperature data for a given date range
// date must be in the format yyyy-MM-dd or today
func (m *Session) TemperatureCoreByDateRange(startDay string, endDay string) (TemperatureCore, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/temp/core/date/%s/%s.json", startDay, endDay))
if err != nil {
return TemperatureCore{}, err
}
temperature := TemperatureCore{}
if err := json.Unmarshal(contents, &temperature); err != nil {
return TemperatureCore{}, err
}
return temperature, nil
}
type TemperatureSkin struct {
TempSkin []struct {
DateTime string `json:"dateTime"`
Value struct {
NightlyRelative float64 `json:"nightlyRelative"`
} `json:"value"`
LogType string `json:"logType"`
} `json:"tempSkin"`
}
// TemperatureSkinByDay returns the skin temperature data for a given date
// date must be in the format yyyy-MM-dd or today
func (m *Session) TemperatureSkinByDay(day string) (TemperatureSkin, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/temp/skin/date/%s.json", day))
if err != nil {
return TemperatureSkin{}, err
}
temperature := TemperatureSkin{}
if err := json.Unmarshal(contents, &temperature); err != nil {
return TemperatureSkin{}, err
}
return temperature, nil
}
// TemperatureSkinByDateRange returns the skin temperature data for a given date range
// date must be in the format yyyy-MM-dd or today
func (m *Session) TemperatureSkinByDateRange(startDay string, endDay string) (TemperatureSkin, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/temp/skin/date/%s/%s.json", startDay, endDay))
if err != nil {
return TemperatureSkin{}, err
}
temperature := TemperatureSkin{}
if err := json.Unmarshal(contents, &temperature); err != nil {
return TemperatureSkin{}, err
}
return temperature, nil
}