edupage

package
v0.0.0-...-edc3f96 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

README

Edupage

You begin with creating a Credentials struct

credentials, err := Login(username, password, server)
if err != nil {
    //Proper error handling...
}

This struct contains the important authorization and server information.

Then you can create the EdupageClient struct

client, err := CreateClient(credentials)
if err != nil {
    //Proper error handling...
}

This is the most important part, the EdupageClient struct. You will use this to interact with the Edupage API.

To update credentials of an existing client use EdupageClient#UpdateCredentials(Credentials)

User

To retrieve the user information use function EdupageClient#GetUser(bool). If the boolean is set to true, this function will update the stored used structure and, otherwise return the said structure without updating it.

user, err := client.GetUser(true)
if err != nil {
    //Proper error handling...
}

Timeline

To retrieve timeline information use function EdupageClient#GetRecentTimeline or EdupageClient#GetTimeline(Time, Time)

timeline, err := client.GetRecentTimeline()
if err != nil {
    //Proper error handling...
}

This will retrieve the last 30 days from the timeline.

Or you can specifiy your own interval, like so

timeline, err := client.GetTimeline(TIME_FROM, TIME_TO)
if err != nil {
    //Proper error handling...
}

Results (grades)

To retrieve the results use function EdupageClient#GetRecentResults

results, err := client.GetRecentResults()
if err != nil {
	//Proper error handling...
}

This will load results from the current year, you can also specify your own interval using EdupageClient#GetResults(string, string)

The arguments are halfyear and year. Possible halfyears are (but are not limited to) these values:

  • P1 first half
  • P2 second half
  • RX whole year

Timetable (dayplan)

To retrieve the timetable use function EdupageClient#GetRecentResults

timetable, err := client.GetRecentTimetable()
if err != nil {
    //Proper error handling...
}

This will load timetable 7 days ahead, and 2 days before today (using local time). You can also specify your own interval using EdupageClient#GetResults(Time, Time).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorUnitialized  = errors.New("unitialized")
	ErrorNotFound     = errors.New("not found")
	ErrorUnauthorized = errors.New("unauthorized")
	ErrorUnchangeable = errors.New("can not make changes at this time")
)
View Source
var (
	ErrAuthorization = errors.New("failed to authorize")
	ErrRedirect      = errors.New("redirect")
)
View Source
var (
	Server = ""
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func CreatePayload

func CreatePayload(data map[string]string) url.Values

func HashPassword

func HashPassword(password string) (string, error)

Types

type Attachment

type Attachment struct {
}

type Canteen

type Canteen struct {
	Days map[string]Day
	// contains filtered or unexported fields
}

Represents the canteen, contains menu information, and additional information

func CreateCanteen

func CreateCanteen(m model.Canteen) (Canteen, error)

CreateCanteen creates Canteen object from model.Canteen

func (Canteen) GetMenuByDay

func (c Canteen) GetMenuByDay(time time.Time) (Day, bool)

Obtain the menu for a specified day. Returns menu, or false bool, indicating that no menu for that day was found.

type CanteenPayload

type CanteenPayload struct {
	BoarderID   string            `json:"stravnikid"`
	Edupage     string            `json:"edupage"`
	BoarderUser string            `json:"stravnikUser,omitempty"`
	Date        string            `json:"mysqlDate"` // YYYY-mm-dd
	FIDS        map[string]string `json:"jids"`
	View        string            `json:"view"`
	Permission  string            `json:"pravo"`
	Action      string            `json:"akcia"`
}

type Credentials

type Credentials struct {
	Server       string
	PasswordHash string
	// contains filtered or unexported fields
}

func Login

func Login(username, password, server string) (Credentials, error)

Login creates EdupageClient you can use to interact the edupage api with. Returns EdupageClient or error.

type Day

type Day struct {
	Date            time.Time
	AvailableFrom   time.Time
	AvailableTo     time.Time
	Ordered         bool
	OrderableUntil  time.Time
	CancelableUntil time.Time
	Menus           []Menu
}

func CreateDay

func CreateDay(date string, day model.CanteenDay) (Day, error)

CreateDay creates a Day object from model.CanteenDay

func (Day) IsAvailable

func (m Day) IsAvailable(t time.Time) bool

IsAvailable checks if the meal is currently available for consuming/pickup

type EdupageClient

type EdupageClient struct {
	Credentials Credentials
	// contains filtered or unexported fields
}

EdupageClient is used to access the edupage api.

func CreateClient

func CreateClient(credentials Credentials) (*EdupageClient, error)

CreateClient is used to create a client struct

func (*EdupageClient) ChangeOrderStatus

func (e *EdupageClient) ChangeOrderStatus(day Day, order bool) error

ChangeOrderStatus changed order status of a meal for the specified day Return ErrorUnathorized, ErrorUnitialized, ErrorUnchangeable

func (*EdupageClient) FetchHomeworkAttachments

func (client *EdupageClient) FetchHomeworkAttachments(i model.Homework) (map[string]string, error)

FetchHomeworkAttachmens obtains the homework attchments for the specified homework. Returns ErrUnobtainableAttachments in case the attachments are not present. Retruns map, key is the resource name and value is the resource link

func (*EdupageClient) GetCanteen

func (client *EdupageClient) GetCanteen(date time.Time) (Canteen, error)

GetCanteen retrieves the whole week's canteen from the specified day. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetClassroomByID

func (client *EdupageClient) GetClassroomByID(id string) (model.Classroom, error)

GetClassroomByID is used to retrieve the classroom by it's specified ID. Returns ErrorNotFound if the classroom can't be found. Returns ErrorUnitialized if the user object hasn't been initialized.

func (*EdupageClient) GetRecentCanteen

func (client *EdupageClient) GetRecentCanteen() (Canteen, error)

GetCanteen retrieves the current week's canteen menu. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetRecentResults

func (client *EdupageClient) GetRecentResults() (model.Results, error)

GetRecentResults retrieves the results from the current year from edupage. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetRecentTimeline

func (client *EdupageClient) GetRecentTimeline() (model.Timeline, error)

GetRecentTimeline retrieves last 30 days of timeline from edupage. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetRecentTimetable

func (client *EdupageClient) GetRecentTimetable() (model.Timetable, error)

GetResults retrieves this week's timetable from edupage.

func (*EdupageClient) GetResults

func (client *EdupageClient) GetResults(year, halfyear string) (model.Results, error)

GetResults retrieves the results in a specified interval from edupage. Halfyears types are: P1 (first halfyear), P2 (second halfyear), RX (whole year) Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetStudentID

func (client *EdupageClient) GetStudentID() (string, error)

GetStudentID is used to retrieve the client's student ID. Returns ErrorUnitialized if the user object hasn't been initialized.

func (*EdupageClient) GetSubjectByID

func (client *EdupageClient) GetSubjectByID(id string) (model.Subject, error)

GetSubjectByID is used to retrieve the subject by it's specified ID. Returns ErrorNotFound if the subject can't be found. Returns ErrorUnitialized if the user object hasn't been initialized.

func (*EdupageClient) GetTeacherByID

func (client *EdupageClient) GetTeacherByID(id string) (model.Teacher, error)

GetTeacherByID is used to retrieve the teacher by their specified ID. Returns ErrorNotFound if the teacher can't be found. Returns ErrorUnitialized if the user object hasn't been initialized.

func (*EdupageClient) GetTimeline

func (client *EdupageClient) GetTimeline(from, to time.Time) (model.Timeline, error)

GetUser retrieves the timeline in a specified time interval from edupage. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetTimetable

func (client *EdupageClient) GetTimetable(from, to time.Time) (model.Timetable, error)

GetResults retrieves the timetable in the specified interval from edupage. Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) GetUser

