comindwork

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 11 Imported by: 0

README

comindwork-go

Go client library for the ComindWork (Extranet) REST API.

Installation

go get github.com/Hukyl/comindwork-go

Usage

package main

import (
	"fmt"
	"log"

	comindwork "github.com/Hukyl/comindwork-go"
)

func main() {
	client := comindwork.NewClient(
		"https://extranet2.newtonideas.com/api",
		"Europe/Kiev",
	)
	client.SetAuthToken("your-auth-token")

	// List records with a filter
	records, err := client.ListScopedRecords("WORKSPACE", "TASK", comindwork.ListOptions{
		ListOfFields: "ALL",
		LimitRecords: 10,
	})
	if err != nil {
		log.Fatal(err)
	}

	for _, rec := range records {
		fmt.Println(rec.GetString("title"))
	}
}

License

MIT

Documentation

Index

Constants

View Source
const (
	AppAliasTask    = "TASK"
	AppAliasTimelog = "TIMELOG"
	AppAliasWorkday = "WORKDAY"
	AppAliasUser    = "USER"
)

App aliases used in scoped URLs (/w/{ws}/a/{app}/...)

View Source
const (
	AppIDTask    = "v2-app-task"
	AppIDTimelog = "v2-hr-timelog"
	AppIDWorkday = "v2-hr-workday"
	AppIDUser    = "default-app-guser"
)

App IDs used in API responses and record identification

View Source
const (
	TransitionAdd    = "add"
	TransitionEdit   = "edit"
	TransitionDelete = "delete"
)

Transitions for /tickets/multi operations

View Source
const (
	// ISO8601Layout is the time format used by ComindWork API
	ISO8601Layout = "2006-01-02T15:04:05.000Z"
	// DateLayout is the date format used for workday dates
	DateLayout = "2006-01-02"
)
View Source
const (
	AuthPrefix = "CMW_AUTH_CODE"
)

Auth

Variables

This section is empty.

Functions

func CalculateTotalReal

func CalculateTotalReal(start, end time.Time) float64

CalculateTotalReal calculates the duration in hours between start and end times

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats a time.Time to the date format expected by ComindWork API

func FormatISO8601

func FormatISO8601(t time.Time) string

FormatISO8601 formats a time.Time to the ISO8601 format expected by ComindWork API

func FormatTaskReference

func FormatTaskReference(workspaceAlias string, taskNumber int) string

FormatTaskReference formats a workspace alias and task number into a task reference string

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate parses a date string from the ComindWork API

func ParseISO8601

func ParseISO8601(s string) (time.Time, error)

ParseISO8601 parses a timestamp string from the ComindWork API

func ParseTaskReference

func ParseTaskReference(ref string) (workspaceAlias string, taskNumber int, err error)

ParseTaskReference parses a task reference string like "NICI/TASK167" Returns the workspace alias and task number, or an error if the format is invalid

Types

type APIClient

type APIClient struct {
	// contains filtered or unexported fields
}

APIClient is the ComindWork (Extranet) API client

func NewClient

func NewClient(baseURL, timeZone string) *APIClient

NewClient creates a new ComindWork API client

func (*APIClient) CreateRecords

func (c *APIClient) CreateRecords(records []map[string]any) ([]MultiResult, error)

CreateRecords creates one or more records via /tickets/multi. Each record should be a flat map with workspace_alias, app_alias, and field values.

func (*APIClient) CreateTimeLog

func (c *APIClient) CreateTimeLog(workspaceAlias, workdayID string, startOn, finishOn time.Time, title string) (*TimeLog, error)

CreateTimeLog creates a new timelog entry

func (*APIClient) CreateTimeLogForDate

func (c *APIClient) CreateTimeLogForDate(workspaceAlias string, date time.Time, startOn, finishOn time.Time, title string) (*TimeLog, error)

CreateTimeLogForDate is a convenience method that creates a timelog for a specific date, automatically finding or creating the workday first

func (*APIClient) DeleteTimeLog

func (c *APIClient) DeleteTimeLog(id string) error

DeleteTimeLog deletes a timelog entry

func (*APIClient) GetOrCreateWorkday

func (c *APIClient) GetOrCreateWorkday(workspaceAlias string, date time.Time) (*Workday, error)

GetOrCreateWorkday finds an existing workday for the given date or creates a new one

func (*APIClient) GetRecord

func (c *APIClient) GetRecord(id string, listOfFields string) (Record, error)

GetRecord retrieves a single record by its ID.

func (*APIClient) GetRecordByNumber

func (c *APIClient) GetRecordByNumber(workspaceAlias, appAlias string, number int, listOfFields string) (Record, error)

GetRecordByNumber retrieves a single record by its workspace-scoped number.

func (*APIClient) GetWorkspaceByAlias

func (c *APIClient) GetWorkspaceByAlias(alias string) (*Workspace, error)

GetWorkspaceByAlias returns a workspace by its alias from the cache

func (*APIClient) ListRecords

func (c *APIClient) ListRecords(opts ListOptions) ([]Record, error)

ListRecords retrieves records using the global /tickets/list endpoint.

func (*APIClient) ListTimeLogs

func (c *APIClient) ListTimeLogs(workspaceAlias, workdayID string) ([]TimeLog, error)

