public User[] GetInstructors(string course_id) { HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, String.Format(Properties.Resources.API_LIST_USERS_TEACHER, course_id)); HttpResponseMessage resp = client.SendAsync(req).Result; JArray instrs = JArray.Parse(resp.Content.ReadAsStringAsync().Result); User[] instructors = new User[instrs.Count]; for (int i = 0; i < instrs.Count; ++i) { instructors[i] = new User((string)instrs[i]["id"], (string)instrs[i]["name"]); } return instructors; }
// Get the students in a course public User[] GetStudents(string course_id, int current_page) { HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, String.Format(Properties.Resources.API_LIST_USERS_STUDENT, course_id)); HttpResponseMessage resp = client.SendAsync(req).Result; JArray users = JArray.Parse(resp.Content.ReadAsStringAsync().Result); User[] students = new User[users.Count]; for (int i = 0; i < users.Count; ++i) { students[i] = new User((string)users[i]["id"], (string)users[i]["name"], (string)users[i]["sortable_name"]); } return students; }
private void MainWindow_Load(object sender, EventArgs e) { AccessToken = TokenFileExists() ? ReadTokenFile() : GetAccessTokenAndWrite(); client = new CanvasConnector(AccessToken); // Try to grab the courses try { courses = client.ListCourses(); } catch (Newtonsoft.Json.JsonReaderException) { // Probably tried to parse a non-json object // ...which means Canvas changed API or AccessToken was wrong MessageBox.Show("Canvas did not accept your access token. You will need to reenter it.", "Invalid Access Token"); File.Delete(AccessTokenFilename); this.Close(); } foreach (Course c in courses) { CoursesListBox.Items.Add(c.toString()); } loggedInUser = client.GetUser(); this.Text = String.Format("Logged in as {0}", loggedInUser.Name()); }