summaryrefslogtreecommitdiff
path: root/canvas.go
diff options
context:
space:
mode:
Diffstat (limited to 'canvas.go')
-rw-r--r--canvas.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/canvas.go b/canvas.go
index df5f94c..5a43999 100644
--- a/canvas.go
+++ b/canvas.go
@@ -2,20 +2,21 @@ package main
2 2
3import ( 3import (
4 "encoding/json" 4 "encoding/json"
5 "errors"
5 "fmt" 6 "fmt"
6 "io" 7 "io"
7 "net/http" 8 "net/http"
8 "net/http/cookiejar" 9 "net/http/cookiejar"
9 "os" 10 "os"
11 "strings"
10 12
11 "golang.org/x/net/publicsuffix" 13 "golang.org/x/net/publicsuffix"
12) 14)
13 15
14func initialize() { 16func initialize() {
15 base_link = "https://floridapolytechnic.instructure.com/api/v1" 17 instance_url := "https://floridapolytechnic.instructure.com"
16 base_aplus_link = "https://floridapoly.aplusattendance.com/canvas" 18 base_link = instance_url + "/api/v1"
17 token = os.Getenv("CANVAS_API_KEY") 19 token = os.Getenv("CANVAS_API_KEY")
18 external_tools_code = 913
19 jar, _ := cookiejar.New(&cookiejar.Options{ 20 jar, _ := cookiejar.New(&cookiejar.Options{
20 PublicSuffixList: publicsuffix.List, 21 PublicSuffixList: publicsuffix.List,
21 }) 22 })
@@ -49,6 +50,31 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse {
49 return canvas_courses 50 return canvas_courses
50} 51}
51 52
53func init_aplus_toolid(course_id int) error {
54 link := fmt.Sprintf("%s/courses/%d/external_tools?access_token=%s&search_term=aplus&include_parents=true", base_link, course_id, token)
55 resp, err := client.Get(link)
56 if err != nil {
57 return err
58 }
59 defer resp.Body.Close()
60 body, _ := io.ReadAll(resp.Body)
61
62 var external_tools []ExternalTool
63 err = json.Unmarshal(body, &external_tools)
64 if err != nil && !strings.Contains(string(body), "\"unauthorized\"") {
65 return err
66 }
67
68 for _, tool := range external_tools {
69 if strings.Contains(tool.URL, ".aplusattendance.com/") && base_aplus_link == "" {
70 base_aplus_link = tool.URL
71 external_tools_code = tool.ID
72 }
73 }
74
75 return errors.New("Could not find A+ link and tool ID")
76}
77
52func list_all_courses() { 78func list_all_courses() {
53 all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token) 79 all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token)
54 80