magistergo

package module
v0.0.0-...-75bc76c Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

README

magistergo

A go implementation of the Magister 6 API

Usage

Get the tokens using an external library

Get the session token and refresh token using another library (e.g. magister-scraper)

const { AuthManager } = require("magister-openid");
const axios = require("axios");

const options = {
    tenant: "school.magister.net",
    username: "<username>",
    password: "<password>"
}

const manager = new AuthManager(options.tenant);

axios("https://argo-web.vercel.app/api/authCode").then(({ data: authCode }) => {
    manager.login(options.username, options.password, authCode).then(tokens => {
        console.log("ACCESSTOKEN=" + tokens.access_token);
        console.log("REFRESHTOKEN=" + tokens.refresh_token);
        console.log("EXPIRES=" + tokens.expires_at);
        console.log("TENANT=" + options.tenant);
    });
});

Note: this library is not able to get the access and refresh token by itself (yet), however it is able to refresh the access token with the refresh token.

Use the library

package main

import (
	"fmt"
	"github.com/J0eppp/magistergo"
	"github.com/joho/godotenv"
	"os"
	"strconv"
)

func main() {
	// Get data from .env file
	godotenv.Load(".env")
	accessToken := os.Getenv("ACCESSTOKEN")
	refreshToken := os.Getenv("REFRESHTOKEN")
	accessTokenExpires, _ := strconv.ParseInt(os.Getenv("EXPIRES"), 10, 64)
	tenant := os.Getenv("TENANT")

	// Create a Magister instance, give it all the data it needs
	magister, err := magistergo.NewMagister(accessToken, refreshToken, accessTokenExpires, tenant)
	if err != nil {
		fmt.Println(err)
		return
	}

	_, err = magister.GetAppointments()
	if err != nil {
		fmt.Println(err)
		return
	}

	// Get today's appointments
	_, err = magister.GetAppointments("2021-05-25", "2021-05-25")
	if err != nil {
		fmt.Println(err)
		return
	}

	// Get messages
	messages, err := magister.GetMessages(7)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, message := range messages {
		fmt.Printf("%+v\n", message)
	}

	// Get the content of the last received message
	msgID := messages[0].ID
	message, err := magister.GetMessage(msgID)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(message.Content)
}

Examples

Find examples in the examples folder

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Absence

type Absence struct {
	ID                 int         `magisterjson:"Id" json:"id"`
	Start              time.Time   `magisterjson:"Start" json:"start"`
	End                time.Time   `magisterjson:"Eind" json:"end"`
	Period             int         `magisterjson:"Lesuur" json:"period"`
	Allowed            bool        `magisterjson:"Geoorloofd" json:"allowed"`
	AppointmentID      int         `magisterjson:"AfspraakId" json:"appointmentID"`
	Description        string      `magisterjson:"Omschrijving" json:"description"`
	AccountabilityType int         `magisterjson:"Verantwoordingtype" json:"accountabilityType"`
	Code               string      `magisterjson:"Code" json:"code"`
	Appointment        Appointment `magisterjson:"Afspraak" json:"appointment"`
}

type AbsencePeriod

type AbsencePeriod struct {
	Start       time.Time `magisterjson:"Start" json:"start"`
	End         time.Time `magisterjson:"Eind" json:"end"`
	Description string    `magisterjson:"Omschrijving" json:"description"`
}

type AccountData

type AccountData struct {
	Persoon Persoon `json:"Persoon"`
}

type Appointment

