moodle

package module
v0.0.0-...-0c641a7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 15 Imported by: 0

README

moodle

Tests Workflow codecov Go Report Card

Go Moodle API Client

Example

package main

import (
	"context"
	"fmt"
	"github.com/k-yomo/moodle"
	"net/url"
)

func main() {
	ctx := context.Background()
	serviceURL, err := url.Parse("https://my.uopeople.edu")
	if err != nil {
		panic(err)
	}
	moodleClient, err := moodle.NewClientWithLogin(
		ctx,
		serviceURL,
		"SXXXXXX",
		"password",
	)
	if err != nil {
		panic(err)
	}

	siteInfo, err := moodleClient.SiteAPI.GetSiteInfo(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", siteInfo)

	courses, err := moodleClient.CourseAPI.GetEnrolledCoursesByTimelineClassification(
		ctx,
		moodle.CourseClassificationInProgress,
	)
	if err != nil {
		panic(err)
	}

	for _, c := range courses {
		fmt.Printf("%#v\n", c)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) string

Types

type APIError

type APIError struct {
	Err              *string `json:"error,omitempty"`
	Message          *string `json:"message,omitempty"`
	ErrorCode        string  `json:"errorcode"`
	StackTrace       *string `json:"stacktrace,omitempty"`
	Exception        *string `json:"exception,omitempty"`
	DebugInfo        *string `json:"debuginfo,omitempty"`
	ReproductionLink *string `json:"reproductionlink,omitempty"`
}

func (*APIError) Error

func (a *APIError) Error() string

type AdvancedFeatureEnabled

type AdvancedFeatureEnabled struct {
	Name    string
	Enabled bool
}

type AuthAPI

type AuthAPI interface {
	Login(ctx context.Context, username, password string) (*LoginResponse, error)
}

type Client

type Client struct {
	AuthAPI   AuthAPI
	SiteAPI   SiteAPI
	UserAPI   UserAPI
	CourseAPI CourseAPI
	QuizAPI   QuizAPI
	GradeAPI  GradeAPI
	// contains filtered or unexported fields
}

Client is a Moodle API client scoped to a service.

func NewClient

func NewClient(ctx context.Context, serviceURL *url.URL, authToken string, opt ...ClientOption) (*Client, error)

NewClient creates a new Moodle client.

func NewClientWithLogin

func NewClientWithLogin(ctx context.Context, serviceURL *url.URL, username, password string, opt ...ClientOption) (*Client, error)

NewClientWithLogin creates a new Moodle client with token retrieved from login request.

func (*Client) AuthToken

func (c *Client) AuthToken() string

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption is a option to change client configuration.

func WithDebugEnabled

func WithDebugEnabled() ClientOption

WithDebugEnabled enable debug logs this option is should be used in development only.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

type ClientOptions

type ClientOptions struct {
	AuthToken  string
	HttpClient *http.Client
	Debug      bool
}

type Course

type Course struct {
	ID              int
	FullName        string
	ShortName       string
	Summary         string
	SummaryFormat   int
	StartDate       time.Time
	EndDate         time.Time
	Visible         bool
	FullNameDisplay string
	ViewURL         string
	CourseImage     string
	Progress        int
	HasProgress     bool
	IsSavourite     bool
	Hidden          bool
	ShowShortName   bool
	CourseCategory  string
}

type CourseAPI

type CourseAPI interface {
	GetEnrolledCoursesByTimelineClassification(ctx context.Context, classification CourseClassification) ([]*Course, error)
}

type CourseClassification

type CourseClassification string
const (
	CourseClassificationPast       CourseClassification = "past"
	CourseClassificationInProgress CourseClassification = "inprogress"
	CourseClassificationFuture     CourseClassification = "future"
)

type GradeAPI

type GradeAPI interface {
	GetGradeItems(ctx context.Context, userID int, courseID int) ([]*UserGrade, error)
	GetGradesTable(ctx context.Context, userID int, courseID int) ([]*GradeTable, error)
}

type GradeItem

type GradeItem struct {
	ID                 int
	ItemName           string
	ItemType           string
	ItemModule         *string
	ItemInstance       int
	ItemNumber         *int
	CategoryID         *int
	OutcomeID          *int
	ScaleID            *int
	Locked             *bool
	CmID               int
	GradeRaw           float64
	GradeDateSubmitted *time.Time
	GradeDateGraded    *time.Time
	GradeHiddenByDate  bool
	GradeNeedsUpdate   bool
	GradeIsHidden      bool
	GradeIsLocked      *bool
	GradeIsOverridden  *bool
	GradeFormatted     string
	GradeMin           int
	GradeMax           int
	RangeFormatted     string
	Feedback           string
	FeedbackFormat     int
}

GradeItem represents an grade If you want to know percentage of the grade out of course total grade, see GradeTableItem

type GradeTable

type GradeTable struct {
	CourseID     int
	UserID       int
	UserFullname string
	MaxDepth     int
	ItemGroups   []*GradeTableItemGroup
}

GradeTable represents a grade table for a course

type GradeTableItem

type GradeTableItem struct {
	ItemName                  string
	ItemNameRawHTML           string
	ItemURL                   *string
	IsGraded                  bool
	Grade                     float64
	GradeRangeMin             float64
	GradeRangeMax             float64
	Feedback                  string
	FeedBackRawHTML           string
	ContributionToCourseTotal float64
}

type GradeTableItemGroup

type GradeTableItemGroup struct {
	Name  string
	Items []*GradeTableItem
}

GradeTableItemGroup represents a group of grade items

type LoginResponse

type LoginResponse struct {
	Token        string `json:"token"`
	PrivateToken string `json:"privatetoken"`
}

type Quiz

type Quiz struct {
	ID                    int
	CourseID              int
	CourseModuleID        int
	Name                  string
	Intro                 string
	IntroFormat           int
	TimeOpen              time.Time
	TimeClose             time.Time
	TimeLimit             int
	PreferredBehaviour    string
	Attempts              int
	GradeMethod           int
	DecimalPoints         int
	QuestionDecimalPoints int
	SumGrades             int
	Grade                 int
	HasFeedback           int
	Section               int
	Visible               int
	GroupMode             int
	GroupingID            int
}

type QuizAPI

type QuizAPI interface {
	GetQuizzesByCourse(ctx context.Context, courseID int) ([]*Quiz, error)
	GetUserAttempts(ctx context.Context, quizID int) ([]*QuizAttempt, error)
	GetAttemptReview(ctx context.Context, attemptID int) (*QuizAttempt, []*QuizQuestion, error)
	StartAttempt(ctx context.Context, quizID int) (*QuizAttempt, error)
	FinishAttempt(ctx context.Context, attemptID int, timeUp bool) error
}

type QuizAttempt

type QuizAttempt struct {
	ID                  int
	QuizID              int
	UserID              int
	Attempt             int
	UniqueID            int
	Layout              string
	CurrentPage         int
	Preview             int
	State               string
	TimeStart           time.Time
	TimeFinish          *time.Time
	TimeModified        time.Time
	TimeModifiedOffline time.Time
	TimeCheckState      *time.Time
	SumGrades           int
}

type QuizQuestion

type QuizQuestion struct {
	Slot              int
	Type              string
	Page              int
	HtmlRaw           string
	SequenceCheck     int
	LastActionTime    time.Time
	HasAutoSavedStep  bool
	Flagged           bool
	Number            int
	State             string
	Status            string
	BlockedByPrevious bool
	Mark              string
	MaxMark           int
}

type SiteAPI

type SiteAPI interface {
	GetSiteInfo(ctx context.Context) (*SiteInfo, error)
}

type SiteFunctionVersion

type SiteFunctionVersion struct {
	Name    string
	Version string
}

type SiteInfo

type SiteInfo struct {
	SiteName              string
	Username              string
	Firstname             string
	Lastname              string
	Fullname              string
	Lang                  string
	UserID                int
	SiteURL               string
	UserPictureURL        string
	Functions             []*SiteFunctionVersion
	DownloadFiles         bool
	UploadFiles           bool
	Release               string
	Version               string
	MobileCSSURL          string
	AdvancedFeatures      []*AdvancedFeatureEnabled
	UserCanManageOwnFiles bool
	UserQuota             int
	UserMaxUploadFileSize int
	UserHomePage          int
	SiteID                int
	SiteCalendarType      string
	UserCalendarType      string
	Theme                 string
}

type UserAPI

type UserAPI interface {
}

type UserGrade

type UserGrade struct {
	CourseID     int
	UserID       int
	UserFullname string
	MaxDepth     int
	GradeItems   []*GradeItem
}

type Warning

type Warning struct {
	Item        string `json:"item"`
	ItemID      int    `json:"itemid"`
	WarningCode string `json:"warningcode"`
	Message     string `json:"message"`
}

type Warnings

type Warnings []*Warning

func (Warnings) Error

func (l Warnings) Error() string

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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