api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NewService(caller Caller, mode safety.Mode, allowWrite bool) *Service

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.

Jump to

Keyboard shortcuts

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