This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
company_holidays.go
56 lines (45 loc) · 1.32 KB
/
company_holidays.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
package factorial
import (
"encoding/json"
)
const (
companyHolidayURL = "/api/v1/company_holidays"
)
// CompanyHoliday holds the basic information related
// with the company holidays in Factorial
type CompanyHoliday struct {
ID int `json:"id"`
Summary string `json:"summary"`
Description string `json:"description"`
Date string `json:"date"`
HalfDay string `json:"half_day"`
LocationID int `json:"location_id"`
}
// GetCompanyHoliday will get the company holiday linked
// to the given id
func (c Client) GetCompanyHoliday(id string) (CompanyHoliday, error) {
var companyHoliday CompanyHoliday
resp, err := c.get(companyHolidayURL+"/"+id, nil)
if err != nil {
return companyHoliday, err
}
defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(&companyHoliday); err != nil {
return companyHoliday, err
}
return companyHoliday, nil
}
// ListCompanyHolidays will get all the company holidays saved
// in Factorial
func (c Client) ListCompanyHolidays() ([]CompanyHoliday, error) {
var companyHolidays []CompanyHoliday
resp, err := c.get(companyHolidayURL, nil)
if err != nil {
return companyHolidays, err
}
defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(&companyHolidays); err != nil {
return companyHolidays, err
}
return companyHolidays, nil
}