diff options
| author | Juan Roig <jaroig@outlook.com> | 2023-10-27 19:02:38 -0400 |
|---|---|---|
| committer | Juan Roig <jaroig@outlook.com> | 2023-10-27 19:02:38 -0400 |
| commit | 41a98cfe6012afc3bb02a027bdf04c8a9fa422ad (patch) | |
| tree | 781f6b13e69d3d3f8a09cd7483a957839a8990df /main.go | |
| parent | 3da2c17e49e6a68b4dd1f0d90d351d4a03f116b2 (diff) | |
first commit
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 82 |
1 files changed, 82 insertions, 0 deletions
| @@ -0,0 +1,82 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "encoding/json" | ||
| 5 | "fmt" | ||
| 6 | "io" | ||
| 7 | "net/http" | ||
| 8 | ) | ||
| 9 | |||
| 10 | func get_courses(token string, link string) []CanvasCourse { | ||
| 11 | resp, err := http.Get(link) | ||
| 12 | if err != nil { | ||
| 13 | // handle error | ||
| 14 | } | ||
| 15 | defer resp.Body.Close() | ||
| 16 | body, err := io.ReadAll(resp.Body) | ||
| 17 | |||
| 18 | var canvas_courses []CanvasCourse | ||
| 19 | err2 := json.Unmarshal(body, &canvas_courses) | ||
| 20 | if err2 != nil { | ||
| 21 | fmt.Println(err2) | ||
| 22 | return nil | ||
| 23 | } | ||
| 24 | |||
| 25 | return canvas_courses | ||
| 26 | } | ||
| 27 | |||
| 28 | func get_aplus(token string, link string) string { | ||
| 29 | resp, err := http.Get(link) | ||
| 30 | |||
| 31 | if err != nil { | ||
| 32 | // handle error | ||
| 33 | } | ||
| 34 | defer resp.Body.Close() | ||
| 35 | body, err := io.ReadAll(resp.Body) | ||
| 36 | var aplus Aplus | ||
| 37 | json.Unmarshal(body, &aplus) | ||
| 38 | |||
| 39 | return aplus.URL | ||
| 40 | } | ||
| 41 | |||
| 42 | func get_course_ids(canvas_courses []CanvasCourse) []uint64 { | ||
| 43 | var courses []uint64 | ||
| 44 | |||
| 45 | for _, course := range canvas_courses { | ||
| 46 | courses = append(courses, course.ID%10000) | ||
| 47 | } | ||
| 48 | return courses | ||
| 49 | } | ||
| 50 | |||
| 51 | func main() { | ||
| 52 | |||
| 53 | // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token | ||
| 54 | base_link := "https://floridapolytechnic.instructure.com/api/v1" | ||
| 55 | token := "instructure api key" | ||
| 56 | //favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token) | ||
| 57 | //all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link,token) | ||
| 58 | |||
| 59 | //var canvas_courses []CanvasCourse | ||
| 60 | //canvas_courses = get_courses(token, favorites) | ||
| 61 | //var course_ids []uint64 | ||
| 62 | //course_ids = get_course_ids(canvas_courses) | ||
| 63 | |||
| 64 | //selected := 1 // course_ids[selected] | ||
| 65 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works | ||
| 66 | var aplus string | ||
| 67 | aplus = get_aplus(token, aplus_link) | ||
| 68 | fmt.Println(aplus) | ||
| 69 | |||
| 70 | resp, err := http.Get(aplus) | ||
| 71 | |||
| 72 | if err != nil { | ||
| 73 | // handle error | ||
| 74 | } | ||
| 75 | |||
| 76 | //fmt.Println(resp) | ||
| 77 | |||
| 78 | defer resp.Body.Close() | ||
| 79 | body, err := io.ReadAll(resp.Body) | ||
| 80 | |||
| 81 | fmt.Println(string(body)) | ||
| 82 | } | ||