type Appointment struct {
	ID int64 `magisterjson:"Id" json:"id"`
	// Skip "Links", is that interesting to know?
	Start           string      `magisterjson:"Start" json:"start"`
	End             string      `magisterjson:"Einde" json:"end"`
	PeriodStarts    int8        `magisterjson:"LesuurVan" json:"periodStarts"`
	PeriodEnds      int8        `magisterjson:"LesuurTotMet" json:"periodEnds"`
	TakesWholeDay   bool        `magisterjson:"DuurtHeleDag" json:"TakesWholeDay"`
	Description     string      `magisterjson:"Omschrijving" json:"description"`
	Location        string      `magisterjson:"Locatie" json:"location"`
	Status          int64       `magisterjson:"Status" json:"status"`
	Type            int64       `magisterjson:"Type" json:"type"`
	IsOnline        bool        `magisterjson:"IsOnlineDeelname" json:"isOnline"`
	DisplayType     int64       `magisterjson:"WeergaveType" json:"displayType"`
	Content         string      `magisterjson:"Inhoud" json:"content"`
	InfoType        int64       `magisterjson:"InfoType" json:"infoType"`
	Notes           string      `magisterjson:"Aantekeningen" json:"notes"`
	Finished        bool        `magisterjson:"Afgerond" json:"finished"`
	RepeatStatus    int64       `magisterjson:"HerhaalStatus" json:"repeatStatus"`
	Repeat          string      `magisterjson:"Herhaling" json:"repeat"`
	Subjects        []Subject   `magisterjson:"Vakken" json:"subjects"`
	Teachers        []Teacher   `magisterjson:"Docenten" json:"teachers"`
	Classrooms      []Classroom `magisterjson:"Lokalen" json:"classrooms"`
	Groups          string      `magisterjson:"Groepen" json:"groups"`
	AssignmentID    int64       `magisterjson:"OpdrachtId" json:"assignmentID"`
	HasAttachements bool        `magisterjson:"HeeftBijlagen" json:"hasAttachments"`
	Attachments     string      `magisterjson:"Bijlagen" json:"attachments"`
}

Appointment contains all the info about an appointment

func (*Appointment) GetInfoType

func (appointment *Appointment) GetInfoType() string

GetInfoType returns the info type of the appointment as a string

func (*Appointment) GetStatus

func (appointment *Appointment) GetStatus() string

GetStatus returns the status of the appointment as a string

func (*Appointment) GetType

func (appointment *Appointment) GetType() string

GetType returns the type of the appointment as a string

type Assignment

type Assignment struct {
	ID    int `magisterjson:"Id" json:"id"`
	Links []struct {
		Rel  string `magisterjson:"Rel" json:"rel"`
		Href string `magisterjson:"Href" json:"href"`
	} `magisterjson:"Links"`
	Title                       string        `magisterjson:"Titel" json:"title"`
	Subject                     string        `magisterjson:"Vak" json:"subject"`
	HandInBefore                time.Time     `magisterjson:"InleverenVoor" json:"handInBefore"`
	HandedInAt                  interface{}   `magisterjson:"IngeleverdOp" json:"handedInAt"`
	StatusLastAssignmentVersion int           `magisterjson:"StatusLaatsteOpdrachtVersie" json:"statusLastAssignmentVersion"`
	LastAssignmentVersionNumber int           `magisterjson:"LaatsteOpdrachtVersienummer" json:"lastAssignmentVersionNumber"`
	Attachments                 []interface{} `magisterjson:"Bijlagen" json:"attachments"`
	Teachers                    interface{}   `magisterjson:"Docenten" json:"teachers"`
	VersionNavigationItems      []interface{} `magisterjson:"VersieNavigatieItems" json:"versionNavigationItems"`
	Description                 string        `magisterjson:"Omschrijving" json:"description"`
	Grading                     string        `magisterjson:"Beoordeling" json:"grading"`
	GradedAt                    time.Time     `magisterjson:"BeoordeeldOp" json:"gradedAt"`
	HandInAgain                 bool          `magisterjson:"OpnieuwInleveren" json:"handInAgain"`
	Closed                      bool          `magisterjson:"Afgesloten" json:"closed"`
	AllowedToHandIn             bool          `magisterjson:"MagInleveren" json:"allowedToHandIn"`
}

Assignment contains information about an assignment

type Classroom

type Classroom struct {
	Name string `json:"Naam"`
}

type Endpoints

