feat: merge oo-cli and extend library with Calendar/CRM/subtasks/files
- Add Calendar helpers (ListCalendars/ListEvents/AddEvent/DeleteEvent) - Add CRM helpers: contacts, opportunities, cases, CRM tasks, history notes - Add project-task extras (ListTasks/ListAllTasks/GetTaskByID/AddTask/ AddSubtask/UpdateTaskStatus/DeleteTask, GetProjectByID) - Add UploadOpportunityFile (multipart) and SelfUserID caching - Introduce Defaults struct, SetDefaults, GetEnvironmentDefaults; GetEnvironmentCredentials now accepts ONLYOFFICE_HOST/NAME/PASSWORD aliases - Add public Authenticate() helper that eagerly primes the token - Bundle Cobra CLI at cmd/oo-cli with full command surface (calendar, tasks, subtasks, CRM, applications-sync); CLI-only deps (cobra, godotenv) kept out of the library surface - Add httptest-based unit tests for form/multipart helpers - Docs: CHANGELOG, AGENTS, .env.example, README updates for v0.3 features Consolidates the standalone eSlider/oo-cli tool into this canonical Go module (see eSlider/inventar ASR-0008). Made-with: Cursor
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
package onlyoffice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ListCalendars returns calendars/events for the given date span (YYYY-MM-DD).
|
||||
// Empty start/end fall back to a wide default window (2020-01-01..2030-12-31),
|
||||
// matching the Python reference implementation.
|
||||
func (c *Client) ListCalendars(ctx context.Context, start, end string) ([]map[string]any, error) {
|
||||
if start == "" {
|
||||
start = "2020-01-01"
|
||||
}
|
||||
if end == "" {
|
||||
end = "2030-12-31"
|
||||
}
|
||||
path := fmt.Sprintf("/api/2.0/calendar/calendars/%s/%s.json", url.PathEscape(start), url.PathEscape(end))
|
||||
return c.ResponseArray(ctx, path)
|
||||
}
|
||||
|
||||
// ListEvents is an alias for ListCalendars; retained for the Python-port CLI.
|
||||
func (c *Client) ListEvents(ctx context.Context, start, end string) ([]map[string]any, error) {
|
||||
return c.ListCalendars(ctx, start, end)
|
||||
}
|
||||
|
||||
// AddEvent creates a simple one-shot calendar event. When calendarID is empty
|
||||
// the configured default (SetDefaults or GetEnvironmentDefaults) is used.
|
||||
// Start/end timestamps are forwarded verbatim (OnlyOffice accepts ISO 8601).
|
||||
func (c *Client) AddEvent(ctx context.Context, calendarID, title, start, end, description string, allDay bool) (map[string]any, error) {
|
||||
if calendarID == "" {
|
||||
calendarID = c.defaults.CalendarID
|
||||
}
|
||||
if calendarID == "" {
|
||||
return nil, fmt.Errorf("AddEvent: calendarID is required (pass explicitly or set via SetDefaults)")
|
||||
}
|
||||
fields := url.Values{}
|
||||
fields.Set("name", title)
|
||||
fields.Set("description", description)
|
||||
fields.Set("startDate", start)
|
||||
fields.Set("endDate", end)
|
||||
fields.Set("repeatType", "")
|
||||
fields.Set("alertType", "0")
|
||||
fields.Set("isAllDayLong", fmt.Sprintf("%t", allDay))
|
||||
raw, err := c.postForm(ctx, fmt.Sprintf("/api/2.0/calendar/%s/event.json", url.PathEscape(calendarID)), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := responseField(raw, "response")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var arr []map[string]any
|
||||
if err := json.Unmarshal(resp, &arr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(arr) == 0 {
|
||||
return nil, fmt.Errorf("AddEvent: empty response")
|
||||
}
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
// DeleteEvent removes a single calendar event by its event ID.
|
||||
func (c *Client) DeleteEvent(ctx context.Context, eventID string) (map[string]any, error) {
|
||||
raw, err := c.deleteReq(ctx, fmt.Sprintf("/api/2.0/calendar/events/%s.json", url.PathEscape(eventID)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := responseField(raw, "response")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out map[string]any
|
||||
_ = json.Unmarshal(resp, &out)
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user