cu

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseURL       = "https://my.centraluniversity.ru"
	GitLabBaseURL = "https://git.culab.ru"

	CourseEndpoint                = "/api/micro-lms/courses/%d"
	CourseOverviewEndpoint        = "/api/micro-lms/courses/%d/overview"
	CourseProgressEndpoint        = "/api/micro-lms/courses/%d/student/progress"
	StudentPerformanceEndpoint    = "/api/micro-lms/courses/%d/student-performance"
	ActivitiesPerformanceEndpoint = "/api/micro-lms/courses/%d/activities-performance"
	CourseExercisesEndpoint       = "/api/micro-lms/courses/%d/exercises"
	StudentCoursesEndpoint        = "/api/micro-lms/courses/student"
	ThemeEndpoint                 = "/api/micro-lms/themes/%d"
	LongreadEndpoint              = "/api/micro-lms/longreads/%d"
	LongreadMaterialsEndpoint     = "/api/micro-lms/longreads/%d/materials"
	CurrentStudentEndpoint        = "/api/micro-lms/students/me"
	TaskEndpoint                  = "/api/micro-lms/tasks/%d"
	DeadlinesEndpoint             = "/api/micro-lms/deadlines"
	DownloadLinkEndpoint          = "/api/micro-lms/content/download-link"

	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func CookieFilePath

func CookieFilePath() (string, error)

func GitLabCookieFilePath

func GitLabCookieFilePath() (string, error)
func IsGitLabLink(link string) bool

IsGitLabLink checks if a URL is a git.culab.ru link.

func LoadCookie

func LoadCookie() (string, error)

func LoadGitLabCookie

func LoadGitLabCookie() (string, error)

func LoginGitLabWithBrowser

func LoginGitLabWithBrowser(ctx context.Context, timeout time.Duration) (string, error)

LoginGitLabWithBrowser opens Chrome for GitLab SSO login and captures _gitlab_session cookie. It waits until the user completes SSO and is redirected away from the sign-in page.

func LoginWithBrowser

func LoginWithBrowser(ctx context.Context, timeout time.Duration) (string, error)

LoginWithBrowser opens Chrome for LMS login and captures bff.cookie.

func ParseGitLabLink(link string) (string, string, string, bool, bool)

ParseGitLabLink extracts project, ref, and path from a git.culab.ru link.

func SaveCookie

func SaveCookie(cookie string) error

func SaveGitLabCookie

func SaveGitLabCookie(cookie string) error

Types

type APIError

type APIError struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	Details string `json:"details"`
}

APIError represents an API error response.

func (APIError) Error

func (e APIError) Error() string

type ActivitiesPerformance

type ActivitiesPerformance struct {
	Items       []ActivityPerformanceItem `json:"items"`
	TotalWeight float64                   `json:"totalWeight"`
	TotalScore  float64                   `json:"totalScore"`
}

ActivitiesPerformance represents performance grouped by activity type.

type ActivityFull

type ActivityFull struct {
	AverageScoreThreshold *float64 `json:"averageScoreThreshold"`
	Name                  string   `json:"name"`
	Weight                float64  `json:"weight"`
	ID                    int      `json:"id"`
	MaxExercisesCount     int      `json:"maxExercisesCount"`
}

ActivityFull represents an activity with all fields.

type ActivityPerformanceItem

type ActivityPerformanceItem struct {
	Activity  ActivityFull `json:"activity"`
	Total     float64      `json:"total"`
	Average   float64      `json:"average"`
	IsBlocker bool         `json:"isBlocker"`
}

ActivityPerformanceItem represents one activity's performance.

type ActivityRef

type ActivityRef struct {
	Name   string  `json:"name"`
	Weight float64 `json:"weight"`
	ID     int     `json:"id"`
}

ActivityRef is a minimal activity reference.

type Blocker

type Blocker struct {
	ActivityName          string  `json:"activityName"`
	AverageScoreThreshold float64 `json:"averageScoreThreshold"`
	ActivityID            int     `json:"activityId"`
}

Blocker represents a blocker activity in performance.

type Client

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

func NewClient

func NewClient(bffCookie string) *Client

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

func NewClientWithOptions

func NewClientWithOptions(bffCookie string, timeout time.Duration, userAgent string) *Client

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, material Material, destDir string) (string, error)

func (*Client) GetActivitiesPerformance

func (c *Client) GetActivitiesPerformance(ctx context.Context, courseID int) (*ActivitiesPerformance, error)

GetActivitiesPerformance fetches performance grouped by activity type.

func (*Client) GetAllCourses added in v0.1.4

func (c *Client) GetAllCourses(ctx context.Context) ([]StudentCourse, []StudentCourse, error)

GetAllCourses fetches both active (state=published) and archived (state=archived) student courses. The first return is the active list, the second is the archived list; combine if a flat list is needed.

