further simplify launch_aplus function and get_aplus function

This commit is contained in:
Juan Roig 2023-11-13 02:56:01 -05:00
parent e46ca43d4c
commit a8b1886d86

View File

@ -10,13 +10,25 @@ import (
"strings"
)
func get_aplus(token string, link string, client http.Client) string {
resp, err := client.Get(link)
func launch_aplus(course_code int) {
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, course_code, token) // 7329 always works
aplus := get_aplus(token, aplus_link, client)
resp, _ := client.Get(aplus)
body, _ := io.ReadAll(resp.Body)
form_str := get_form_from_request_body(body)
form_values := parse_form(form_str)
resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
body, _ = io.ReadAll(resp.Body)
fmt.Println(string(body))
}
func get_aplus(token string, link string, client http.Client) string {
resp, _ := client.Get(link)
if err != nil {
fmt.Println("Error performing GET request to initial link.")
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var aplus Aplus
@ -75,31 +87,3 @@ func extract_attribute(input string, attribute string) string {
return input[start : start+end]
}
func launch_aplus(course_code int) {
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, course_code, token) // 7329 always works
aplus := get_aplus(token, aplus_link, client)
resp, err := client.Get(aplus)
if err != nil {
fmt.Println("Error while performing GET request to aplus auth link.")
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
form_str := get_form_from_request_body(body)
form_values := parse_form(form_str)
resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
body, err = io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading body of post form response from aplus attendance.")
}
fmt.Println(string(body))
}