GoAsistent

package module
v0.0.0-...-d10c40c Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 12 Imported by: 0

README

GoAsistent

Knjižica za uporabo eAsistent notranjega (zasebnega/internega) API-ja

Uporaba

Zelo intuitivna.

Licenca

MIT

Documentation

Index

Constants

View Source
const (
	GradeNotification         = iota
	SubstitutionNotification  = iota
	CommunicationNotification = iota
)
View Source
const (
	PisnaOcena = iota
	UstnaOcena = iota
	DrugaOcena = iota
)
View Source
const EASISTENT_URL = "https://www.easistent.com"

Variables

View Source
var CaptchaRequired = errors.New("captcha required")
View Source
var ERROR_NO_CONTENT = errors.New("eAsistent responded with no content. This is likely due to no grades on this subject")
View Source
var MOBILE_HEADER = map[string]string{
	"Content-Type":      "application/json",
	"X-App-Name":        "child",
	"X-Client-Version":  "11102",
	"X-Client-Platform": "android",
}
View Source
var WEB_HEADER = map[string]string{
	"Content-Type":      "application/json",
	"X-Client-Version":  "13",
	"X-Client-Platform": "web",
	"User-Agent":        "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
}

Functions

func ExtractSubjectsFromTimetable

func ExtractSubjectsFromTimetable(timetable *TimetableResponse) (map[string]*Subject, error)

Types

type AbsencesResponse

type AbsencesResponse struct {
	Summary struct {
		PendingHours      int `json:"pending_hours"`
		ExcusedHours      int `json:"excused_hours"`
		UnexcusedHours    int `json:"unexcused_hours"`
		UnmanagedAbsences int `json:"unmanaged_absences"`
	} `json:"summary"`
	Items []struct {
		Id                int     `json:"id"`
		Date              string  `json:"date"`
		MissingCount      int     `json:"missing_count"`
		ExcusedCount      int     `json:"excused_count"`
		NotExcusedCount   int     `json:"not_excused_count"`
		State             string  `json:"state"`
		Seen              bool    `json:"seen"`
		ExcuseSent        bool    `json:"excuse_sent"`
		ExcuseDescription *string `json:"excuse_description"`
		ExcuseWrittenDate any     `json:"excuse_written_date"`
		Hours             []struct {
			ClassName      string `json:"class_name"`
			ClassShortName string `json:"class_short_name"`
			Value          string `json:"value"`
			From           string `json:"from"`
			To             string `json:"to"`
			State          string `json:"state"`
		} `json:"hours"`
		Attachments []any `json:"attachments"`
	} `json:"items"`
}

type AllDayEvent

type AllDayEvent struct {
	ID       int      `json:"id"`
	Date     string   `json:"date"`
	Location Location `json:"location"`
	// Teachers: TBD
	Teachers []Teacher `json:"teachers"`
	Name     string    `json:"name"`
	// EventType je:
	// 4 – prazniki/počitnice;
	// 6 – celodnevne aktivnosti, ki jih določi šola;
	// ostalo – ????
	EventType int `json:"event_type"`
}

type Classroom

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

type CommunicationMetadata

type CommunicationMetadata struct {
	ChannelID   string `json:"channelId"`
	MessageID   int    `json:"messageId"`
	UserID      int    `json:"userId"`
	ChannelType string `json:"channelType"`
	Link        string `json:"link"`
}

type Department

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

type EAsistentJWTClaims

type EAsistentJWTClaims struct {
	jwt.MapClaims
	ConsumerKey  string `json:"consumerKey"`
	UserId       string `json:"userId"`
	UserType     string `json:"userType"`
	SchoolId     any    `json:"schoolId"`
	SessionId    string `json:"sessionId"`
	PasswordHash any    `json:"password_hash"`
	IssuedAt     string `json:"issuedAt"`
	AppName      string `json:"appName"`
	ExpiresAt    string `json:"exp"`
}

type EAsistentNotification

type EAsistentNotification struct {
	Title     string          `json:"title"`
	Message   string          `json:"message"`
	ID        int             `json:"id"`
	CreatedAt string          `json:"created_at"`
	Seen      bool            `json:"seen"`
	Type      string          `json:"type"`
	Metadata  json.RawMessage `json:"meta_data"`
}

type Event

type Event struct {
	Id   int    `json:"id"`
	Date string `json:"date"`
	Time struct {
		From string `json:"from"`
		To   string `json:"to"`
	} `json:"time"`
	Location  Location  `json:"location"`
	Teachers  []Teacher `json:"teachers"`
	Name      string    `json:"name"`
	EventType int       `json:"event_type"`
}

