-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabsences.go
48 lines (37 loc) · 1.08 KB
/
absences.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 matata
import (
"context"
"fmt"
"net/http"
"strconv"
"time"
)
type AbsenceOptions struct {
Year string
}
type Absence struct {
ID int `json:"id"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
FirstHalfDay bool `json:"first_half_day"`
SecondHalfDay bool `json:"second_half_day"`
IsRecurring bool `json:"is_recurring"`
WeeklyRepeatInterval interface{} `json:"weekly_repeat_interval"`
User User `json:"user"`
Type AbsenceType `json:"absence_type"`
}
type AbsenceList []Absence
func (c *Client) GetAbsences(ctx context.Context, options *AbsenceOptions) (*AbsenceList, error) {
if options.Year == "" {
options.Year = strconv.Itoa(time.Now().Year())
}
req, err := http.NewRequest("GET", fmt.Sprintf("%s/absences?year=%s", c.BaseURL, options.Year), nil)
if err != nil {
return nil, err
}
res := AbsenceList{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}