func (*Client) GetBffCookie

func (c *Client) GetBffCookie() string

func (*Client) GetCourse

func (c *Client) GetCourse(ctx context.Context, courseID int) (*Course, error)

func (*Client) GetCourseExercises

func (c *Client) GetCourseExercises(ctx context.Context, courseID int) (*CourseExercises, error)

GetCourseExercises fetches all exercises for a course.

func (*Client) GetCourseOverview

func (c *Client) GetCourseOverview(ctx context.Context, courseID int) (*CourseOverview, error)

func (*Client) GetCourseProgress

func (c *Client) GetCourseProgress(ctx context.Context, courseID int) (*CourseProgress, error)

GetCourseProgress fetches the student's overall score in a course.

func (*Client) GetCurrentStudent

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

GetCurrentStudent fetches the authenticated student profile.

func (*Client) GetDeadlines

func (c *Client) GetDeadlines(ctx context.Context, limit int, courseID *int) ([]Deadline, error)

GetDeadlines fetches student deadlines, optionally filtered by courseId.

func (c *Client) GetDownloadLink(ctx context.Context, filename, version string) (string, error)

func (*Client) GetLongReadContent

func (c *Client) GetLongReadContent(ctx context.Context, longReadID int) (*MaterialsResponse, error)

func (*Client) GetLongread

func (c *Client) GetLongread(ctx context.Context, longreadID int) (*Longread, error)

func (*Client) GetStudentCourses

func (c *Client) GetStudentCourses(ctx context.Context, limit int, state string) (*StudentCoursesResponse, error)

func (*Client) GetStudentPerformance

func (c *Client) GetStudentPerformance(ctx context.Context, courseID int) (*StudentPerformance, error)

GetStudentPerformance fetches per-exercise scores for a course.

func (*Client) GetTask

func (c *Client) GetTask(ctx context.Context, taskID int) (*Task, error)

GetTask fetches a single task by ID.

func (*Client) GetTheme

func (c *Client) GetTheme(ctx context.Context, themeID int) (*Theme, error)

func (*Client) ResolveCourse

func (c *Client) ResolveCourse(ctx context.Context, query string) (int, string, error)

ResolveCourse finds a course by ID (numeric string) or by substring match on course name. Searches both active and archived courses; for numeric IDs the archived list is a fallback when the ID is not in the active set. Returns the matched course ID. If multiple courses match, returns all matches and an error.

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string) bool

func (*Client) SetBffCookie

func (c *Client) SetBffCookie(cookie string)

func (*Client) ValidateCookie

func (c *Client) ValidateCookie() error

func (*Client) ValidateCookieWithContext

func (c *Client) ValidateCookieWithContext(ctx context.Context) error

type Course

type Course struct {
	PublishDate   *time.Time     `json:"publishDate"`
	PublishedAt   *time.Time     `json:"publishedAt"`
	SubjectID     *int           `json:"subjectId"`
	Settings      CourseSettings `json:"settings"`
	Name          string         `json:"name"`
	State         string         `json:"state"`
	Category      string         `json:"category"`
	CategoryCover string         `json:"categoryCover"`
	ID            int            `json:"id"`
	IsArchived    bool           `json:"isArchived"`
}

Course represents course summary information.

type CourseExercise

type CourseExercise struct {
	Activity ActivityRef `json:"activity"`
	Longread LongreadRef `json:"longread"`
	Theme    ThemeRef    `json:"theme"`
	Name     string      `json:"name"`
	Type     string      `json:"type"`
	ID       int         `json:"id"`
}

CourseExercise is an exercise in the course exercises list.

type CourseExercises

type CourseExercises struct {
	Exercises []CourseExercise `json:"exercises"`
	Name      string           `json:"name"`
	ID        int              `json:"id"`
}

CourseExercises represents exercises list for a course.

type CourseOverview

type CourseOverview struct {
	PublishDate *time.Time     `json:"publishDate"`
	PublishedAt *time.Time     `json:"publishedAt"`
	Settings    CourseSettings `json:"settings"`
	Themes      []Theme        `json:"themes"`
	Name        string         `json:"name"`
	State       string         `json:"state"`
	ID          int            `json:"id"`
	IsArchived  bool           `json:"isArchived"`
}

CourseOverview represents the complete course overview response.

type CourseProgress

type CourseProgress struct {
	EarnedScore     float64 `json:"earnedScore"`
	LeftToEarnScore float64 `json:"leftToEarnScore"`
	MaxScore        float64 `json:"maxScore"`
}

CourseProgress represents the student's overall progress in a course.

type CourseRef

type CourseRef struct {
	Name       string `json:"name"`
	ID         int    `json:"id"`
	IsArchived bool   `json:"isArchived"`
}

CourseRef is a minimal course reference.

type CourseSettings

