personio

package
v0.0.0-...-23fd19e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	UserAgent = "Rootless-Personio-bot/0.1 (+https://github.com/jilleJr/rootless-personio)"
)

Functions

func DoRequest

func DoRequest(client *http.Client, req *http.Request) (*http.Response, error)

func NormalizeBaseURL

func NormalizeBaseURL(baseURL string) (string, error)

func ParseResponseJSON

func ParseResponseJSON[M any](resp *http.Response) (M, error)

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 CalendarDayAttributes struct {
	BreakMin    int    `json:"break_min"`    // Duration of breaks in minutes
	DurationMin int    `json:"duration_min"` // Duration of attendance in minutes
	Status      string `json:"status"`       // ex: "empty"
	Day         string `json:"day"`          // ex: "2023-01-20"
}

type CalendarHoliday

type CalendarHoliday struct {
	HalfDay             bool   `json:"half_day"`
	HolidayCalendarName string `json:"holiday_calendar_name"` // ex: "DE (Hamburg) Feiertage CompanyName"
	ID                  int    `json:"id"`                    // ex: 123456
	Name                string `json:"name"`                  // ex: "2. Weihnachtstag"
	Date                string `json:"date"`                  // ex: "2022-12-26"
}

type Client

type Client struct {
	BaseURL string

	EmployeeID int
	// contains filtered or unexported fields
}

func New

func New(baseURL string) (*Client, error)

func (*Client) DeleteAttendance

func (c *Client) DeleteAttendance(date time.Time) error

func (*Client) GetAttendanceCalendar

func (c *Client) GetAttendanceCalendar(employeeID int, startDate, endDate time.Time) (*AttendanceCalendar, error)

func (*Client) GetDayUUID

func (c *Client) GetDayUUID(date time.Time) (*uuid.UUID, error)

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) GetEmployeeData

func (c *Client) GetEmployeeData(id int) (*Employee, error)

func (*Client) GetMyAttendanceCalendar

func (c *Client) GetMyAttendanceCalendar(startDate, endDate time.Time) (*AttendanceCalendar, error)

func (*Client) GetMyEmployeeData

func (c *Client) GetMyEmployeeData() (*Employee, error)

func (*Client) GetOrNewDayUUID

func (c *Client) GetOrNewDayUUID(date time.Time) (uuid.UUID, error)

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) Login

func (c *Client) Login(email, pass string) error

func (*Client) Raw

func (c *Client) Raw(req *http.Request) (*http.Response, error)

func (*Client) RawForm

func (c *Client) RawForm(req *http.Request) (*http.Response, error)

func (*Client) RawJSON

func (c *Client) RawJSON(req *http.Request) (*http.Response, error)

func (*Client) SetAttendance

func (c *Client) SetAttendance(date time.Time, periods []Period) error

func (*Client) UnlockAndLogin

func (c *Client) UnlockAndLogin(email, pass, emailToken string) error

func (*Client) UnlockWithToken

func (c *Client) UnlockWithToken(emailToken string) error

type Data

type Data[M any] struct {
	Data M `json:"data"`
}

type Employee

type Employee struct {
	ID           int             `json:"id"`
	FirstName    string          `json:"first_name"`
	LastName     string          `json:"last_name"`
	Position     string          `json:"position"`
	Department   string          `json:"department"`
	Office       string          `json:"office"`
	Team         string          `json:"team"`
	AccessRights map[string]bool `json:"access_rights"`
}

type EmployeeProfileImage

type EmployeeProfileImage struct {
	Small    string `json:"small"`
	Medium   string `json:"medium"`
	Large    string `json:"large"`
	Original string `json:"original"`
}

type EmployeeTab

type EmployeeTab struct {
	Name     string `json:"name"`
	Route    string `json:"route"`
	Label    string `json:"label"`
	IsActive bool   `json:"isActive"`
}

type Error

type Error struct {
	Code      int
	Message   string
	ErrorData map[string][]string
	Response  *http.Response
}

func (Error) Error

func (e Error) Error() string

type LockedAccountError

type LockedAccountError struct {
	CSRFToken string
	Response  *http.Response
}

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 (p Period) GetComment() string

func (Period) GetProjectID

func (p Period) GetProjectID() int

type PeriodType

type PeriodType string
const (
	PeriodTypeWork  PeriodType = "work"
	PeriodTypeBreak PeriodType = "break"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL