diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 107 |
1 files changed, 102 insertions, 5 deletions
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | "fmt" | 5 | "fmt" |
| 6 | "io" | 6 | "io" |
| 7 | "net/http" | 7 | "net/http" |
| 8 | "strings" | ||
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | func get_courses(token string, link string, client http.Client) []CanvasCourse { | 11 | func get_courses(token string, link string, client http.Client) []CanvasCourse { |
| @@ -58,21 +59,22 @@ func main() { | |||
| 58 | 59 | ||
| 59 | // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token | 60 | // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token |
| 60 | base_link := "https://floridapolytechnic.instructure.com/api/v1" | 61 | base_link := "https://floridapolytechnic.instructure.com/api/v1" |
| 61 | token := "insert api key here" | 62 | token := "token here" |
| 63 | |||
| 64 | // course selection by user happens below | ||
| 62 | //favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token) | 65 | //favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token) |
| 63 | //all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link,token) | 66 | //all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link,token) |
| 64 | |||
| 65 | //var canvas_courses []CanvasCourse | 67 | //var canvas_courses []CanvasCourse |
| 66 | //canvas_courses = get_courses(token, favorites, client) | 68 | //canvas_courses = get_courses(token, favorites, client) |
| 67 | //var course_ids []uint64 | 69 | //var course_ids []uint64 |
| 68 | //course_ids = get_course_ids(canvas_courses) | 70 | //course_ids = get_course_ids(canvas_courses) |
| 69 | |||
| 70 | //selected := 1 // course_ids[selected] | 71 | //selected := 1 // course_ids[selected] |
| 72 | // course selection by user happens above | ||
| 73 | |||
| 71 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works | 74 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works |
| 72 | var aplus string | 75 | var aplus string |
| 73 | aplus = get_aplus(token, aplus_link, client) | 76 | aplus = get_aplus(token, aplus_link, client) |
| 74 | fmt.Println(aplus) | 77 | fmt.Println(aplus) |
| 75 | |||
| 76 | resp, err := client.Get(aplus) | 78 | resp, err := client.Get(aplus) |
| 77 | 79 | ||
| 78 | if err != nil { | 80 | if err != nil { |
| @@ -82,9 +84,104 @@ func main() { | |||
| 82 | //fmt.Println(resp) | 84 | //fmt.Println(resp) |
| 83 | 85 | ||
| 84 | defer resp.Body.Close() | 86 | defer resp.Body.Close() |
| 85 | //body, err := io.ReadAll(resp.Body) | 87 | body, err := io.ReadAll(resp.Body) |
| 86 | 88 | ||
| 87 | //fmt.Println(string(body)) | 89 | //fmt.Println(string(body)) |
| 88 | //fmt.Println(resp) | 90 | //fmt.Println(resp) |
| 91 | //fmt.Println("Status code:", resp.StatusCode) | ||
| 92 | |||
| 93 | if err != nil { | ||
| 94 | // handle error | ||
| 95 | } | ||
| 96 | |||
| 97 | body_str := string(body) | ||
| 98 | |||
| 99 | form_start := strings.Index(body_str, "<form") | ||
| 100 | form_end := strings.Index(body_str, "</form>") + 7 | ||
| 101 | form_html := body[form_start:form_end] | ||
| 102 | |||
| 103 | fmt.Println(string(form_html)) | ||
| 89 | 104 | ||
| 90 | } | 105 | } |
| 106 | |||
| 107 | /* | ||
| 108 | |||
| 109 | The code below takes the form that defines the post request we must perform to the aplusattendance.com site, and actually maps it to a request. | ||
| 110 | what I have to do is programmatically grab that form, translate it on the fly, and submit the request rather than doing this manually. | ||
| 111 | // Define the form data as a map of key-value pairs. | ||
| 112 | formData := map[string]string{ | ||
| 113 | "oauth_consumer_key": "aplus-attendance", | ||
| 114 | "oauth_signature_method": "HMAC-SHA1", | ||
| 115 | "oauth_timestamp": "1698650339", | ||
| 116 | "oauth_nonce": "nV9EswFv8LtXXRVgRmWW8NSQ7mO3Sheeqi1SjJWPJGE", | ||
| 117 | "oauth_version": "1.0", | ||
| 118 | "context_id": "0c1f49ff7b35cba2226f93e9cbb84ae810ed00ab", | ||
| 119 | "context_label": "CIS4367.01I&T", | ||
| 120 | "context_title": "Computer Security(FA 2023_CIS4367.01 I&T", | ||
| 121 | "custom_canvas_api_domain": "floridapolytechnic.instructure.com", | ||
| 122 | "custom_canvas_course_id": "7329", | ||
| 123 | "custom_canvas_enrollment_state": "active", | ||
| 124 | "custom_canvas_user_id": "6858", | ||
| 125 | "custom_canvas_user_login_id": "jroig9590", | ||
| 126 | "custom_canvas_workflow_state": "available", | ||
| 127 | "ext_roles": "urn:lti:instrole:ims/lis/Student,urn:lti:role:ims/lis/Learner,urn:lti:sysrole:ims/lis/User", | ||
| 128 | "launch_presentation_document_target": "iframe", | ||
| 129 | "launch_presentation_locale": "en", | ||
| 130 | "launch_presentation_return_url": "https://floridapolytechnic.instructure.com/courses/7329", | ||
| 131 | "lis_course_offering_sourcedid": "7093", | ||
| 132 | "lis_person_contact_email_primary": "jroig9590@floridapoly.edu", | ||
| 133 | "lis_person_name_family": "Roig", | ||
| 134 | "lis_person_name_full": "Juan Roig", | ||
| 135 | "lis_person_name_given": "Juan", | ||
| 136 | "lis_person_sourcedid": "10308", | ||
| 137 | "lti_message_type": "basic-lti-launch-request", | ||
| 138 | "lti_version": "LTI-1p0", | ||
| 139 | "oauth_callback": "about:blank", | ||
| 140 | "resource_link_id": "0c1f49ff7b35cba2226f93e9cbb84ae810ed00ab", | ||
| 141 | "resource_link_title": "aPlus+ Attendance", | ||
| 142 | "roles": "Learner", | ||
| 143 | "tool_consumer_info_product_family_code": "canvas", | ||
| 144 | "tool_consumer_info_version": "cloud", | ||
| 145 | "tool_consumer_instance_contact_email": "notifications@instructure.com", | ||
| 146 | "tool_consumer_instance_guid": "7db438071375c02373713c12c73869ff2f470b68.floridapolytechnic.instructure.com", | ||
| 147 | "tool_consumer_instance_name": "Florida Polytechnic University", | ||
| 148 | "user_id": "91ba5b390440f646d9d4c47a0dc14f91cf595887", | ||
| 149 | "user_image": "https://canvas.instructure.com/images/messages/avatar-50.png", | ||
| 150 | "oauth_signature": "u3mIfUZ+qgSN4zzk0Ipklc0A7KU=", | ||
| 151 | } | ||
| 152 | |||
| 153 | // Create an HTTP client | ||
| 154 | client := &http.Client{} | ||
| 155 | |||
| 156 | // Create a new request | ||
| 157 | req, err := http.NewRequest("POST", "https://floridapoly.aplusattendance.com/canvas", bytes.NewBuffer([]byte{})) | ||
| 158 | if err != nil { | ||
| 159 | fmt.Println("Error creating the request:", err) | ||
| 160 | return | ||
| 161 | } | ||
| 162 | |||
| 163 | // Add the form data as URL-encoded values to the request | ||
| 164 | q := req.URL.Query() | ||
| 165 | for key, value := range formData { | ||
| 166 | q.Add(key, value) | ||
| 167 | } | ||
| 168 | req.URL.RawQuery = q.Encode() | ||
| 169 | |||
| 170 | // Set the appropriate content type for the form | ||
| 171 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 172 | |||
| 173 | // Perform the POST request | ||
| 174 | resp, err := client.Do(req) | ||
| 175 | if err != nil { | ||
| 176 | fmt.Println("Error sending the POST request:", err) | ||
| 177 | return | ||
| 178 | } | ||
| 179 | defer resp.Body.Close() | ||
| 180 | |||
| 181 | // Check the response | ||
| 182 | if resp.StatusCode == http.StatusOK { | ||
| 183 | fmt.Println("Request successful. You may need to parse and process the response body if applicable.") | ||
| 184 | } else { | ||
| 185 | fmt.Println("Request failed with status code:", resp.Status) | ||
| 186 | } | ||
| 187 | */ | ||
