-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCalendar.go
111 lines (98 loc) · 3.88 KB
/
Calendar.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package connect
import (
"fmt"
)
// CalendarYear describes a Garmin Connect calendar year
type CalendarYear struct {
StartDayOfJanuary int `json:"startDayofJanuary"`
LeapYear bool `json:"leapYear"`
YearItems []YearItem `json:"yearItems"`
YearSummaries []YearSummary `json:"yearSummaries"`
}
// YearItem describes an item on a Garmin Connect calendar year
type YearItem struct {
Date Date `json:"date"`
Display int `json:"display"`
}
// YearSummary describes a per-activity-type yearly summary on a Garmin Connect calendar year
type YearSummary struct {
ActivityTypeID int `json:"activityTypeId"`
NumberOfActivities int `json:"numberOfActivities"`
TotalDistance int `json:"totalDistance"`
TotalDuration int `json:"totalDuration"`
TotalCalories int `json:"totalCalories"`
}
// CalendarMonth describes a Garmin Conenct calendar month
type CalendarMonth struct {
StartDayOfMonth int `json:"startDayOfMonth"`
NumOfDaysInMonth int `json:"numOfDaysInMonth"`
NumOfDaysInPrevMonth int `json:"numOfDaysInPrevMonth"`
Month int `json:"month"`
Year int `json:"year"`
CalendarItems []CalendarItem `json:"calendarItems"`
}
// CalendarWeek describes a Garmin Connect calendar week
type CalendarWeek struct {
StartDate Date `json:"startDate"`
EndDate Date `json:"endDate"`
NumOfDaysInMonth int `json:"numOfDaysInMonth"`
CalendarItems []CalendarItem `json:"calendarItems"`
}
// CalendarItem describes an activity displayed on a Garmin Connect calendar
type CalendarItem struct {
ID int `json:"id"`
ItemType string `json:"itemType"`
ActivityTypeID int `json:"activityTypeId"`
Title string `json:"title"`
Date Date `json:"date"`
Duration int `json:"duration"`
Distance int `json:"distance"`
Calories int `json:"calories"`
StartTimestampLocal Time `json:"startTimestampLocal"`
ElapsedDuration float64 `json:"elapsedDuration"`
Strokes float64 `json:"strokes"`
MaxSpeed float64 `json:"maxSpeed"`
ShareableEvent bool `json:"shareableEvent"`
AutoCalcCalories bool `json:"autoCalcCalories"`
ProtectedWorkoutSchedule bool `json:"protectedWorkoutSchedule"`
IsParent bool `json:"isParent"`
}
// CalendarYear will get the activity summaries and list of days active for a given year
func (c *Client) CalendarYear(year int) (*CalendarYear, error) {
URL := fmt.Sprintf("https://connect.garmin.com/modern/proxy/calendar-service/year/%d",
year,
)
calendarYear := new(CalendarYear)
err := c.getJSON(URL, &calendarYear)
if err != nil {
return nil, err
}
return calendarYear, nil
}
// CalendarMonth will get the activities for a given month
func (c *Client) CalendarMonth(year int, month int) (*CalendarMonth, error) {
URL := fmt.Sprintf("https://connect.garmin.com/modern/proxy/calendar-service/year/%d/month/%d",
year,
month-1, // Months in Garmin Connect start from zero
)
calendarMonth := new(CalendarMonth)
err := c.getJSON(URL, &calendarMonth)
if err != nil {
return nil, err
}
return calendarMonth, nil
}
// CalendarWeek will get the activities for a given week. A week will be returned that contains the day requested, not starting with)
func (c *Client) CalendarWeek(year int, month int, week int) (*CalendarWeek, error) {
URL := fmt.Sprintf("https://connect.garmin.com/modern/proxy/calendar-service/year/%d/month/%d/day/%d/start/1",
year,
month-1, // Months in Garmin Connect start from zero
week,
)
calendarWeek := new(CalendarWeek)
err := c.getJSON(URL, &calendarWeek)
if err != nil {
return nil, err
}
return calendarWeek, nil
}