type Endpoints struct {
	Issuer                             string     `json:"issuer"`
	JWKSUri                            string     `json:"jwks_uri"`
	AuthorizationEndpoint              string     `json:"authorization_endpoint"`
	TokenEndpoint                      string     `json:"token_endpoint"`
	UserInfoEndpoint                   string     `json:"userinfo_endpoint"`
	EndSessionEndpoint                 string     `json:"end_session_endpoint"`
	CheckSessionIframe                 string     `json:"check_session_endpoint"`
	RevocationEndpoint                 string     `json:"revocation_endpoint"`
	FrontChannelLogoutSupported        bool       `json:"frontchannel_logout_supported"`
	FrontChannelLogoutSessionSupported bool       `json:"frontchannel_logout_session_supported"`
	BackChannelLogoutSupported         bool       `json:"backchannel_logout_supported"`
	BackChannelLogoutSessionSupported  bool       `json:"backchannel_logout_session_supported"`
	ScopesSupported                    [4]string  `json:"scopes_supported"`
	ClaimsSupported                    [19]string `json:"claims_supported"`
	GrantTypesSupported                [6]string  `json:"grant_types_supported"`
	ResponseTypesSupported             [7]string  `json:"response_types_supported"`
	ResponseModesSupported             [4]string  `json:"response_modes_supported"`
	TokenEndpointAuthMethodsSupported  [2]string  `json:"token_endpoint_auth_methods_supported"`
	IDTokenSigningAlgValuesSupported   [1]string  `json:"id_token_signing_alg_values_supported"`
	SubjectTypesSupported              [1]string  `json:"subject_types_supported"`
	CodeChallengeMethodsSupported      [2]string  `json:"code_challenge_methods_supported"`
	RequestParameterSupported          bool       `json:"request_parameter_supported"`
	TenantsEndpoint                    string     `json:"tenants_endpoint"`
}

Endpoints contains all the information about the Magister endpoints (I guess)

type Grade

type Grade struct {
	GradeID       int       `magisterjson:"CijferId" json:"gradeID"`
	GradeStr      string    `magisterjson:"CijferStr" json:"gradeStr"`
	IsSufficient  bool      `magisterjson:"IsVoldoende" json:"isSufficient"`
	EnteredBy     string    `magisterjson:"IngevoerdDoor" json:"enteredBy"`
	DateEntered   time.Time `magisterjson:"DatumIngevoerd" json:"dateEntered"`
	GradingPeriod struct {
		ID              int    `magisterjson:"Id" json:"id"`
		Name            string `magisterjson:"Naam" json:"name"`
		ReferenceNumber int    `magisterjson:"VolgNummer" json:"referenceNumber"`
	} `magisterjson:"CijferPeriode" json:"gradingPeriod"`
	Subject struct {
		ID           int    `magisterjson:"Id" json:"id"`
		Abbreviation string `magisterjson:"Afkorting" json:"abbreviation"`
		Description  string `magisterjson:"Omschrijving" json:"description"`
		FollowNumber int    `magisterjson:"Volgnr" json:"followNumber"`
	} `magisterjson:"Vak" json:"subject"`
	CatchUp     bool `magisterjson:"Inhalen" json:"catchUp"`
	Exemption   bool `magisterjson:"Vrijstelling" json:"exemption"`
	Counts      bool `magisterjson:"TeltMee" json:"counts"`
	GradeColumn struct {
		ID                   int         `magisterjson:"Id" json:"id"`
		ColumnName           string      `magisterjson:"KolomNaam" json:"columnName"`
		ColumnNumber         string      `magisterjson:"KolomNummer" json:"columnNumber"`
		ColumnFollowNumber   string      `magisterjson:"KolomVolgNummer" json:"columnFollowNumber"`
		ColumnHeader         string      `magisterjson:"KolomKop" json:"columnHeader"`
		ColumnDescription    interface{} `magisterjson:"KolomOmschrijving" json:"columnDescription"`
		ColumnType           int         `magisterjson:"KolomSoort" json:"columnType"`
		IsRetakeColumn       bool        `magisterjson:"IsHerkansingKolom" json:"isRetakeColumn"`
		IsTeacherColumn      bool        `magisterjson:"IsDocentKolom" json:"isTeacherColumn"`
		HasUnderlyingColumns bool        `magisterjson:"HeeftOnderliggendeKolommen" json:"HasUnderlyingColumns"`
		IsPTAColumn          bool        `magisterjson:"IsPTAKolom" json:"isPTAColumn"`
	} `magisterjson:"CijferKolom" json:"gradeColumn"`
	GradeColumnIDEloAssignment int    `magisterjson:"CijferKolomIdEloOpdracht" json:"gradeColumnIDEloAssignment"`
	Teacher                    string `magisterjson:"Docent" json:"teacher"`
	SubjectExemption           bool   `magisterjson:"VakOntheffing" json:"subjectExemption"`
	SubjectDispensation        bool   `magisterjson:"VakVrijstelling" json:"subjectDispensation"`
}

