Documentation
¶
Overview ¶
Package api is the escape hatch: calling a web service function directly.
It exists because no client will ever cover every function a Moodle site exposes — a site with plugins exposes functions this project has never heard of. Everything else here is a typed command with a checked contract; this is the door out of that, and it is deliberately narrower to walk through.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller interface {
Call(ctx context.Context, function string, params map[string]any) (json.RawMessage, error)
}
Caller sends one function call and hands back what the site said, unread.
type Function ¶
type Function struct {
Name string
Version string
// Reviewed reports whether this project has looked at the function. An
// unreviewed function is not an unknown quantity to be tried hopefully: it
// is assumed to write and is never retried.
Reviewed bool
Mutates bool
Retry string
// Why records the reasoning behind a reviewed entry, so a caller can judge
// it rather than trust it. Empty for anything unreviewed.
Why string
}
Function is one function a site exposes, with what is known about it.
func Functions ¶
func Functions(capabilities *site.Capabilities) []Function
Functions lists what the site exposes, in name order.
type Result ¶
type Result struct {
Function string
// Params is what was sent, so a dry run has something to show and a real
// call can be reproduced.
Params map[string]any
// Response is exactly what the site returned, unread. There is no typed
// contract for an arbitrary function, and inventing one would be a promise
// this project cannot keep.
Response json.RawMessage
// Planned reports that nothing was sent.
Planned bool
// NeedsAllowWrite reports that a real run of this call would be refused
// without --allow-write. Only meaningful for a plan.
NeedsAllowWrite bool
Policy Function
}
Result is one call's outcome.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service lists and calls functions.
func NewService ¶
NewService builds the use case.
func (*Service) Call ¶
func (s *Service) Call(ctx context.Context, capabilities *site.Capabilities, function string, params map[string]any, dryRun bool) (Result, error)
Call sends one function call.
A function this project has not reviewed is treated as a write. That is the whole point: a site's plugins can expose anything, and the alternative is guessing with someone else's coursework. So the caller has to say --allow-write for anything not known to be a read, which turns "I did not realise that wrote" into a decision someone made on purpose.