Help us shape the future of Go! Take the 2026 Go Developer Survey

d2l

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package d2l is a minimal Brightspace Valence API client authenticated with browser session cookies.

Index

Constants

View Source
const (
	ActivityFile    = 1
	ActivityLink    = 2
	ActivityDropbox = 3
	ActivityQuiz    = 4
	ActivityLTI     = 7
)

Activity types from the Valence content API.

Variables

View Source
var ErrStalled = errors.New("connection stalled")

ErrStalled means a response stopped sending data.

View Source
var ErrUnauthorized = errors.New("session expired or invalid; run `d2l login`")

ErrUnauthorized means the session is missing or expired.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status int
	Path   string
	Body   string
}

APIError is a non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

type Attachment

type Attachment struct {
	FileID   int    `json:"FileId"`
	FileName string `json:"FileName"`
	Size     int64  `json:"FileSize"`
}

type Client

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

func New

func New(baseURL string, cookies []*http.Cookie) (*Client, error)

New builds a client that sends cookies for baseURL and refuses to follow redirects to the login page.

func (*Client) AbsURL

func (c *Client) AbsURL(u string) string

AbsURL resolves a possibly relative topic URL against the instance.

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) CourseWebURL

func (c *Client) CourseWebURL(orgUnit int) string

CourseWebURL is the course home page.

func (*Client) Courses

func (c *Client) Courses(ctx context.Context) ([]Course, error)

Courses returns every course offering enrollment (org unit type 3).

func (*Client) DropboxFolders

func (c *Client) DropboxFolders(ctx context.Context, orgUnit int) ([]DropboxFolder, error)

func (*Client) DropboxWebURL

func (c *Client) DropboxWebURL(orgUnit, folderID int) string

DropboxWebURL is the submission page for an assignment folder.

func (*Client) FinalGrade

func (c *Client) FinalGrade(ctx context.Context, orgUnit int) (*GradeValue, error)

FinalGrade returns the user's final course grade, or nil when the course has none or it is not released yet.

func (*Client) Grades

func (c *Client) Grades(ctx context.Context, orgUnit int) ([]GradeValue, error)

func (*Client) ModuleWebURL

func (c *Client) ModuleWebURL(orgUnit, moduleID int) string

ModuleWebURL is the content page for a module.

func (*Client) MySubmissions

func (c *Client) MySubmissions(ctx context.Context, orgUnit, folderID int) ([]MySubmission, error)

func (*Client) News

func (c *Client) News(ctx context.Context, orgUnit int) ([]NewsItem, error)

func (*Client) NewsAttachment

func (c *Client) NewsAttachment(ctx context.Context, orgUnit, newsID, fileID int) (*http.Response, error)

NewsAttachment opens an announcement attachment. The caller closes the body.

func (*Client) OffSite

func (c *Client) OffSite(resp *http.Response) bool

OffSite reports whether resp came from a host other than Learn, which for an HTML page means a redirect to the sign-in page.

func (*Client) TOC

func (c *Client) TOC(ctx context.Context, orgUnit int) (*TOC, error)

func (*Client) TopicFile

func (c *Client) TopicFile(ctx context.Context, orgUnit, topicID int) (*http.Response, error)

TopicFile opens the file behind a File topic. The caller closes the body.

func (*Client) TopicWebURL

func (c *Client) TopicWebURL(orgUnit, topicID int) string

TopicWebURL is the Learn page for a topic, for opening in a browser.

func (*Client) WhoAmI

func (c *Client) WhoAmI(ctx context.Context) (*WhoAmI, error)

type Course

type Course struct {
	OrgUnit struct {
		ID   int    `json:"Id"`
		Name string `json:"Name"`
		Code string `json:"Code"`
		Type struct {
			ID   int    `json:"Id"`
			Code string `json:"Code"`
		} `json:"Type"`
		HomeURL string `json:"HomeUrl"`
	} `json:"OrgUnit"`
	Access struct {
		IsActive     bool       `json:"IsActive"`
		CanAccess    bool       `json:"CanAccess"`
		StartDate    *time.Time `json:"StartDate"`
		EndDate      *time.Time `json:"EndDate"`
		LastAccessed *time.Time `json:"LastAccessed"`
	} `json:"Access"`
	PinDate *time.Time `json:"PinDate"`
}

Course is one enrollment returned by myenrollments.

func (Course) Code

func (c Course) Code() string

func (Course) Current

func (c Course) Current() bool

func (Course) ID

func (c Course) ID() int

func (Course) Name

func (c Course) Name() string

func (Course) Pinned

func (c Course) Pinned() bool

type DropboxFolder