ListTimeLogs retrieves all timelogs for a workday

func (*APIClient) ListTimeLogsByDateRange

func (c *APIClient) ListTimeLogsByDateRange(startDate, endDate time.Time, opts ListOptions) ([]TimeLog, error)

ListTimeLogsByDateRange retrieves timelogs within a date range.

func (*APIClient) ListTimeLogsForDate

func (c *APIClient) ListTimeLogsForDate(workspaceAlias string, date time.Time) ([]TimeLog, error)

ListTimeLogsForDate is a convenience method that lists all timelogs for a specific date

func (*APIClient) ListUsers

func (c *APIClient) ListUsers(opts ListOptions) ([]Record, error)

ListUsers retrieves user records via the /aid/default-app-guser/tickets/list endpoint.

func (*APIClient) ListWorkdays

func (c *APIClient) ListWorkdays(workspaceAlias string, startDate, endDate time.Time) ([]Workday, error)

ListWorkdays retrieves workdays for a workspace within a date range

func (*APIClient) RegisterWorkspace

func (c *APIClient) RegisterWorkspace(workspace *Workspace)

RegisterWorkspace registers a workspace in the cache for lookup by alias

func (*APIClient) SetAuthToken

func (c *APIClient) SetAuthToken(token string)

SetAuthToken sets the bearer token for API authentication

func (*APIClient) UpdateRecords

func (c *APIClient) UpdateRecords(records []map[string]any) ([]MultiResult, error)

UpdateRecords updates one or more records via /tickets/multi. Each record should have at least "id" and "transition" fields.

func (*APIClient) UpdateTimeLog

func (c *APIClient) UpdateTimeLog(id string, startOn, finishOn time.Time, title string) error

UpdateTimeLog updates an existing timelog entry

type ListOptions

type ListOptions struct {
	ListOfFields string // Comma-separated field names, or "ALL"
	LimitRecords int    // Max number of records to return (0 = server default)
	Filter       string // rlx filter expression
	SortBy       string // Sort expression, e.g. "creation_date desc"
}

ListOptions encapsulates query parameters for /tickets/list endpoints.

type MultiResult

type MultiResult struct {
	Created       bool           `json:"created,omitempty"`
	Updated       bool           `json:"updated,omitempty"`
	Successful    bool           `json:"successful"`
	Data          Record         `json:"data,omitempty"`
	Warnings      []MultiWarning `json:"warnings,omitempty"`
	TransactionID string         `json:"transactionId,omitempty"`
}

MultiResult represents a single item in the response array from /tickets/multi.

type MultiWarning

type MultiWarning struct {
	Message  string `json:"message"`
	Severity int    `json:"severity"`
}

MultiWarning represents a warning in a MultiResult.

type Record

type Record map[string]any

Record represents a generic API record returned as a flat JSON object. The official API returns records with snake_case field names.

func (Record) GetFloat

func (r Record) GetFloat(key string) float64

GetFloat extracts a float64 field from the record.

func (Record) GetInt

func (r Record) GetInt(key string) int

GetInt extracts an integer field from the record (JSON numbers are float64).

func (Record) GetString

func (r Record) GetString(key string) string

GetString extracts a string field from the record.

type Task

type Task struct {
	WorkspaceAlias string `json:"workspaceAlias"`
	TaskNumber     int    `json:"taskNumber"`
	TaskID         string `json:"taskId,omitempty"`
}

Task represents a task reference parsed from "WORKSPACE/TASKnnn" format

func (Task) String

func (t Task) String() string

type TimeLog

type TimeLog struct {
	ID           string    `json:"id"`
	WorkdayID    string    `json:"workdayId"`
	WorkspaceID  string    `json:"workspaceId"`
	Title        string    `json:"title"`
	StartOn      time.Time `json:"startOn"`
	FinishOn     time.Time `json:"finishOn"`
	TotalReal    float64   `json:"totalReal"` // Duration in hours
	Task         *Task     `json:"task,omitempty"`
	UpdateDate   time.Time `json:"updateDate,omitempty"`
	ProjectAlias string    `json:"projectAlias,omitempty"`
	Number       int       `json:"number,omitempty"`
}

TimeLog represents a time entry in ComindWork

func (TimeLog) String

func (t TimeLog) String() string

type User

type User struct {
	ID        string `json:"id"`
	Email     string `json:"email,omitempty"`
	Name      string `json:"name,omitempty"`
	FirstName string `json:"firstName,omitempty"`
	LastName  string `json:"lastName,omitempty"`
	Title     string `json:"title,omitempty"`
}

User represents a ComindWork user/account

func (User) String

func (u User) String() string

type Workday

type Workday struct {
	ID          string     `json:"id"`
	WorkspaceID string     `json:"workspaceId"`
	Date        time.Time  `json:"date"`
	TimeLogs    []*TimeLog `json:"timeLogs,omitempty"`
}

Workday represents a daily container for timelogs

func (Workday) String

func (w Workday) String() string

type Workspace

type Workspace struct {
	ID    string `json:"id"`
	Alias string `json:"alias"`
	Name  string `json:"name,omitempty"`
}

Workspace represents a ComindWork workspace/project

func (Workspace) String

func (w Workspace) String() string

Jump to

Keyboard shortcuts

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