type GradeMetadata

type GradeMetadata struct {
	GradeID   int    `json:"gradeId"`
	SubjectID int    `json:"subjectId"`
	Link      string `json:"link"`
}

type GradesResponse

type GradesResponse struct {
	Items []struct {
		Name       string `json:"name"`
		ShortName  string `json:"short_name"`
		ID         int    `json:"id"`
		GradeType  string `json:"grade_type"`
		IsExcused  bool   `json:"is_excused"`
		FinalGrade *struct {
			Value string `json:"value"`
		} `json:"final_grade"`
		AverageGrade string `json:"average_grade"`
		GradeRank    string `json:"grade_rank"`
		Semesters    []struct {
			ID         int `json:"id"`
			FinalGrade any `json:"final_grade"`
			Grades     []struct {
				TypeName     string  `json:"type_name"`
				Comment      *string `json:"comment"`
				ID           int     `json:"id"`
				Type         string  `json:"type"`
				OverridesIds any     `json:"overrides_ids"`
				Value        string  `json:"value"`
				Color        string  `json:"color"`
				Date         string  `json:"date"`
			} `json:"grades"`
		} `json:"semesters"`
	} `json:"items"`
}

type Grading

type Grading struct {
	ID          int
	Course      string
	GradingName string
	Type        int
	Date        string
	Hour        int
	Test        bool
	Grade       int
}

type GradingResponse

type GradingResponse struct {
	Items []struct {
		ID       int    `json:"id"`
		Course   string `json:"course"`
		Subject  string `json:"subject"`
		Type     string `json:"type"`
		Date     string `json:"date"`
		Period   string `json:"period"`
		Test     bool   `json:"test"` // Kaj zaboga naj bi ta vrednost pomenila/povedala? Še en duplicate za pisno oceno???
		Grade    string `json:"grade"`
		TypeName string `json:"type_name"`
	} `json:"items"`
}

type Group

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

type Location

type Location struct {
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
}

type LoginRequest

type LoginRequest struct {
	Username           string   `json:"username"`
	Password           string   `json:"password"`
	SupportedUserTypes []string `json:"supported_user_types"`
}

type LoginResponse

type LoginResponse struct {
	AccessToken struct {
		Token          string `json:"token"`
		ExpirationDate string `json:"expiration_date"`
	} `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	User         struct {
		ID            int    `json:"id"`
		Language      string `json:"language"`
		Username      string `json:"username"`
		Name          string `json:"name"`
		Type          string `json:"type"`
		FreshPassword any    `json:"freshPassword"`
	} `json:"user"`
	Redirect any `json:"redirect"`
}

type Meal

type Meal struct {
	ID          *int   `json:"id"`
	MenuID      int    `json:"menu_id"`
	Type        string `json:"type"`
	Date        string `json:"date"`
	Ordered     bool   `json:"ordered"`
	ChangeUntil string `json:"change_until"`
}

type MealsResponse

type MealsResponse struct {
	Items []Meal `json:"items"`
}
type Menu struct {
	Date  string `json:"date"`
	Menus struct {
		Breakfast      []MenuMeal `json:"breakfast"`
		Snack          []MenuMeal `json:"snack"`
		Lunch          []MenuMeal `json:"lunch"`
		AfternoonSnack []MenuMeal `json:"afternoon_snack"`
	} `json:"menus"`
}
type MenuMeal struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}
type MenusResponse struct {
	Items []Menu `json:"items"`
}

type MobileClassHour

type MobileClassHour struct {
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
	From      string `json:"from"`
	To        string `json:"to"`
	IsBreak   bool   `json:"is_break,omitempty"`
}

type MobileEvent

type MobileEvent struct {
	Slug string `json:"slug"` // useless
	// Type je lahko:
	// - school_hour
	// - event
	Type       string   `json:"type"`
	Date       string   `json:"date"`
	From       string   `json:"from"` // ura (npr. 12.45)
	To         string   `json:"to"`   // ura (npr. 13.30)
	Color      string   `json:"color"`
	Title      string   `json:"title"`
	TitleShort string   `json:"title_short"`
	Teachers   []string `json:"teachers"`
	// Subject je na voljo samo na Type == "school_hour"
	Subject struct {
		SubjectID  int    `json:"subject_id"`
		TitleShort string `json:"title_short"`
		Title      string `json:"title"`
		Color      string `json:"color"`
	} `json:"subject,omitempty"`
	// Classroom je na voljo samo na Type == "school_hour"
	Classroom string `json:"classroom,omitempty"`
	// Lesson je na voljo samo na Type == "school_hour".
	// Lesson je opis realizacije učne ure (kar se vpiše kot snov v dnevnik)
	Lesson string `json:"lesson,omitempty"`
	// ScheduleIndex pove, katere učne ure pokriva ta predmet
	ScheduleIndex []int `json:"schedule_index"`
	// Description je na voljo samo na Type == "event"
	Description string `json:"description,omitempty"`
	// TypeLabel je na voljo samo na Type == "event"
	TypeLabel string `json:"type_label,omitempty"`
	// TypeLabelShort je na voljo samo na Type == "event"
	TypeLabelShort string `json:"type_label_short,omitempty"`
	// IsImportant je na voljo samo na Type == "event" (še vedno ne vem, kakšni dogodki so nepomembni)
	IsImportant bool `json:"is_important,omitempty"`
	// TextColor je na voljo samo na Type == "event"
	TextColor string `json:"text_color,omitempty"`
	// BackgroundImage je na voljo samo na Type == "event"
	BackgroundImage struct {
		Daily  string `json:"daily"`
		Weekly string `json:"weekly"`
	} `json:"background_image,omitempty"`
}

type MobileNotificationsResponse

type MobileNotificationsResponse struct {
	Items []EAsistentNotification `json:"items"`
}

type MobileTimetableResponse

type MobileTimetableResponse struct {
	Schedule []MobileClassHour `json:"schedule"`
	Events   []MobileEvent     `json:"events"`
}

type Notification

type Notification struct {
	CreatedAt time.Time
	Type      int
	GradeData struct {
		GradeID     int
		SubjectID   int
		SubjectName string
		Grade       int
		GradeType   int
	}
	SubstitutionData  SubstitutionMetadata
	CommunicationData CommunicationMetadata
}

Notification je javen izhod iz funkcije GetNotifications

type NotificationsResponse

type NotificationsResponse struct {
	Status    any                     `json:"status"`
	Message   any                     `json:"message"`
	Errfields []any                   `json:"errfields"`
	Data      []EAsistentNotification `json:"data"`
}

type OrderCreateRequest

type OrderCreateRequest struct {
	Type string `json:"type"`
	Menu int    `json:"menu"`
	Date string `json:"date"`
}

type RefreshSessionRequest

type RefreshSessionRequest struct {
	RefreshToken string `json:"refresh_token"`
}

type RefreshSessionResponse

type RefreshSessionResponse struct {
	AccessToken struct {
		Token          string `json:"token"`
		ExpirationDate string `json:"expiration_date"`
	} `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	Redirect     any    `json:"redirect"`
}

type Session

type Session interface {
	RefreshSession() error
	RefreshWebSession(string) error
	GetGradings(past bool) ([]Grading, error)
	GetTimetable(startDate time.Time, endDate time.Time) (TimetableResponse, error)
	GetMobileTimetable(startDate time.Time, endDate time.Time) (MobileTimetableResponse, error)
	GetNotifications() ([]Notification, error)
	GetMobileNotifications() ([]Notification, error)
	GetGrades() (GradesResponse, error)
	GetGradesForSubject(subjectId int) (SubjectGradesResponse, error)
	GetSessionData() *sessionImpl
	GetMeals(from time.Time, to time.Time) (MealsResponse, error)
	GetMenus(from time.Time, to time.Time) (MenusResponse, error)
	CreateOrder(t string, date string, menu int) error
	DeleteOrder(mealId int) error
	GetAbsences() (AbsencesResponse, error)
	GetUserInfo() (UserInfo, error)
	SetRefreshToken(refreshToken string)
	SetSessionToken(sessionToken string)
}

func Login

func Login(username, password string, devMode bool, refreshTokenCallback func(username string, refreshToken string)) (Session, error)

func SessionFromAuthToken

func SessionFromAuthToken(authToken string, refreshToken string, userId string, expiry int, username string, name string, devMode bool, refreshTokenCallback func(username string, refreshToken string)) (Session, error)

func WebLogin

func WebLogin(username, password string, devMode bool, refreshTokenCallback func(username string, refreshToken string)) (Session, error)

type Subject

type Subject struct {
	ID       string
	Name     string
	Teachers []string
}

type SubjectGradesResponse