type DropboxFolder struct {
	ID                 int        `json:"Id"`
	Name               string     `json:"Name"`
	DueDate            *time.Time `json:"DueDate"`
	IsHidden           bool       `json:"IsHidden"`
	CustomInstructions RichText   `json:"CustomInstructions"`
	Availability       *struct {
		StartDate *time.Time `json:"StartDate"`
		EndDate   *time.Time `json:"EndDate"`
	} `json:"Availability"`
	Assessment *struct {
		ScoreDenominator *float64 `json:"ScoreDenominator"`
	} `json:"Assessment"`
}

type FlatTopic

type FlatTopic struct {
	Path  []string // module titles, outermost first
	Topic Topic
}

FlatTopic is a topic with the module titles leading to it.

type GradeValue

type GradeValue struct {
	GradeObjectIdentifier string   `json:"GradeObjectIdentifier"`
	GradeObjectName       string   `json:"GradeObjectName"`
	GradeObjectTypeName   string   `json:"GradeObjectTypeName"`
	DisplayedGrade        string   `json:"DisplayedGrade"`
	PointsNumerator       *float64 `json:"PointsNumerator"`
	PointsDenominator     *float64 `json:"PointsDenominator"`
	WeightedNumerator     *float64 `json:"WeightedNumerator"`
	WeightedDenominator   *float64 `json:"WeightedDenominator"`
	Comments              RichText `json:"Comments"`
}

type Module

type Module struct {
	ModuleID         int        `json:"ModuleId"`
	Title            string     `json:"Title"`
	SortOrder        int        `json:"SortOrder"`
	IsHidden         bool       `json:"IsHidden"`
	IsLocked         bool       `json:"IsLocked"`
	LastModifiedDate *time.Time `json:"LastModifiedDate"`
	Modules          []Module   `json:"Modules"`
	Topics           []Topic    `json:"Topics"`
}

func (*Module) Children

func (m *Module) Children() []Node

Children returns submodules and topics merged by SortOrder.

func (*Module) Walk

func (m *Module) Walk(prefix []string) []FlatTopic

Walk returns every topic under m, depth first, in display order. prefix is prepended to each Path.

type MySubmission

type MySubmission struct {
	Submissions []struct {
		ID             int        `json:"Id"`
		SubmissionDate *time.Time `json:"SubmissionDate"`
	} `json:"Submissions"`
	Feedback *struct {
		Score *float64 `json:"Score"`
	} `json:"Feedback"`
}

Submission status for one dropbox folder, from mysubmissions. Status is left out: the docs disagree on whether it is a number or a string, and Submissions and Feedback say all the app needs.

type NewsItem

type NewsItem struct {
	ID          int          `json:"Id"`
	Title       string       `json:"Title"`
	Body        RichText     `json:"Body"`
	StartDate   *time.Time   `json:"StartDate"`
	IsHidden    bool         `json:"IsHidden"`
	IsPublished bool         `json:"IsPublished"`
	Attachments []Attachment `json:"Attachments"`
}

type Node

type Node struct {
	Module *Module
	Topic  *Topic
}

Node is either a module or a topic, in display order.

func (Node) Title

func (n Node) Title() string

type RichText

type RichText struct {
	Text string `json:"Text"`
	HTML string `json:"Html"`
}

RichText is D2L's {Text, Html} pair.

type TOC

type TOC struct {
	Modules []Module `json:"Modules"`
}

func (*TOC) Root

func (t *TOC) Root() *Module

Root returns the top-level modules as a synthetic module.

type Topic

type Topic struct {
	TopicID          int        `json:"TopicId"`
	Title            string     `json:"Title"`
	TypeIdentifier   string     `json:"TypeIdentifier"` // "File" or "Link"
	URL              string     `json:"Url"`
	SortOrder        int        `json:"SortOrder"`
	ActivityType     int        `json:"ActivityType"`
	IsBroken         bool       `json:"IsBroken"`
	IsHidden         bool       `json:"IsHidden"`
	IsLocked         bool       `json:"IsLocked"`
	Unread           bool       `json:"Unread"`
	LastModifiedDate *time.Time `json:"LastModifiedDate"`
	StartDateTime    *time.Time `json:"StartDateTime"`
	EndDateTime      *time.Time `json:"EndDateTime"`
}

func (Topic) Available

func (t Topic) Available(now time.Time) bool

Available reports whether the user can open the topic at now. Learn lists topics that are locked or outside their dates but refuses to serve them.

func (Topic) IsFile

func (t Topic) IsFile() bool

IsFile reports whether the topic is backed by a downloadable file.

type WhoAmI

type WhoAmI struct {
	Identifier string `json:"Identifier"`
	FirstName  string `json:"FirstName"`
	LastName   string `json:"LastName"`
	UniqueName string `json:"UniqueName"`
}

Jump to

Keyboard shortcuts

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