Initial commit
This commit is contained in:
commit
fcb7687c05
19 changed files with 880 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# GoSkola24API
|
||||
|
||||
Go module for easy interaction with the Skola24 API.
|
40
cmd/goskola24api/main.go
Normal file
40
cmd/goskola24api/main.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/utility"
|
||||
"git.zervo.org/zervo/GoSkola24API/pkg/goskola24api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
key, _ := utility.GetRendererKey()
|
||||
|
||||
api := goskola24api.Skola24API{
|
||||
Host: "avesta.skola24.se",
|
||||
}
|
||||
|
||||
_, err := api.GetTerms()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
schools, _ := api.GetSchools()
|
||||
|
||||
for _, school := range schools {
|
||||
fmt.Println(school.AvailableData)
|
||||
}
|
||||
|
||||
rooms, err := api.GetRooms(schools[4], true)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
fmt.Println(rooms)
|
||||
|
||||
for _, room := range rooms {
|
||||
fmt.Println(room.Name)
|
||||
}
|
||||
|
||||
fmt.Println(key)
|
||||
}
|
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module git.zervo.org/zervo/GoSkola24API
|
||||
|
||||
go 1.22.5
|
54
internal/requests/get_generic_selection.go
Normal file
54
internal/requests/get_generic_selection.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/types"
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/utility"
|
||||
pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types"
|
||||
)
|
||||
|
||||
func GetGenericSelection(school pubtypes.School, filters types.RequestFilters) (_result map[string]interface{}, _error error) {
|
||||
request := types.RequestSelectionBase{
|
||||
HostName: school.HostName,
|
||||
UnitGuid: school.SchoolId,
|
||||
Filters: filters,
|
||||
}
|
||||
|
||||
response, err := utility.Request(request, "get/timetable/selection")
|
||||
if err != nil {
|
||||
return nil, errors.New("could not get selection: " + err.Error())
|
||||
}
|
||||
|
||||
// Assert the response type to a map[string]interface{}
|
||||
responseMap, ok := response.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unexpected response type")
|
||||
}
|
||||
|
||||
return responseMap, nil
|
||||
}
|
91
internal/requests/get_rooms.go
Normal file
91
internal/requests/get_rooms.go
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/types"
|
||||
pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types"
|
||||
)
|
||||
|
||||
func GetRooms(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Room, _error error) {
|
||||
if checkAvailability && !school.AvailableData.HasRooms {
|
||||
return nil, errors.New("availability check failed: school does not provide room data")
|
||||
}
|
||||
|
||||
filters := types.RequestFilters{
|
||||
Class: false,
|
||||
Course: false,
|
||||
Group: false,
|
||||
Period: false,
|
||||
Room: true,
|
||||
Student: false,
|
||||
Subject: false,
|
||||
Teacher: false,
|
||||
}
|
||||
|
||||
responseMap, err := GetGenericSelection(school, filters)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to get rooms: " + err.Error())
|
||||
}
|
||||
|
||||
fmt.Println(school)
|
||||
fmt.Println(responseMap)
|
||||
|
||||
// Extract rooms as []interface{}
|
||||
roomsRaw, ok := responseMap["rooms"].([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("missing or invalid \"rooms\" field in response")
|
||||
}
|
||||
|
||||
fmt.Println(roomsRaw)
|
||||
|
||||
// Convert raw rooms into usable room type
|
||||
var rooms []pubtypes.Room
|
||||
for _, roomRaw := range roomsRaw {
|
||||
roomMap, ok := roomRaw.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unexpected room format")
|
||||
}
|
||||
|
||||
// Extract fields from each room
|
||||
roomName, _ := roomMap["name"].(string)
|
||||
roomId, _ := roomMap["eid"].(string)
|
||||
external, _ := roomMap["external"].(bool)
|
||||
|
||||
// Map to struct
|
||||
room := pubtypes.Room{
|
||||
Name: roomName,
|
||||
RoomId: roomId,
|
||||
External: external,
|
||||
}
|
||||
|
||||
rooms = append(rooms, room)
|
||||
}
|
||||
|
||||
return rooms, nil
|
||||
}
|
121
internal/requests/get_schools.go
Normal file
121
internal/requests/get_schools.go
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// I'm aware this code is really weird and not optimised. I changed approach multiple times in the middle of it and am too lazy to fix it. It works though.
|
||||
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/types"
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/utility"
|
||||
pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types"
|
||||
)
|
||||
|
||||
func GetSchools(api_host string) (_result []pubtypes.School, _error error) {
|
||||
request := types.RequestSchools{
|
||||
GetTimetableViewerUnitsRequest: types.RequestSchoolsHost{
|
||||
HostName: api_host,
|
||||
},
|
||||
}
|
||||
|
||||
response, err := utility.Request(request, "services/skola24/get/timetable/viewer/units")
|
||||
if err != nil {
|
||||
return nil, errors.New("could not get schools: " + err.Error())
|
||||
}
|
||||
|
||||
// Assert the response type to a map[string]interface{}
|
||||
responseMap, ok := response.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unexpected response type")
|
||||
}
|
||||
|
||||
// Assert getTimetableViewerUnitsResponse to a type
|
||||
timetableMap, ok := responseMap["getTimetableViewerUnitsResponse"].(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("missing or invalid \"getTimetableViewerUnitsResponse\" field in response")
|
||||
}
|
||||
|
||||
// Get hostname
|
||||
hostname, ok := timetableMap["hostName"].(string)
|
||||
if !ok {
|
||||
return nil, errors.New("missing or invalid \"hostName\" field in response")
|
||||
}
|
||||
|
||||
// Extract units as []interface{}
|
||||
unitsRaw, ok := timetableMap["units"].([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("missing or invalid \"units\" field in response")
|
||||
}
|
||||
|
||||
// Convert units into a proper type
|
||||
var units []pubtypes.School
|
||||
for _, unitRaw := range unitsRaw {
|
||||
unitMap, ok := unitRaw.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.New("unexpected unit format")
|
||||
}
|
||||
|
||||
// Extract fields from each unit
|
||||
unitGuid, _ := unitMap["unitGuid"].(string)
|
||||
unitId, _ := unitMap["unitId"].(string)
|
||||
allowCalendarExport, _ := unitMap["allowCalendarExport"].(bool)
|
||||
anonMap, _ := unitMap["anonymous"].(map[string]interface{})
|
||||
|
||||
// Same for anonymous units
|
||||
hasClasses, _ := anonMap["classes"].(bool)
|
||||
hasCourses, _ := anonMap["courses"].(bool)
|
||||
hasGroups, _ := anonMap["groups"].(bool)
|
||||
hasResources, _ := anonMap["resources"].(bool)
|
||||
hasRooms, _ := anonMap["rooms"].(bool)
|
||||
hasStudents, _ := anonMap["students"].(bool)
|
||||
hasSubjects, _ := anonMap["subjects"].(bool)
|
||||
hasTeachers, _ := anonMap["teachers"].(bool)
|
||||
|
||||
availableData := pubtypes.DataAvailability{
|
||||
HasClasses: hasClasses,
|
||||
HasCourses: hasCourses,
|
||||
HasGroups: hasGroups,
|
||||
HasResources: hasResources,
|
||||
HasRooms: hasRooms,
|
||||
HasStudents: hasStudents,
|
||||
HasSubjects: hasSubjects,
|
||||
HasTeachers: hasTeachers,
|
||||
}
|
||||
|
||||
// Map to the struct
|
||||
unit := pubtypes.School{
|
||||
Name: unitId,
|
||||
SchoolId: unitGuid,
|
||||
HostName: hostname,
|
||||
AllowCalendarExport: allowCalendarExport,
|
||||
AvailableData: availableData,
|
||||
}
|
||||
|
||||
units = append(units, unit)
|
||||
}
|
||||
|
||||
return units, nil
|
||||
}
|
91
internal/requests/get_terms.go
Normal file
91
internal/requests/get_terms.go
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/types"
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/utility"
|
||||
pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types"
|
||||
)
|
||||
|
||||
func GetTerms(api_host string) (_result pubtypes.Terms, _error error) {
|
||||
request := types.RequestTerms{
|
||||
HostName: api_host,
|
||||
CheckSchoolYearsFeatures: false,
|
||||
}
|
||||
|
||||
response, err := utility.Request(request, "get/active/school/years")
|
||||
if err != nil {
|
||||
return pubtypes.Terms{}, errors.New("could not get terms: " + err.Error())
|
||||
}
|
||||
|
||||
// Assert the response type to a map[string]interface{}
|
||||
responseMap, ok := response.(map[string]interface{})
|
||||
if !ok {
|
||||
return pubtypes.Terms{}, errors.New("unexpected response type")
|
||||
}
|
||||
|
||||
// Assert useSchoolYearsFeatures to bool
|
||||
useYears, ok := responseMap["useSchoolYearsFeatures"].(bool)
|
||||
if !ok {
|
||||
useYears = false
|
||||
}
|
||||
|
||||
// Extract the "activeSchoolYears" value using type assertion
|
||||
extractedYears, ok := responseMap["activeSchoolYears"].([]interface{})
|
||||
if !ok {
|
||||
return pubtypes.Terms{}, errors.New("missing or invalid \"activeSchoolYears\" field in response")
|
||||
}
|
||||
|
||||
var schoolTerms []pubtypes.SchoolTerm
|
||||
|
||||
// Iterate over the school years
|
||||
for _, year := range extractedYears {
|
||||
yearMap, ok := year.(map[string]interface{})
|
||||
if !ok {
|
||||
return pubtypes.Terms{}, errors.New("unexpected type in activeSchoolYears slice")
|
||||
}
|
||||
|
||||
// Map to the struct
|
||||
schoolTerm := pubtypes.SchoolTerm{
|
||||
Start: yearMap["from"].(string),
|
||||
TermId: yearMap["guid"].(string),
|
||||
Name: yearMap["name"].(string),
|
||||
End: yearMap["to"].(string),
|
||||
}
|
||||
|
||||
schoolTerms = append(schoolTerms, schoolTerm)
|
||||
}
|
||||
|
||||
// Assemble result
|
||||
result := pubtypes.Terms{
|
||||
ActiveTerms: schoolTerms,
|
||||
UseSchoolYearsFeatures: useYears,
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
29
internal/types/data_key.go
Normal file
29
internal/types/data_key.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type DataRenderKey struct {
|
||||
Key string `json:"key"`
|
||||
}
|
36
internal/types/filters.go
Normal file
36
internal/types/filters.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type RequestFilters struct {
|
||||
Class bool `json:"class"`
|
||||
Course bool `json:"course"`
|
||||
Group bool `json:"group"`
|
||||
Period bool `json:"period"`
|
||||
Room bool `json:"room"`
|
||||
Student bool `json:"student"`
|
||||
Subject bool `json:"subject"`
|
||||
Teacher bool `json:"teacher"`
|
||||
}
|
33
internal/types/req_schools.go
Normal file
33
internal/types/req_schools.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type RequestSchoolsHost struct {
|
||||
HostName string `json:"hostName"`
|
||||
}
|
||||
|
||||
type RequestSchools struct {
|
||||
GetTimetableViewerUnitsRequest RequestSchoolsHost `json:"getTimetableViewerUnitsRequest"`
|
||||
}
|
31
internal/types/req_selection_base.go
Normal file
31
internal/types/req_selection_base.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type RequestSelectionBase struct {
|
||||
HostName string `json:"hostName"`
|
||||
UnitGuid string `json:"unitGuid"`
|
||||
Filters RequestFilters `json:"filters"`
|
||||
}
|
30
internal/types/req_terms.go
Normal file
30
internal/types/req_terms.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type RequestTerms struct {
|
||||
HostName string `json:"hostName"`
|
||||
CheckSchoolYearsFeatures bool `json:"checkSchoolYearsFeatures"`
|
||||
}
|
34
internal/types/response.go
Normal file
34
internal/types/response.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type BaseResponse struct {
|
||||
Error interface{} `json:"error"`
|
||||
Data interface{} `json:"data"`
|
||||
Exception interface{} `json:"exception"`
|
||||
Validation []interface{} `json:"validation"`
|
||||
SessionExpires interface{} `json:"sessionExpires"`
|
||||
NeedSessionRefresh bool `json:"needSessionRefresh"`
|
||||
}
|
50
internal/utility/key.go
Normal file
50
internal/utility/key.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package utility
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
func GetRendererKey() (_key string, _error error) {
|
||||
response, err := Request(nil, "get/timetable/render/key")
|
||||
if err != nil {
|
||||
return "", errors.New("could not get render key: " + err.Error())
|
||||
}
|
||||
|
||||
// Assert the response type to a map[string]interface{}
|
||||
responseMap, ok := response.(map[string]interface{})
|
||||
if !ok {
|
||||
return "", errors.New("unexpected response type")
|
||||
}
|
||||
|
||||
// Extract the "key" value using type assertion
|
||||
keyValue, ok := responseMap["key"].(string)
|
||||
if !ok {
|
||||
return "", errors.New("missing or invalid \"key\" field in response")
|
||||
}
|
||||
|
||||
return keyValue, nil
|
||||
}
|
76
internal/utility/request.go
Normal file
76
internal/utility/request.go
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package utility
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/types"
|
||||
)
|
||||
|
||||
func Request(data any, endpoint string) (_response interface{}, _error error) {
|
||||
const xscope string = "8a22163c-8662-4535-9050-bc5e1923df48" // Might need to change this
|
||||
|
||||
var url string = fmt.Sprintf("https://web.skola24.se/api/%s", endpoint)
|
||||
|
||||
// Enconde JSON
|
||||
jsonRequest, err := json.Marshal(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("could not encode json: " + err.Error())
|
||||
}
|
||||
|
||||
// Create the POST request
|
||||
postRequest, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonRequest))
|
||||
postRequest.Header.Add("Content-Type", "application/json")
|
||||
postRequest.Header.Add("X-Scope", xscope)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("could not create request: " + err.Error())
|
||||
}
|
||||
|
||||
// Send the POST request
|
||||
response, err := http.DefaultClient.Do(postRequest)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("request failed: " + err.Error())
|
||||
}
|
||||
|
||||
// Read body
|
||||
defer response.Body.Close()
|
||||
bodyBytes, _ := io.ReadAll(response.Body)
|
||||
|
||||
// Unmarshal response
|
||||
var responseData types.BaseResponse
|
||||
json.Unmarshal(bodyBytes, &responseData)
|
||||
|
||||
// Return as raw bytes (let consumer do type assertion)
|
||||
return responseData.Data, nil
|
||||
}
|
46
pkg/goskola24api/skola24api.go
Normal file
46
pkg/goskola24api/skola24api.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package goskola24api
|
||||
|
||||
import (
|
||||
"git.zervo.org/zervo/GoSkola24API/internal/requests"
|
||||
pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types"
|
||||
)
|
||||
|
||||
type Skola24API struct {
|
||||
Host string
|
||||
}
|
||||
|
||||
func (api Skola24API) GetTerms() (_result pubtypes.Terms, _error error) {
|
||||
return requests.GetTerms(api.Host)
|
||||
}
|
||||
|
||||
func (api Skola24API) GetSchools() (_result []pubtypes.School, _error error) {
|
||||
return requests.GetSchools(api.Host)
|
||||
}
|
||||
|
||||
func (api Skola24API) GetRooms(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Room, _error error) {
|
||||
return requests.GetRooms(school, checkAvailability)
|
||||
}
|
31
pkg/goskola24api/types/rooms.go
Normal file
31
pkg/goskola24api/types/rooms.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type Room struct {
|
||||
Name string `json:"name"`
|
||||
RoomId string `json:"roomId"`
|
||||
External bool `json:"external"`
|
||||
}
|
44
pkg/goskola24api/types/schools.go
Normal file
44
pkg/goskola24api/types/schools.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type School struct {
|
||||
Name string `json:"name"`
|
||||
SchoolId string `json:"schoolId"`
|
||||
HostName string `json:"hostName"`
|
||||
AllowCalendarExport bool `json:"allowCalendarExport"`
|
||||
AvailableData DataAvailability `json:"availableData"`
|
||||
}
|
||||
|
||||
type DataAvailability struct {
|
||||
HasClasses bool `json:"hasClasses"`
|
||||
HasCourses bool `json:"hasCourses"`
|
||||
HasGroups bool `json:"hasGroups"`
|
||||
HasResources bool `json:"hasResources"`
|
||||
HasRooms bool `json:"hasRooms"`
|
||||
HasStudents bool `json:"hasStudents"`
|
||||
HasSubjects bool `json:"hasSubjects"`
|
||||
HasTeachers bool `json:"hasTeachers"`
|
||||
}
|
37
pkg/goskola24api/types/terms.go
Normal file
37
pkg/goskola24api/types/terms.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
GoSkola24API
|
||||
Copyright (C) 2024, Marco Vitchi Thulin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
type SchoolTerm struct {
|
||||
Start string `json:"start"`
|
||||
TermId string `json:"termId"`
|
||||
Name string `json:"name"`
|
||||
End string `json:"end"`
|
||||
}
|
||||
|
||||
type Terms struct {
|
||||
ActiveTerms []SchoolTerm `json:"activeSchoolYears"`
|
||||
UseSchoolYearsFeatures bool `json:"useSchoolYearsFeatures"`
|
||||
}
|
Loading…
Reference in a new issue