type GradingPeriod

type GradingPeriod struct {
	ID    int `magisterjson:"id" json:"id"`
	Study struct {
		ID    int    `magisterjson:"id" json:"id"`
		Code  string `magisterjson:"code" json:"code"`
		Links struct {
			Self struct {
				Href string `magisterjson:"href" json:"href"`
			} `magisterjson:"self" json:"self"`
		} `magisterjson:"links" json:"links"`
	} `magisterjson:"studie" json:"study"`
	Group struct {
		ID          int    `magisterjson:"id" json:"id"`
		Code        string `magisterjson:"code" json:"code"`
		Description string `magisterjson:"omschrijving" json:"description"`
		Links       struct {
			Self struct {
				Href string `magisterjson:"href" json:"href"`
			} `magisterjson:"self" json:"self"`
		} `magisterjson:"links" json:"links"`
	} `magisterjson:"groep" json:"group"`
	ClassPeriod struct {
		Code  string `magisterjson:"code" json:"code"`
		Links struct {
			Self struct {
				Href string `magisterjson:"href" json:"href"`
			} `magisterjson:"self" json:"self"`
		} `magisterjson:"links" json:"links"`
	} `magisterjson:"lesperiode" json:"classPeriod"`
	StudyProgram []struct {
		Code  string `magisterjson:"code" json:"code"`
		Links struct {
			Self struct {
				Href string `magisterjson:"href" json:"href"`
			} `magisterjson:"self" json:"self"`
		} `magisterjson:"links" json:"links"`
	} `magisterjson:"profielen" json:"studyProgram"`
	PersonalMentor struct {
		Initials      string `magisterjson:"voorletters" json:"initials"`
		SurnamePrefix string `magisterjson:"tussenvoegsel" json:"surnamePrefix"`
		Lastname      string `magisterjson:"achternaam" json:"lastName"`
		Links         struct {
			Self struct {
				Href string `magisterjson:"href" json:"href"`
			} `magisterjson:"self" json:"self"`
		} `magisterjson:"links" json:"links"`
	} `magisterjson:"persoonlijkeMentor" json:"personalMentor"`
	Start              string `magisterjson:"begin" json:"start"`
	End                string `magisterjson:"einde" json:"end"`
	IsMainRegistration bool   `magisterjson:"isHoofdAanmelding" json:"isMainRegistration"`
	Links              struct {
		Self struct {
			Href string `magisterjson:"href" json:"href"`
		} `magisterjson:"self" json:"self"`
		Subjects struct {
			Href string `magisterjson:"href" json:"href"`
		} `magisterjson:"vakken" json:"subjects"`
		Periods struct {
			Href string `magisterjson:"href" json:"href"`
		} `magisterjson:"perioden" json:"periods"`
		Grades struct {
			Href string `magisterjson:"href" json:"href"`
		} `magisterjson:"cijfers" json:"grades"`
		Mentors struct {
			Href string `magisterjson:"href" json:"href"`
		} `magisterjson:"mentoren" json:"mentors"`
	} `magisterjson:"links" json:"links"`
}

type LoginOptions

type LoginOptions struct {
	Username string
	Password string
}

type Magister

type Magister struct {
	Tenant               string
	AccessToken          string
	RefreshToken         string
	AccessTokenExpiresAt int64
	Authority            string
	Endpoints            Endpoints
	// ClientID string
	UserID     string
	HTTPClient http.Client
}

func NewMagister

func NewMagister(accessToken string, refreshToken string, accessTokenExpiresAt int64, tenant string) (Magister, error)

func (*Magister) CheckSession

func (m *Magister) CheckSession() error

CheckSession checks if the session has expired