type CourseSettings struct {
	SkillLevel          string `json:"skillLevel"`
	IsSkillLevelEnabled bool   `json:"isSkillLevelEnabled"`
}

CourseSettings represents course configuration settings.

type Deadline

type Deadline struct {
	Exercise  DeadlineExercise `json:"exercise"`
	Deadline  time.Time        `json:"deadline"`
	CreatedAt time.Time        `json:"createdAt"`
	RejectAt  *time.Time       `json:"rejectAt"`
	Reviewer  *Reviewer        `json:"reviewer"`
	Course    CourseRef        `json:"course"`
	Theme     ThemeRef         `json:"theme"`
	Longread  LongreadRef      `json:"longread"`
	State     string           `json:"state"`
	ID        int              `json:"id"`
}

Deadline represents a student's deadline for an exercise.

type DeadlineActivity

type DeadlineActivity struct {
	Name              string  `json:"name"`
	Weight            float64 `json:"weight"`
	ID                int     `json:"id"`
	IsLateDaysEnabled bool    `json:"isLateDaysEnabled"`
}

DeadlineActivity is the activity info in a deadline exercise.

type DeadlineExercise

type DeadlineExercise struct {
	StartDate *time.Time       `json:"startDate"`
	Deadline  time.Time        `json:"deadline"`
	Activity  DeadlineActivity `json:"activity"`
	Name      string           `json:"name"`
	Type      string           `json:"type"`
	ID        int              `json:"id"`
	MaxScore  int              `json:"maxScore"`
}

DeadlineExercise is the exercise info embedded in a deadline.

type DownloadLinkResponse

type DownloadLinkResponse struct {
	URL string `json:"url"`
}

DownloadLinkResponse represents the response from /api/micro-lms/content/download-link.

type Exercise

type Exercise struct {
	Activity *ActivityRef `json:"activity,omitempty"`
	Deadline *time.Time   `json:"deadline,omitempty"`
	Name     string       `json:"name"`
	ID       int          `json:"id"`
	MaxScore int          `json:"maxScore"`
}

Exercise represents an exercise within a longread.

type FileContent

type FileContent struct {
	Name      string `json:"name"`
	Filename  string `json:"filename"`
	MediaType string `json:"mediaType"`
	Version   string `json:"version"`
	Length    int    `json:"length"`
}

FileContent represents file content information.

type GitLabClient

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

GitLabClient provides access to git.culab.ru using session cookie.

func NewGitLabClient

func NewGitLabClient(sessionCookie string) *GitLabClient

NewGitLabClient creates a client with a _gitlab_session cookie.

func NewGitLabClientFromEnv

func NewGitLabClientFromEnv() (*GitLabClient, error)

NewGitLabClientFromEnv loads the GitLab session cookie from env or file.

func (g *GitLabClient) DownloadGitLabLink(ctx context.Context, link, destDir string) ([]string, error)

DownloadGitLabLink downloads content from a git.culab.ru link and saves to destDir. For blob links — downloads the single file. For tree links — downloads all text files in the directory via GitLab API.

func (*GitLabClient) GetRawFile

func (g *GitLabClient) GetRawFile(ctx context.Context, project, ref, filePath string) ([]byte, error)

GetRawFile downloads a single file from GitLab via the raw endpoint.

type Longread

type Longread struct {
	PublishDate *time.Time `json:"publishDate"`
	PublishedAt *time.Time `json:"publishedAt"`
	Exercises   []Exercise `json:"exercises"`
	Type        string     `json:"type"`
	Name        string     `json:"name"`
	State       string     `json:"state"`
	Order       int        `json:"order"`
	ID          int        `json:"id"`
}

Longread represents a learning material within a theme.

type LongreadRef

type LongreadRef struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

LongreadRef is a minimal longread reference.

type Material

type Material struct {
	PublishDate   *time.Time   `json:"publishDate"`
	PublishedAt   *time.Time   `json:"publishedAt"`
	Content       *FileContent `json:"content,omitempty"`
	TaskID        *int         `json:"taskId,omitempty"`
	Discriminator string       `json:"discriminator"`
	ViewContent   string       `json:"viewContent,omitempty"`
	ViewType      string       `json:"viewType,omitempty"`
	MediaType     string       `json:"mediaType,omitempty"`
	Filename      string       `json:"filename,omitempty"`
	Version       string       `json:"version,omitempty"`
	State         string       `json:"state"`
	Type          string       `json:"type"`
	Name          string       `json:"name,omitempty"`
	Length        int          `json:"length,omitempty"`
	ID            int          `json:"id"`
	Order         int          `json:"order"`
}

Material represents a material item in a longread.

type MaterialsResponse

type MaterialsResponse struct {
	Items  []Material `json:"items"`
	Paging Paging     `json:"paging"`
}

MaterialsResponse represents the response from /api/micro-lms/longreads/{id}/materials.