func (client *EdupageClient) GetUser(update bool) (model.User, error)

GetUser retrieves the user from edupage or returns the stored data. If update is set to true, user data wil explicitly update Return ErrorUnauthorized if an authorization error occcurs.

func (*EdupageClient) PingSession

func (client *EdupageClient) PingSession() (bool, error)

func (*EdupageClient) SendMessage

func (client *EdupageClient) SendMessage(recipient string, options MessageOptions) error

func (*EdupageClient) UpdateCredentials

func (client *EdupageClient) UpdateCredentials(credentials Credentials)

UpdateCredentials updates the credentials and allows this struct to continue working after token expiry.

type Meal

type Meal struct {
	Alergens []int
	Name     string
	Weight   int
}
type Menu struct {
	Meals []Meal
}

type MessageOptions

type MessageOptions struct {
	Text                string       `json:"text"`
	Important           bool         `json:"important,omitempty"`
	Parents             bool         `json:"parents,omitempty"`
	AllowReplies        *bool        `json:"allowReplies,omitempty"`
	RepliesToAuthorOnly bool         `json:"repliesToAuthorOnly,omitempty"`
	Attachments         []string     `json:"attachments,omitempty"`
	Poll                *PollOptions `json:"poll,omitempty"`
}

func (*MessageOptions) UnmarshalJSON

func (m *MessageOptions) UnmarshalJSON(data []byte) error

type MessagePayload

type MessagePayload struct {
	SelectedUser string
	Text         string
	Attachments  string
	Typ          string
}

func CreateMessage

func CreateMessage(receiver, text, attachments string) MessagePayload

type PollOption

type PollOption struct {
	Text string `json:"text"`
	ID   string `json:"id,omitempty"`
}

type PollOptions

type PollOptions struct {
	Options  []PollOption `json:"options"`
	Multiple bool         `json:"multiple,omitempty"`
}

type PortalPingResponse

type PortalPingResponse struct {
	Status string `json:"status"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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