func (*Magister) GetAbsences

func (m *Magister) GetAbsences(dates ...time.Time) ([]Absence, error)

func (*Magister) GetAppointments

func (m *Magister) GetAppointments(dates ...string) ([]Appointment, error)

GetAppointments fetches the appointment data from Magister and puts it into a []Appointment

func (*Magister) GetAssignments

func (m *Magister) GetAssignments(startDate time.Time, endDate time.Time, _amount ...int64) ([]Assignment, error)

GetAssignments returns an array of assignments. The third parameter is there if you want to get more/less than 250 assignments.

func (*Magister) GetGrades

func (m *Magister) GetGrades() ([]Grade, error)

func (*Magister) GetMessage

func (m *Magister) GetMessage(messageID int64) (Message, error)

func (*Magister) GetMessages

func (m *Magister) GetMessages(amountOfMessages uint64, skip ...uint64) ([]MessageInfo, error)

func (*Magister) RefreshAccessToken

func (m *Magister) RefreshAccessToken() (RefreshAccessTokenResponse, error)

RefreshAccessToken refreshes the access token

type Message

type Message struct {
	Content   string `json:"inhoud"`
	Receivers []struct {
		ID          int    `json:"id"`
		DisplayName string `json:"weergavenaam"`
		Type        string `json:"type"`
		IsToParent  bool   `json:"isAanOuder"`
		Links       struct {
			Self struct {
				Href string `json:"href"`
			} `json:"self"`
		} `json:"links"`
	} `json:"ontvangers"`
	CopyReceivers      []interface{} `json:"kopieOntvangers"`
	BlindCopyReceivers []interface{} `json:"blindeKopieOntvangers"`
	ID                 int           `json:"id"`
	Subject            string        `json:"onderwerp"`
	MapID              int           `json:"mapId"`
	Sender             struct {
		ID    int    `json:"id"`
		Name  string `json:"naam"`
		Links struct {
			Self struct {
				Href string `json:"href"`
			} `json:"self"`
		} `json:"links"`
	} `json:"afzender"`
	HasPriority    bool        `json:"heeftPrioriteit"`
	HasAttachments bool        `json:"heeftBijlagen"`
	Isread         bool        `json:"isGelezen"`
	SentAt         time.Time   `json:"verzondenOp"`
	ForwardedAt    interface{} `json:"doorgestuurdOp"`
	RepliedAt      interface{} `json:"beantwoordOp"`
	Links          struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		Map struct {
			Href string `json:"href"`
		} `json:"map"`
		Attachments struct {
			Href string `json:"href"`
		} `json:"bijlagen"`
	} `json:"links"`
}

type MessageInfo

type MessageInfo struct {
	ID      int64  `json:"id"`
	Subject string `json:"onderwerp"`
	MapID   int    `json:"mapId"`
	Sender  struct {
		ID    int    `json:"id"`
		Name  string `json:"naam"`
		Links struct {
			Self struct {
				Href string `json:"href"`
			} `json:"self"`
		} `json:"links"`
	} `json:"afzender"`
	HasPriority    bool        `json:"heeftPrioriteit"`
	HasAttachments bool        `json:"heeftBijlagen"`
	IsRead         bool        `json:"isGelezen"`
	SentAt         time.Time   `json:"verzondenOp"`
	ForwaredAt     interface{} `json:"doorgestuurdOp"`
	RepliedAt      interface{} `json:"beantwoordOp"`
	Links          struct {
		Self struct {
			Href string `json:"href"`
		} `json:"self"`
		Map struct {
			Href string `json:"href"`
		} `json:"map"`
	} `json:"links"`
}

type Persoon

type Persoon struct {
	Id int64 `json:"Id"`
}

type RefreshAccessTokenResponse

type RefreshAccessTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`

	ExpiresAt int64
	// contains filtered or unexported fields
}

type Subject

type Subject struct {
	ID   int64  `json:"Id"`
	Name string `json:"Naam"`
}

type Teacher

type Teacher struct {
	ID          int64  `json:"Id"`
	Name        string `json:"Naam"`
	TeacherCode string `json:"Docentcode"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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