type SubjectGradesResponse struct {
	Name       string `json:"name"`
	ShortName  string `json:"short_name"`
	ID         int    `json:"id"`
	GradeType  string `json:"grade_type"`
	IsExcused  bool   `json:"is_excused"`
	FinalGrade *struct {
		ID         int    `json:"id"`
		Value      string `json:"value"`
		Date       string `json:"date"`
		InsertedBy *struct {
			ID   int    `json:"id"`
			Name string `json:"name"`
		} `json:"inserted_by"`
	} `json:"final_grade"`
	AverageGrade string `json:"average_grade"`
	GradeRank    string `json:"grade_rank"`
	Semesters    []struct {
		ID         int `json:"id"`
		FinalGrade any `json:"final_grade"`
		Grades     []struct {
			TypeName     string `json:"type_name"`
			Comment      any    `json:"comment"`
			ID           int    `json:"id"`
			OverridesIds any    `json:"overrides_ids"`
			Value        string `json:"value"`
			Subject      any    `json:"subject"`
			Date         string `json:"date"`
			NotifiedAt   any    `json:"notified_at"`
			InsertedAt   string `json:"inserted_at"`
			InsertedBy   *struct {
				ID   int    `json:"id"`
				Name string `json:"name"`
			} `json:"inserted_by"`
			GradeRank string `json:"grade_rank"`
		} `json:"grades"`
	} `json:"semesters"`
}

type SubstitutionMetadata

type SubstitutionMetadata struct {
	Date       string `json:"date"`
	ScheduleID int    `json:"schedule_id"`
	EventSlug  string `json:"event_slug"`
	Link       string `json:"link"`
}

type Teacher

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

type TimetableHour

type TimetableHour struct {
	Time struct {
		FromID int    `json:"from_id"`
		ToID   int    `json:"to_id"`
		Date   string `json:"date"`
	} `json:"time"`
	// Videokonferenca je useless
	Videokonferenca struct {
		ID      any `json:"id"`
		Link    any `json:"link"`
		Zacetek any `json:"zacetek"`
		Opomba  any `json:"opomba"`
	} `json:"videokonferenca"`
	EventID   int              `json:"event_id"`
	Color     string           `json:"color"`
	Subject   TimetableSubject `json:"subject"`
	Completed bool             `json:"completed"`
	// HourSpecialType je lahko
	// - exam
	// - substitution
	// - pre-exam (preverjanje)
	// - cancelled (odpadla)
	// - prazen string (eAsistent pošlje null)
	//
	// Zanimivo, da eAsistent ne podpira exama in substitutiona hkrati ... slab design choice ig
	HourSpecialType string       `json:"hour_special_type"`
	Departments     []Department `json:"departments"`
	Classroom       Classroom    `json:"classroom"`
	Teachers        []Teacher    `json:"teachers"`
	Groups          []Group      `json:"groups"`
	Info            []any        `json:"info"`
}

type TimetableResponse

type TimetableResponse struct {
	// TimeTable nam pove vse ure zahtevanega tedna (in še preveč???). To je torej najbolj levi stolpec v eAsistent sistemu.
	TimeTable []struct {
		ID        int    `json:"id"`
		Name      string `json:"name"`
		NameShort string `json:"name_short"`
		Time      struct {
			From string `json:"from"`
			To   string `json:"to"`
		} `json:"time"`
		Type string `json:"type"`
	} `json:"time_table"`
	// DayTable nam pove vse datume zahtevanega tedna. Torej gornja vrstica v eAsistent sistemu.
	DayTable []struct {
		Name      string `json:"name"`
		ShortName string `json:"short_name"`
		Date      string `json:"date"`
	} `json:"day_table"`
	// SchoolHourEvents nam pove dejanske ure (predmete) na urniku. Končno nekaj uporabnega.
	SchoolHourEvents []TimetableHour `json:"school_hour_events"`
	// Events: TBD
	Events       []Event       `json:"events"`
	AllDayEvents []AllDayEvent `json:"all_day_events"`
}

type TimetableSubject

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

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Email    string `json:"email"`
}

type WebLoginResponse

type WebLoginResponse struct {
	Status    string `json:"status"`
	Message   string `json:"message"`
	ErrFields []any  `json:"errfields"`
	Data      struct {
		ResetForm       bool   `json:"reset_form"`
		RequireCaptcha  bool   `json:"require_captcha"`
		PrijavaRedirect string `json:"prijava_redirect,omitempty"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

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