mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-22 01:10:29 -05:00
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/cookiejar"
|
|
"os"
|
|
|
|
"golang.org/x/net/publicsuffix"
|
|
)
|
|
|
|
func initialize() {
|
|
base_link = "https://floridapolytechnic.instructure.com/api/v1"
|
|
token = os.Getenv("CANVAS_API_KEY")
|
|
|
|
jar, _ := cookiejar.New(&cookiejar.Options{
|
|
PublicSuffixList: publicsuffix.List,
|
|
})
|
|
|
|
client = http.Client{
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
fmt.Println("Redirected to:", req.URL)
|
|
fmt.Println(req.Cookies())
|
|
return nil
|
|
},
|
|
Jar: jar,
|
|
}
|
|
}
|
|
|
|
func get_courses(token string, link string, client http.Client) []CanvasCourse {
|
|
resp, err := client.Get(link)
|
|
if err != nil {
|
|
fmt.Println("Error performing GET request to get courses.")
|
|
return nil
|
|
}
|
|
defer resp.Body.Close()
|
|
body, _ := io.ReadAll(resp.Body)
|
|
|
|
var canvas_courses []CanvasCourse
|
|
err2 := json.Unmarshal(body, &canvas_courses)
|
|
if err2 != nil {
|
|
fmt.Println(err2)
|
|
return nil
|
|
}
|
|
|
|
return canvas_courses
|
|
}
|
|
|
|
// Need to change this to grab both ID and name, return as pairs.
|
|
func get_course_id_name_pair(canvas_courses []CanvasCourse) []uint64 {
|
|
var courses []uint64
|
|
|
|
for _, course := range canvas_courses {
|
|
courses = append(courses, course.ID%10000)
|
|
}
|
|
return courses
|
|
}
|
|
|
|
/*
|
|
func select_course() int {
|
|
// course selection by user happens below
|
|
favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token)
|
|
all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token)
|
|
var canvas_courses []CanvasCourse
|
|
canvas_courses = get_courses(token, favorites, client)
|
|
var course_ids []uint64
|
|
course_ids = get_course_ids(canvas_courses)
|
|
//selected := 1 // course_ids[selected]
|
|
// course selection by user happens above
|
|
return 0
|
|
}
|
|
*/
|