Documentation ¶
Overview ¶
Package personio is the main client library for accessing Personio as a non-admin user. Use the New function followed by Client.Login to get started.
Example ¶
package main import ( "log" "os" "github.com/jilleJr/rootless-personio/pkg/personio" ) func main() { client, err := personio.New("https://example.personio.de") if err != nil { log.Fatalln("Error creating client:", err) } email := os.Getenv("PERSONIO_EMAIL") password := os.Getenv("PERSONIO_PASS") if email == "" || password == "" { log.Fatalln("Must set env var PERSONIO_EMAIL and PERSONIO_PASS") } if client.Login(email, password); err != nil { log.Fatalln("Error logging in:", err) } log.Println("Logged in as employee ID:", client.EmployeeID) currentEmployee, err := client.GetMyEmployeeData() if err != nil { log.Fatalln("Error fetching employee:", err) } log.Printf("Welcome, %s %s, %s of the %s team!", currentEmployee.FirstName, currentEmployee.LastName, currentEmployee.Position, currentEmployee.Department, ) }
Output:
Index ¶
- Variables
- func DoRequest(client *http.Client, req *http.Request) (*http.Response, error)
- func NormalizeBaseURL(baseURL string) (string, error)
- func ParseResponseJSON[M any](resp *http.Response) (M, error)
- type AttendanceCalendar
- type CalendarAbsencePeriod
- type CalendarAttendancePeriod
- type CalendarAttendancePeriodAttributes
- type CalendarDay
- type CalendarDayAttributes
- type CalendarHoliday
- type Client
- func (c *Client) DeleteAttendance(date time.Time) error
- func (c *Client) GetAttendanceCalendar(employeeID int, startDate, endDate time.Time) (*AttendanceCalendar, error)
- func (c *Client) GetDayUUID(date time.Time) (*uuid.UUID, error)
- func (c *Client) GetEmployeeData(id int) (*Employee, error)
- func (c *Client) GetMyAttendanceCalendar(startDate, endDate time.Time) (*AttendanceCalendar, error)
- func (c *Client) GetMyEmployeeData() (*Employee, error)
- func (c *Client) GetOrNewDayUUID(date time.Time) (uuid.UUID, error)
- func (c *Client) Login(email, pass string) error
- func (c *Client) Raw(req *http.Request) (*http.Response, error)
- func (c *Client) RawForm(req *http.Request) (*http.Response, error)
- func (c *Client) RawJSON(req *http.Request) (*http.Response, error)
- func (c *Client) SetAttendance(date time.Time, periods []Period) error
- func (c *Client) UnlockAndLogin(email, pass, emailToken string) error
- func (c *Client) UnlockWithToken(emailToken string) error
- type Data
- type Employee
- type EmployeeProfileImage
- type EmployeeTab
- type Error
- type LockedAccountError
- type Period
- type PeriodType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnexpectedRedirect = errors.New("unexpected redirect") ErrEmployeeIDNotFound = errors.New("employee ID not found") ErrCSRFTokenNotFound = errors.New("CSRF token not found") ErrNotLoggedIn = errors.New("not logged in") ErrNon2xxStatusCode = errors.New("non-2xx status code") )
var (
UserAgent = "Rootless-Personio-bot/0.1 (+https://github.com/jilleJr/rootless-personio)"
)
Functions ¶
func NormalizeBaseURL ¶
Types ¶
type AttendanceCalendar ¶
type AttendanceCalendar struct { AttendanceRights map[string]bool `json:"attendance_rights"` EmployeeWorkingSchedules struct{} `json:"employee_working_schedules"` AttendanceDays Data[[]CalendarDay] `json:"attendance_days"` AttendancePeriods Data[[]CalendarAttendancePeriod] `json:"attendance_periods"` OvertimeItems struct{} `json:"overtime_items"` AttendanceAlerts struct{} `json:"attendance_alerts"` AbsencePeriods Data[[]CalendarAbsencePeriod] `json:"absence_periods"` Holidays Data[[]CalendarHoliday] `json:"holidays"` }
type CalendarAbsencePeriod ¶
type CalendarAbsencePeriod struct { ID string `json:"id"` // ex: "123456789" Name string `json:"name"` // ex: "Paid vacation" TracksOvertime bool `json:"tracks_overtime"` MeasurementUnit string `json:"measurement_unit"` // ex: "day" StartDate string `json:"start_date"` // ex: "2022-12-22" StartTime string `json:"start_time"` // ex: "2022-12-22 00:00:00" EndDate string `json:"end_date"` // ex: "2022-12-28" EndTime string `json:"end_time"` // ex: "2022-12-29 00:00:00" EffectiveDurationInMinutes *int `json:"effective_duration_in_minutes"` HalfDayStart bool `json:"half_day_start"` HalfDayEnd bool `json:"half_day_end"` }
type CalendarAttendancePeriod ¶
type CalendarAttendancePeriod struct { ID uuid.UUID `json:"id"` // ex: "bc1edc0c-44ef-467f-89a0-10d0733efec5" Attributes CalendarAttendancePeriodAttributes `json:"attributes"` }
type CalendarAttendancePeriodAttributes ¶
type CalendarAttendancePeriodAttributes struct { AttendanceDayID uuid.UUID `json:"attendance_day_id"` // ex: "81954d73-0b0d-4053-a5dc-937bdd62f9f7" Comment *string `json:"comment"` // ex: "" End string `json:"end"` // ex: "2023-01-18T17:00:00Z" LegacyBreakMin int `json:"legacy_break_min"` // ex: 0 PeriodType string `json:"period_type"` // ex: "work" ProjectID *int `json:"project_id"` Start string `json:"start"` // ex: "2023-01-18T13:00:00Z" }
type CalendarDay ¶
type CalendarDay struct { ID uuid.UUID `json:"id"` // ex: "d5bb4b32-c499-4f79-a534-93481505bd60" Attributes CalendarDayAttributes `json:"attributes"` }
type CalendarDayAttributes ¶
type CalendarHoliday ¶
type Client ¶
func (*Client) GetAttendanceCalendar ¶
func (*Client) GetDayUUID ¶
GetDayUUID will lookup a day's ID (from cache or by querying the API), or nil if it is undefined.
The Personio API want the client to generate the IDs, so an undefined day ID means you are free to generate your own ID.
After the remote lookup to the API, the client caches which days in the same month that has undefined IDs.
func (*Client) GetMyAttendanceCalendar ¶
func (c *Client) GetMyAttendanceCalendar(startDate, endDate time.Time) (*AttendanceCalendar, error)
func (*Client) GetMyEmployeeData ¶
func (*Client) GetOrNewDayUUID ¶
GetOrNewDayUUID will either lookup a day's ID (from cache or by querying the API), or generate a new ID and store this new ID in cache.
After the remote lookup to the API, the client caches which days in the same month that has undefined IDs.
func (*Client) SetAttendance ¶
func (*Client) UnlockAndLogin ¶
func (*Client) UnlockWithToken ¶
type EmployeeProfileImage ¶
type EmployeeTab ¶
type LockedAccountError ¶
func (LockedAccountError) Error ¶
func (e LockedAccountError) Error() string
type Period ¶
type Period struct { ID uuid.UUID `json:"id"` // ex: "46365bc8-482a-41b2-8d36-68491140edd9" PeriodType PeriodType `json:"period_type"` // ex: "work" Comment *string `json:"comment"` // ex: "" ProjectID *int `json:"project_id"` // ex: null Start time.Time `json:"start"` // ex: "2023-01-18T08:00:00Z" End time.Time `json:"end"` // ex: "2023-01-18T12:00:00Z" // Required by the HTTP API, but seemingly unused LegacyBreakMin int `json:"legacy_break_min"` // ex: 0 }
func (Period) GetComment ¶
func (Period) GetProjectID ¶
type PeriodType ¶
type PeriodType string
const ( PeriodTypeWork PeriodType = "work" PeriodTypeBreak PeriodType = "break" )