type Paging

type Paging struct {
	Limit      int `json:"limit"`
	Offset     int `json:"offset"`
	TotalCount int `json:"totalCount"`
}

Paging represents pagination information.

type Progress

type Progress struct {
	CompletedCount int     `json:"completedCount"`
	TotalCount     int     `json:"totalCount"`
	Percentage     float64 `json:"percentage"`
}

Progress represents course progress information.

type Reviewer

type Reviewer struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	LastName  string `json:"lastName"`
	FirstName string `json:"firstName"`
}

Reviewer represents a task reviewer.

type Solution

type Solution struct {
	Type        string `json:"type"`
	SolutionURL string `json:"solutionUrl"`
}

Solution represents a task solution.

type Student

type Student struct {
	ID              string `json:"id"`
	LastName        string `json:"lastName"`
	FirstName       string `json:"firstName"`
	MiddleName      string `json:"middleName"`
	UniversityEmail string `json:"universityEmail"`
	TimeAccount     string `json:"timeAccount"`
	StudyStartYear  int    `json:"studyStartYear"`
	StudyLevel      string `json:"studyLevel"`
	LateDaysBalance int    `json:"lateDaysBalance"`
}

Student represents the current student profile.

type StudentCourse

type StudentCourse struct {
	PublishDate *time.Time     `json:"publishDate"`
	PublishedAt *time.Time     `json:"publishedAt"`
	SubjectID   *int           `json:"subjectId"`
	Progress    *Progress      `json:"progress,omitempty"`
	Settings    CourseSettings `json:"settings"`
	Name        string         `json:"name"`
	State       string         `json:"state"`
	Category    string         `json:"category"`
	ID          int            `json:"id"`
	IsArchived  bool           `json:"isArchived"`
}

StudentCourse represents a course in the student courses list.

type StudentCoursesResponse

type StudentCoursesResponse struct {
	Items  []StudentCourse `json:"items"`
	Paging Paging          `json:"paging"`
}

StudentCoursesResponse represents the response from /api/micro-lms/courses/student.

type StudentPerformance

type StudentPerformance struct {
	Tasks    []TaskScore `json:"tasks"`
	Blockers []Blocker   `json:"blockers"`
}

StudentPerformance represents the student's performance in a course.

type Task

type Task struct {
	Score      *float64     `json:"score"`
	StartedAt  *time.Time   `json:"startedAt"`
	SubmitAt   *time.Time   `json:"submitAt"`
	RejectAt   *time.Time   `json:"rejectAt"`
	EvaluateAt *time.Time   `json:"evaluateAt"`
	Reviewer   *Reviewer    `json:"reviewer"`
	Solution   *Solution    `json:"solution"`
	CreatedAt  time.Time    `json:"createdAt"`
	Deadline   time.Time    `json:"deadline"`
	Exercise   TaskExercise `json:"exercise"`
	Course     CourseRef    `json:"course"`
	Theme      ThemeRef     `json:"theme"`
	Longread   LongreadRef  `json:"longread"`
	Student    TaskStudent  `json:"student"`
	Type       string       `json:"type"`
	State      string       `json:"state"`
	ID         int          `json:"id"`
}

Task represents a full task detail (student's assignment instance).

type TaskExercise

type TaskExercise struct {
	StartDate   *time.Time  `json:"startDate"`
	Deadline    time.Time   `json:"deadline"`
	Activity    ActivityRef `json:"activity"`
	Name        string      `json:"name"`
	Type        string      `json:"type"`
	ViewContent string      `json:"viewContent"`
	ID          int         `json:"id"`
	MaxScore    int         `json:"maxScore"`
}

TaskExercise is the exercise info embedded in a task.

type TaskScore

type TaskScore struct {
	Score      *float64     `json:"score"`
	Activity   ActivityFull `json:"activity"`
	State      string       `json:"state"`
	ID         int          `json:"id"`
	ExerciseID int          `json:"exerciseId"`
	MaxScore   int          `json:"maxScore"`
}

TaskScore represents a single task's score in the gradebook.

type TaskStudent

type TaskStudent struct {
	ID              string `json:"id"`
	LastName        string `json:"lastName"`
	FirstName       string `json:"firstName"`
	LateDaysBalance int    `json:"lateDaysBalance"`
}

TaskStudent is the student info embedded in a task.

type Theme

type Theme struct {
	PublishDate *time.Time `json:"publishDate"`
	PublishedAt *time.Time `json:"publishedAt"`
	Longreads   []Longread `json:"longreads"`
	Name        string     `json:"name"`
	State       string     `json:"state"`
	ID          int        `json:"id"`
	Order       int        `json:"order"`
}

Theme represents a course theme/module.

type ThemeRef

type ThemeRef struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

ThemeRef is a minimal theme reference.

Jump to

Keyboard shortcuts

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