Documentation
¶
Overview ¶
Package hr provides testable HTTP clients for Moco and Personio APIs. This file implements dependency injection pattern for better testability.
Package hr provides integration with the Moco time tracking API. It allows querying projects, tasks, activities, and users, as well as booking time entries. Moco is a comprehensive time tracking and project management tool.
Features:
- Retrieve projects, tasks, and activities
- Manage user employments and contracts
- Book time entries for users
- Impersonate users when booking time
- Delete time entries
- Custom date handling for Moco's API format
All functions require a valid Moco domain and API token for authentication. The package handles JSON serialization/deserialization with Moco's API format.
Package hr provides integration with the Personio HR management system API. It allows querying employee data, attendance periods, and booking time entries. Personio is a comprehensive HR management platform for modern companies.
Features:
- Authentication with Personio using OAuth2 client credentials
- Retrieval of employee information
- Querying attendance periods and approval statuses
- Booking new attendance periods
- Custom date/time handling for Personio's API format
All functions require valid Personio credentials and environment variables:
- PERSONIO_PARTNER_ID: Your Personio partner ID
- PERSONIO_APP_ID: Your Personio application ID
Index ¶
- func MocoAppBook(domain string, token string, date string, project_id int, task_id int, ...) error
- func MocoAppBookDelete(domain string, token string, activityId int) error
- func MocoAppBookImpersonate(domain string, token string, date string, project_id int, task_id int, ...) error
- func MocoAppNewProjectContract(domain string, token string, project_id int, user MocoUserContract) error
- func PersonioAttendances(token PersonioToken, personId string) error
- func PersonioAttendancesPeriods(token PersonioToken) error
- func PersonioBook(clientId string, clientSecret string, personId string, start string, ...) error
- func PersonioUsers(clientId string, clientSecret string) error
- type HTTPClient
- type MocoActivity
- type MocoClient
- func (c *MocoClient) Activities(projectID, taskID int) ([]MocoActivity, error)
- func (c *MocoClient) AddProjectContract(projectID, userID int) error
- func (c *MocoClient) BookActivity(date string, projectID, taskID, seconds int, description string) error
- func (c *MocoClient) BookActivityImpersonate(date string, projectID, taskID, seconds int, description string, ...) error
- func (c *MocoClient) DeleteActivity(activityID int) error
- func (c *MocoClient) ProjectContracts(projectID int) ([]MocoUserGroup, error)
- func (c *MocoClient) ProjectTasks(projectID int) ([]MocoTask, error)
- func (c *MocoClient) Projects() ([]MocoProject, error)
- func (c *MocoClient) UserEmployments(userID int) ([]MocoUserEmployment, error)
- func (c *MocoClient) Users() ([]MocoUser, error)
- type MocoDate
- type MocoProject
- type MocoTask
- type MocoUser
- type MocoUserContract
- type MocoUserEmployment
- type MocoUserGroup
- type PersonioApproval
- type PersonioAttendance
- type PersonioAttendanceResponse
- type PersonioClient
- type PersonioDate
- type PersonioDateTime
- type PersonioPerson
- type PersonioPersonResponse
- type PersonioToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MocoAppBook ¶
func MocoAppBook(domain string, token string, date string, project_id int, task_id int, seconds int, description string) error
MocoAppBook is a backward-compatible wrapper. Deprecated: Use NewMocoClient().BookActivity() instead.
func MocoAppBookDelete ¶
MocoAppBookDelete is a backward-compatible wrapper. Deprecated: Use NewMocoClient().DeleteActivity() instead.
func MocoAppBookImpersonate ¶
func MocoAppBookImpersonate(domain string, token string, date string, project_id int, task_id int, seconds int, description string, impersonate int) error
MocoAppBookImpersonate is a backward-compatible wrapper. Deprecated: Use NewMocoClient().BookActivityImpersonate() instead.
func MocoAppNewProjectContract ¶
func MocoAppNewProjectContract(domain string, token string, project_id int, user MocoUserContract) error
MocoAppNewProjectContract is a backward-compatible wrapper. Deprecated: Use NewMocoClient().AddProjectContract() instead.
func PersonioAttendances ¶
func PersonioAttendances(token PersonioToken, personId string) error
PersonioAttendances retrieves attendance periods for a specific person with filtering. This function retrieves pending attendance periods for a specific person and logs them.
Parameters:
- token: Valid Personio access token
- personId: ID of the person whose attendances to retrieve
Returns:
- error: If the request or parsing fails
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
func PersonioAttendancesPeriods ¶
func PersonioAttendancesPeriods(token PersonioToken) error
PersonioAttendancesPeriods retrieves all attendance periods from Personio. This function is currently a placeholder that logs the raw API response.
Parameters:
- token: Valid Personio access token
Returns:
- error: If the request fails
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
func PersonioBook ¶
func PersonioBook(clientId string, clientSecret string, personId string, start string, end string) error
PersonioBook books a new attendance period in Personio. This function creates a new WORK type attendance period for a specific person.
Parameters:
- clientId: The client ID for authentication
- clientSecret: The client secret for authentication
- personId: ID of the person for whom to book the attendance
- start: Start date/time in "YYYY-MM-DDTHH:MM:SS" format
- end: End date/time in "YYYY-MM-DDTHH:MM:SS" format
Returns:
- error: If the request fails
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
func PersonioUsers ¶
PersonioUsers retrieves all users from Personio. This function retrieves a list of users and logs their information. For users named "Francisc Simon", it also retrieves their attendance records.
Parameters:
- clientId: The client ID for authentication
- clientSecret: The client secret for authentication
Returns:
- error: If the request or processing fails
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
Types ¶
type HTTPClient ¶ added in v0.0.6
HTTPClient is an interface for making HTTP requests. This allows for easy mocking in tests.
type MocoActivity ¶
type MocoActivity struct {
Id int `json:"id"`
Date MocoDate `json:"date"`
Description string `json:"description"`
ProjectId int `json:"project_id"`
TaskId int `json:"task_id"`
Seconds int `json:"seconds"`
Billable bool `json:"billable"`
Hours float64 `json:"hours"`
Project MocoProject `json:"project"`
User MocoUser `json:"user"`
}
MocoActivity represents a time entry in Moco. Activities track time spent on specific tasks within projects.
func MocoAppActivities ¶
func MocoAppActivities(domain string, token string, project_id int, task_id int) []MocoActivity
MocoAppActivities is a backward-compatible wrapper. Deprecated: Use NewMocoClient().Activities() instead.
type MocoClient ¶ added in v0.0.6
type MocoClient struct {
// contains filtered or unexported fields
}
MocoClient is a client for interacting with the Moco API. It uses dependency injection for the HTTP client to enable testing.
func NewMocoClient ¶ added in v0.0.6
func NewMocoClient(domain, token string) *MocoClient
NewMocoClient creates a new Moco API client.
Parameters:
- domain: The Moco account domain (e.g., "mycompany" for mycompany.mocoapp.com)
- token: API token for authentication
Returns:
- *MocoClient: Configured Moco client
func NewMocoClientWithHTTP ¶ added in v0.0.6
func NewMocoClientWithHTTP(domain, token string, httpClient HTTPClient) *MocoClient
NewMocoClientWithHTTP creates a new Moco API client with a custom HTTP client. This is primarily useful for testing with mock HTTP clients.
Parameters:
- domain: The Moco account domain
- token: API token for authentication
- httpClient: Custom HTTP client implementation
Returns:
- *MocoClient: Configured Moco client
func (*MocoClient) Activities ¶ added in v0.0.6
func (c *MocoClient) Activities(projectID, taskID int) ([]MocoActivity, error)
Activities retrieves activities for a specific project and task.
Parameters:
- projectID: ID of the project
- taskID: ID of the task
Returns:
- []MocoActivity: List of activities
- error: If the request fails
func (*MocoClient) AddProjectContract ¶ added in v0.0.6
func (c *MocoClient) AddProjectContract(projectID, userID int) error
AddProjectContract adds a user to a project as a contractor.
Parameters:
- projectID: ID of the project
- userID: ID of the user to add
Returns:
- error: If the operation fails
func (*MocoClient) BookActivity ¶ added in v0.0.6
func (c *MocoClient) BookActivity(date string, projectID, taskID, seconds int, description string) error
BookActivity books a time entry for a task.
Parameters:
- date: Date in "YYYY-MM-DD" format
- projectID: ID of the project
- taskID: ID of the task
- seconds: Duration in seconds
- description: Activity description
Returns:
- error: If the booking fails
func (*MocoClient) BookActivityImpersonate ¶ added in v0.0.6
func (c *MocoClient) BookActivityImpersonate(date string, projectID, taskID, seconds int, description string, impersonateUserID int) error
BookActivityImpersonate books a time entry on behalf of another user.
Parameters:
- date: Date in "YYYY-MM-DD" format
- projectID: ID of the project
- taskID: ID of the task
- seconds: Duration in seconds
- description: Activity description
- impersonateUserID: ID of user to impersonate
Returns:
- error: If the booking fails
func (*MocoClient) DeleteActivity ¶ added in v0.0.6
func (c *MocoClient) DeleteActivity(activityID int) error
DeleteActivity deletes a time entry.
Parameters:
- activityID: ID of the activity to delete
Returns:
- error: If the deletion fails
func (*MocoClient) ProjectContracts ¶ added in v0.0.6
func (c *MocoClient) ProjectContracts(projectID int) ([]MocoUserGroup, error)
ProjectContracts retrieves all user contracts for a specific project.
Parameters:
- projectID: ID of the project to query
Returns:
- []MocoUserGroup: List of user contracts for the project
- error: If the request fails
func (*MocoClient) ProjectTasks ¶ added in v0.0.6
func (c *MocoClient) ProjectTasks(projectID int) ([]MocoTask, error)
ProjectTasks retrieves all tasks for a specific project.
Parameters:
- projectID: ID of the project to query
Returns:
- []MocoTask: List of tasks
- error: If the request fails
func (*MocoClient) Projects ¶ added in v0.0.6
func (c *MocoClient) Projects() ([]MocoProject, error)
Projects retrieves all projects from the Moco account.
Returns:
- []MocoProject: List of all projects
- error: If the request fails
func (*MocoClient) UserEmployments ¶ added in v0.0.6
func (c *MocoClient) UserEmployments(userID int) ([]MocoUserEmployment, error)
UserEmployments retrieves all employment periods for a specific user.
Parameters:
- userID: ID of the user to query
Returns:
- []MocoUserEmployment: List of employment periods
- error: If the request fails
func (*MocoClient) Users ¶ added in v0.0.6
func (c *MocoClient) Users() ([]MocoUser, error)
Users retrieves all users from the Moco account.
Returns:
- []MocoUser: List of all users
- error: If the request fails
type MocoDate ¶
MocoDate represents a date in Moco's format (YYYY-MM-DD). It implements json.Marshaler and json.Unmarshaler for proper JSON handling.
func (MocoDate) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for MocoDate. It formats the date as "YYYY-MM-DD" for JSON serialization.
func (*MocoDate) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for MocoDate. It parses dates in "YYYY-MM-DD" format from JSON.
type MocoProject ¶
type MocoProject struct {
Id int `json:"id"`
Identifier string `json:"identifier"`
Name string `json:"name"`
Active bool `json:"active"`
Billable bool `json:"billable"`
BillingVariant string `json:"billing_variant"`
StartDate MocoDate `json:"start_date"`
FinishDate MocoDate `json:"finish_date"`
Currency string `json:"currency"`
Tasks []MocoTask `json:"tasks"`
}
MocoProject represents a project in Moco. Projects contain tasks and can have contracts with users.
func MocoAppProjects ¶
func MocoAppProjects(domain string, token string) []MocoProject
MocoAppProjects is a backward-compatible wrapper. Deprecated: Use NewMocoClient().Projects() instead.
type MocoTask ¶
type MocoTask struct {
Id int `json:"id"`
Name string `json:"name"`
Billable bool `json:"billable"`
Active bool `json:"active"`
}
MocoTask represents a task in Moco. Tasks are associated with projects and can be used for time tracking.
type MocoUser ¶
type MocoUser struct {
Id int `json:"id"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
Active bool `json:"active"`
Extern bool `json:"extern"`
Email string `json:"email"`
}
MocoUser represents a user in Moco. Users can book time, be assigned to projects, and have employments.
func MocoAppUsers ¶
MocoAppUsers is a backward-compatible wrapper. Deprecated: Use NewMocoClient().Users() instead.
type MocoUserContract ¶
type MocoUserContract struct {
UserId int `json:"user_id"`
}
MocoUserContract represents a contract between a user and a project. Used when adding users to projects.
type MocoUserEmployment ¶
type MocoUserEmployment struct {
Id int `json:"id"`
WeeklyTargetHours float64 `json:"weekly_target_hours"`
From MocoDate `json:"from"`
To MocoDate `json:"to"`
User MocoUser `json:"user"`
}
MocoUserEmployment represents an employment period for a user in Moco. Employments define working hours and active periods for users.
func MocoUserEmployments ¶
func MocoUserEmployments(domain string, token string, user_id int) []MocoUserEmployment
MocoUserEmployments is a backward-compatible wrapper. Deprecated: Use NewMocoClient().UserEmployments() instead.
type MocoUserGroup ¶
type MocoUserGroup struct {
Id int `json:"id"`
UserId int `json:"user_id"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
Billable bool `json:"billable"`
Active bool `json:"active"`
}
MocoUserGroup represents a user contract for a project in Moco. This shows which users are assigned to which projects.
func MocoAppProjectsContracts ¶
func MocoAppProjectsContracts(domain string, token string, project_id int) []MocoUserGroup
MocoAppProjectsContracts is a backward-compatible wrapper. Deprecated: Use NewMocoClient().ProjectContracts() instead.
type PersonioApproval ¶
type PersonioApproval struct {
Status string `json:"status"`
}
PersonioApproval represents the approval status of an attendance period.
type PersonioAttendance ¶
type PersonioAttendance struct {
Id string `json:"id"`
Start PersonioDate `json:"start"`
End PersonioDate `json:"end"`
AType string `json:"type"`
Approval PersonioApproval `json:"approval"`
}
PersonioAttendance represents an attendance period in Personio. Contains information about the type, timing, and approval status of the attendance.
func PersonioAttendancesPerson ¶
func PersonioAttendancesPerson(token PersonioToken, personId string) []PersonioAttendance
PersonioAttendancesPerson retrieves attendance periods for a specific person. This function is currently a placeholder that logs the raw API response.
Parameters:
- token: Valid Personio access token
- personId: ID of the person whose attendances to retrieve
Returns:
- []PersonioAttendance: Empty slice (function needs implementation)
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
type PersonioAttendanceResponse ¶
type PersonioAttendanceResponse struct {
Data []PersonioAttendance `json:"_data"`
Meta map[string]map[string]interface{} `json:"_meta"`
}
PersonioAttendanceResponse represents the API response for attendance queries. Contains a list of attendance periods and metadata.
type PersonioClient ¶ added in v0.0.6
type PersonioClient struct {
// contains filtered or unexported fields
}
PersonioClient is a client for interacting with the Personio API. It uses dependency injection for the HTTP client to enable testing.
func NewPersonioClient ¶ added in v0.0.6
func NewPersonioClient(clientID, clientSecret string) *PersonioClient
NewPersonioClient creates a new Personio API client. It reads PERSONIO_PARTNER_ID and PERSONIO_APP_ID from environment variables.
Parameters:
- clientID: OAuth client ID
- clientSecret: OAuth client secret
Returns:
- *PersonioClient: Configured Personio client
func NewPersonioClientWithHTTP ¶ added in v0.0.6
func NewPersonioClientWithHTTP(clientID, clientSecret, partnerID, appID string, httpClient HTTPClient) *PersonioClient
NewPersonioClientWithHTTP creates a new Personio API client with a custom HTTP client.
Parameters:
- clientID: OAuth client ID
- clientSecret: OAuth client secret
- partnerID: Personio partner ID
- appID: Personio app ID
- httpClient: Custom HTTP client implementation
Returns:
- *PersonioClient: Configured Personio client
func (*PersonioClient) BookAttendance ¶ added in v0.0.6
func (c *PersonioClient) BookAttendance(personID, start, end string) error
BookAttendance books a new attendance period.
Parameters:
- personID: ID of the person for whom to book
- start: Start date/time in "YYYY-MM-DDTHH:MM:SS" format
- end: End date/time in "YYYY-MM-DDTHH:MM:SS" format
Returns:
- error: If the booking fails
func (*PersonioClient) GetPerson ¶ added in v0.0.6
func (c *PersonioClient) GetPerson(personID string) (PersonioPerson, error)
GetPerson retrieves information about a specific person.
Parameters:
- personID: ID of the person to retrieve
Returns:
- PersonioPerson: The person's information
- error: If the request fails
type PersonioDate ¶
type PersonioDate struct {
DateTime PersonioDateTime `json:"date_time"`
}
PersonioDate represents a date with time in Personio's API format. Used for attendance period start and end times.
type PersonioDateTime ¶
PersonioDateTime represents a date and time in Personio's format (YYYY-MM-DDTHH:MM:SS). It implements json.Marshaler and json.Unmarshaler for proper JSON handling.
func (PersonioDateTime) MarshalJSON ¶
func (d PersonioDateTime) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for PersonioDateTime. It formats the date/time as "YYYY-MM-DDTHH:MM:SS" for JSON serialization.
func (*PersonioDateTime) UnmarshalJSON ¶
func (d *PersonioDateTime) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for PersonioDateTime. It parses dates in "YYYY-MM-DDTHH:MM:SS" format from JSON.
type PersonioPerson ¶
type PersonioPerson struct {
Id string `json:"id"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
PersonioPerson represents an employee in Personio. Contains basic employee information.
func PersonioUser ¶
func PersonioUser(token PersonioToken, personId string) PersonioPerson
PersonioUser retrieves information about a specific person from Personio.
Parameters:
- token: Valid Personio access token
- personId: ID of the person to retrieve
Returns:
- PersonioPerson: The person's information
Environment Variables:
- PERSONIO_PARTNER_ID: Required for the API request
- PERSONIO_APP_ID: Required for the API request
type PersonioPersonResponse ¶
type PersonioPersonResponse struct {
Data []PersonioPerson `json:"_data"`
Meta map[string]map[string]interface{} `json:"_meta"`
}
PersonioPersonResponse represents the API response for person queries. Contains a list of persons and metadata.