Documentation
¶
Overview ¶
Package clockify provides a thin, fully-typed HTTP client for the Clockify REST API (https://docs.clockify.me).
Package clockify provides a thin, fully-typed HTTP client for the Clockify REST API (https://docs.clockify.me).
Index ¶
- Constants
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsRateLimited(err error) bool
- func IsUnauthorized(err error) bool
- func Ptr[T any](v T) *T
- type APIError
- type Client
- func (c *Client) CreateTimeEntry(ctx context.Context, workspaceID string, req CreateTimeEntryRequest) (*TimeEntry, error)
- func (c *Client) DeleteTimeEntry(ctx context.Context, workspaceID, entryID string) error
- func (c *Client) GetInProgress(ctx context.Context, workspaceID string) ([]TimeEntry, error)
- func (c *Client) GetProjects(ctx context.Context, workspaceID string) ([]Project, error)
- func (c *Client) GetTimeEntries(ctx context.Context, workspaceID, userID string, params TimeEntryListParams) ([]TimeEntry, error)
- func (c *Client) GetTimeEntry(ctx context.Context, workspaceID, entryID string) (*TimeEntry, error)
- func (c *Client) GetUser(ctx context.Context) (*User, error)
- func (c *Client) GetWorkspaces(ctx context.Context) ([]Workspace, error)
- func (c *Client) StopTimer(ctx context.Context, workspaceID, userID string, end time.Time) (*TimeEntry, error)
- func (c *Client) UpdateTimeEntry(ctx context.Context, workspaceID, entryID string, req UpdateTimeEntryRequest) (*TimeEntry, error)
- type CreateTimeEntryRequest
- type Project
- type ProjectBrief
- type StopTimeEntryRequest
- type TagBrief
- type TaskBrief
- type TimeEntry
- type TimeEntryListParams
- type TimeInterval
- type UpdateTimeEntryRequest
- type User
- type Workspace
Constants ¶
const DefaultBaseURL = "https://api.clockify.me/api/v1"
DefaultBaseURL is the global Clockify API endpoint. Regional workspaces can use a prefixed host instead (e.g. https://euc1.clockify.me/api/v1).
Variables ¶
This section is empty.
Functions ¶
func IsForbidden ¶
IsForbidden reports whether err is a 403 (missing workspace permission).
func IsRateLimited ¶
IsRateLimited reports whether err is a 429 (too many requests).
func IsUnauthorized ¶
IsUnauthorized reports whether err is a 401 (bad or expired API key).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Clockify REST API using an API key (X-Api-Key header).
func NewClient ¶
NewClient returns a Client for baseURL (or DefaultBaseURL when empty) authenticated with apiKey.
func (*Client) CreateTimeEntry ¶
func (c *Client) CreateTimeEntry(ctx context.Context, workspaceID string, req CreateTimeEntryRequest) (*TimeEntry, error)
CreateTimeEntry creates a time entry. Omit End to start a running timer (Clockify then stops any previously running timer). Timestamps are normalized to UTC before sending.
func (*Client) DeleteTimeEntry ¶
DeleteTimeEntry permanently removes a time entry (DELETE, 204 No Content).
func (*Client) GetInProgress ¶
GetInProgress returns the currently running timers on a workspace.
func (*Client) GetProjects ¶
GetProjects lists active projects on a workspace, following pagination (100 per page, up to 50 pages as a safety bound).
func (*Client) GetTimeEntries ¶
func (c *Client) GetTimeEntries(ctx context.Context, workspaceID, userID string, params TimeEntryListParams) ([]TimeEntry, error)
GetTimeEntries lists a user's time entries (newest first). When params.Start or params.End are set, only entries whose *start time* falls inside the window are returned (Clockify filters on entry start, not on overlap).
func (*Client) GetTimeEntry ¶
GetTimeEntry fetches a single time entry by ID.
func (*Client) GetWorkspaces ¶
GetWorkspaces lists the workspaces the authenticated user belongs to.
func (*Client) StopTimer ¶
func (c *Client) StopTimer(ctx context.Context, workspaceID, userID string, end time.Time) (*TimeEntry, error)
StopTimer stops the user's running timer. The PATCH endpoint requires only an end timestamp in the body (the path carries workspace and user IDs).
func (*Client) UpdateTimeEntry ¶
func (c *Client) UpdateTimeEntry(ctx context.Context, workspaceID, entryID string, req UpdateTimeEntryRequest) (*TimeEntry, error)
UpdateTimeEntry edits an existing entry (PUT — note PATCH is reserved for stopping a running timer). Start is required by the API. Timestamps are normalized to UTC before sending.
type CreateTimeEntryRequest ¶
type CreateTimeEntryRequest struct {
Description string `json:"description,omitempty"`
Start *time.Time `json:"start,omitempty"`
End *time.Time `json:"end,omitempty"`
ProjectID string `json:"projectId,omitempty"`
Billable *bool `json:"billable,omitempty"`
TaskID string `json:"taskId,omitempty"`
TagIDs []string `json:"tagIds,omitempty"`
}
CreateTimeEntryRequest is the body for POST /v1/workspaces/{workspaceId}/time-entries. Omit End to start a running timer.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Archived bool `json:"archived"`
Billable bool `json:"billable"`
Color string `json:"color"`
}
Project is a workspace project returned by GET /v1/workspaces/{id}/projects.
type ProjectBrief ¶
type ProjectBrief struct {
ID string `json:"id"`
Name string `json:"name"`
ClientID string `json:"clientId"`
ClientName string `json:"clientName"`
Color string `json:"color"`
}
ProjectBrief is the hydrated project snapshot embedded in time entries when a list request sets hydrated=true.
type StopTimeEntryRequest ¶
StopTimeEntryRequest is the body for PATCH /v1/workspaces/{workspaceId}/user/{userId}/time-entries (stop the running timer). End is the only required field.
type TimeEntry ¶
type TimeEntry struct {
ID string `json:"id"`
Description string `json:"description"`
Billable bool `json:"billable"`
ProjectID string `json:"projectId"`
TaskID string `json:"taskId"`
TagIDs []string `json:"tagIds"`
UserID string `json:"userId"`
WorkspaceID string `json:"workspaceId"`
Type string `json:"type"`
IsLocked bool `json:"isLocked"`
TimeInterval *TimeInterval `json:"timeInterval"`
// Populated when the request sets hydrated=true.
Project *ProjectBrief `json:"project"`
Task *TaskBrief `json:"task"`
Tags []TagBrief `json:"tags"`
}
TimeEntry is a single tracked entry. One struct covers both plain and hydrated responses: hydrated-only fields (Project, Task, Tags) are simply absent otherwise, and TimeEntryInfoDto omits the flat ProjectID/TagIDs.
func (*TimeEntry) EffectiveProjectID ¶
EffectiveProjectID returns the project ID from either the flat or the hydrated representation.
type TimeEntryListParams ¶
type TimeEntryListParams struct {
Page int // 1-indexed; omitted from the query when <= 0
PageSize int // omitted from the query when <= 0
Hydrated bool // embed project/task/tag objects instead of bare IDs
Start *time.Time // only entries starting at/after this time (UTC on the wire)
End *time.Time // only entries starting at/before this time (UTC on the wire)
}
TimeEntryListParams are query options for GetTimeEntries.
type TimeInterval ¶
type TimeInterval struct {
Start *time.Time `json:"start"`
End *time.Time `json:"end"`
Duration string `json:"duration"` // ISO-8601, e.g. "PT1H30M"
}
TimeInterval holds the start/end/duration of a time entry. End is nil while a timer is still running.
type UpdateTimeEntryRequest ¶
type UpdateTimeEntryRequest struct {
Start *time.Time `json:"start"`
Description string `json:"description,omitempty"`
End *time.Time `json:"end,omitempty"`
ProjectID string `json:"projectId,omitempty"`
Billable *bool `json:"billable,omitempty"`
TaskID string `json:"taskId,omitempty"`
TagIDs []string `json:"tagIds,omitempty"`
}
UpdateTimeEntryRequest is the body for PUT /v1/workspaces/{workspaceId}/time-entries/{id}. Start is required by the API; omit optional fields to leave them unchanged.