pub struct TestMyCodeClient(/* private fields */);Expand description
A struct for interacting with the TestMyCode service, including authentication.
Implementations§
Source§impl TestMyCodeClient
impl TestMyCodeClient
Sourcepub fn require_authentication(&self) -> Result<(), TestMyCodeClientError>
pub fn require_authentication(&self) -> Result<(), TestMyCodeClientError>
Convenience function for checking authentication.
Sourcepub fn new(
root_url: Url,
client_name: String,
client_version: String,
) -> TestMyCodeClientResult<Self>
pub fn new( root_url: Url, client_name: String, client_version: String, ) -> TestMyCodeClientResult<Self>
Creates a new TestMyCodeClient with the given config directory and root URL.
§Panics
If the root URL does not have a trailing slash and is not a valid URL with an appended trailing slash.
§Examples
use tmc_testmycode_client::TestMyCodeClient;
let client = TestMyCodeClient::new("https://tmc.mooc.fi".parse().unwrap(), "some_client".to_string(), "some_version".to_string()).unwrap();Sourcepub fn set_token(&mut self, token: Token)
pub fn set_token(&mut self, token: Token)
Sets the authentication token, which may for example have been read from a file.
§Panics
If called when multiple clones of the client exist. Call this function before cloning.
Sourcepub fn authenticate(
&mut self,
email: String,
password: String,
) -> TestMyCodeClientResult<Token>
pub fn authenticate( &mut self, email: String, password: String, ) -> TestMyCodeClientResult<Token>
Attempts to log in with the given credentials, returns an error if an authentication token is already present. Username can be the user’s username or email.
§Errors
This function will return an error if the client has already been authenticated, if the client_name is malformed and leads to a malformed URL, or if there is some error during the token exchange (see oauth2::Client::excange_password).
§Panics
If called when multiple clones exist. Call this function before cloning.
§Examples
use tmc_testmycode_client::TestMyCodeClient;
let mut client = TestMyCodeClient::new("https://tmc.mooc.fi".parse().unwrap(), "some_client".to_string(), "some_version".to_string()).unwrap();
client.authenticate("user".to_string(), "pass".to_string()).unwrap();Sourcepub fn get_exercises_details(
&self,
exercise_ids: &[u32],
) -> TestMyCodeClientResult<Vec<ExercisesDetails>>
pub fn get_exercises_details( &self, exercise_ids: &[u32], ) -> TestMyCodeClientResult<Vec<ExercisesDetails>>
Fetches the course’s information. Does not require authentication.
§Errors
If there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn submit(
&self,
exercise_id: u32,
submission_path: &Path,
submission_size_limit_mb: u32,
locale: Option<Language>,
) -> TestMyCodeClientResult<NewSubmission>
pub fn submit( &self, exercise_id: u32, submission_path: &Path, submission_size_limit_mb: u32, locale: Option<Language>, ) -> TestMyCodeClientResult<NewSubmission>
Sends the submission to the server. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn download_old_submission(
&self,
submission_id: u32,
target: &mut dyn Write,
) -> TestMyCodeClientResult<()>
pub fn download_old_submission( &self, submission_id: u32, target: &mut dyn Write, ) -> TestMyCodeClientResult<()>
Downloads an old submission. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn paste(
&self,
exercise_id: u32,
submission_path: &Path,
paste_message: Option<String>,
locale: Option<Language>,
submission_size_limit_mb: u32,
) -> TestMyCodeClientResult<NewSubmission>
pub fn paste( &self, exercise_id: u32, submission_path: &Path, paste_message: Option<String>, locale: Option<Language>, submission_size_limit_mb: u32, ) -> TestMyCodeClientResult<NewSubmission>
Sends the given submission as a paste. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
§Examples
use tmc_testmycode_client::{TestMyCodeClient, Language};
use url::Url;
use std::path::Path;
let client = TestMyCodeClient::new("https://tmc.mooc.fi".parse().unwrap(), "some_client".to_string(), "some_version".to_string()).unwrap();
// authenticate
let new_submission = client.paste(
123,
Path::new("./exercises/python/123"),
Some("my python solution".to_string()),
Some(Language::Eng),
1,
).unwrap();Sourcepub fn get_exercise_submissions_for_current_user(
&self,
exercise_id: u32,
) -> TestMyCodeClientResult<Vec<Submission>>
pub fn get_exercise_submissions_for_current_user( &self, exercise_id: u32, ) -> TestMyCodeClientResult<Vec<Submission>>
Fetches exercise submissions for the authenticated user. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn download_exercise(
&self,
exercise_id: u32,
target: &mut dyn Write,
) -> TestMyCodeClientResult<()>
pub fn download_exercise( &self, exercise_id: u32, target: &mut dyn Write, ) -> TestMyCodeClientResult<()>
Request code review. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn download_model_solution(
&self,
exercise_id: u32,
target: &Path,
) -> TestMyCodeClientResult<()>
pub fn download_model_solution( &self, exercise_id: u32, target: &Path, ) -> TestMyCodeClientResult<()>
Downloads the model solution from the given url. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error. The method extracts the downloaded model solution archive, which may fail.
pub fn download_model_solution_archive( &self, exercise_id: u32, target: &mut dyn Write, ) -> TestMyCodeClientResult<()>
Sourcepub fn get_course_details(
&self,
course_id: u32,
) -> TestMyCodeClientResult<CourseDetails>
pub fn get_course_details( &self, course_id: u32, ) -> TestMyCodeClientResult<CourseDetails>
Fetches the course’s information. Requires authentication.
§Errors
If not authenticated, or if there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_course_exercises(
&self,
course_id: u32,
) -> TestMyCodeClientResult<Vec<CourseExercise>>
pub fn get_course_exercises( &self, course_id: u32, ) -> TestMyCodeClientResult<Vec<CourseExercise>>
Fetches the given course’s exercises. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_course(&self, course_id: u32) -> TestMyCodeClientResult<CourseData>
pub fn get_course(&self, course_id: u32) -> TestMyCodeClientResult<CourseData>
Fetches the given course’s data. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn list_courses(
&self,
organization_slug: &str,
) -> TestMyCodeClientResult<Vec<Course>>
pub fn list_courses( &self, organization_slug: &str, ) -> TestMyCodeClientResult<Vec<Course>>
Fetches all courses under the given organization. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_exercise_details(
&self,
exercise_id: u32,
) -> TestMyCodeClientResult<ExerciseDetails>
pub fn get_exercise_details( &self, exercise_id: u32, ) -> TestMyCodeClientResult<ExerciseDetails>
Fetches the exercise’s details. Requires authentication.
§Errors
If not authenticated, or if there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_exercise_updates(
&self,
course_id: u32,
checksums: HashMap<u32, String>,
) -> TestMyCodeClientResult<UpdateResult>
pub fn get_exercise_updates( &self, course_id: u32, checksums: HashMap<u32, String>, ) -> TestMyCodeClientResult<UpdateResult>
Fetches the course’s exercises from the server, and finds new or updated exercises. Requires authentication. If an exercise’s id is not found in the checksum map, it is considered new. If an id is found, it is compared to the current one. If they are different, it is considered updated.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
§Examples
use tmc_testmycode_client::TestMyCodeClient;
let client = TestMyCodeClient::new("https://tmc.mooc.fi".parse().unwrap(), "some_client".to_string(), "some_version".to_string()).unwrap();
// authenticate
let mut checksums = std::collections::HashMap::new();
checksums.insert(1234, "exercisechecksum".to_string());
let update_result = client.get_exercise_updates(600, checksums).unwrap();Sourcepub fn get_organization(
&self,
organization_slug: &str,
) -> TestMyCodeClientResult<Organization>
pub fn get_organization( &self, organization_slug: &str, ) -> TestMyCodeClientResult<Organization>
Fetches an organization. Does not require authentication.
§Errors
Returns an error if there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_organizations(&self) -> TestMyCodeClientResult<Vec<Organization>>
pub fn get_organizations(&self) -> TestMyCodeClientResult<Vec<Organization>>
Fetches all organizations. Does not require authentication.
§Errors
Returns an error if there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn get_unread_reviews(
&self,
course_id: u32,
) -> TestMyCodeClientResult<Vec<Review>>
pub fn get_unread_reviews( &self, course_id: u32, ) -> TestMyCodeClientResult<Vec<Review>>
Fetches unread reviews. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn mark_review_as_read(
&self,
course_id: u32,
review_id: u32,
) -> TestMyCodeClientResult<()>
pub fn mark_review_as_read( &self, course_id: u32, review_id: u32, ) -> TestMyCodeClientResult<()>
Mark the review as read on the server. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn request_code_review(
&self,
exercise_id: u32,
submission_path: &Path,
message_for_reviewer: Option<String>,
locale: Option<Language>,
submission_size_limit_mb: u32,
) -> TestMyCodeClientResult<NewSubmission>
pub fn request_code_review( &self, exercise_id: u32, submission_path: &Path, message_for_reviewer: Option<String>, locale: Option<Language>, submission_size_limit_mb: u32, ) -> TestMyCodeClientResult<NewSubmission>
Request code review. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn send_feedback(
&self,
submission_id: u32,
feedback: Vec<FeedbackAnswer>,
) -> TestMyCodeClientResult<SubmissionFeedbackResponse>
pub fn send_feedback( &self, submission_id: u32, feedback: Vec<FeedbackAnswer>, ) -> TestMyCodeClientResult<SubmissionFeedbackResponse>
Sends feedback. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn send_feedback_to_url(
&self,
feedback_url: Url,
feedback: Vec<FeedbackAnswer>,
) -> TestMyCodeClientResult<SubmissionFeedbackResponse>
pub fn send_feedback_to_url( &self, feedback_url: Url, feedback: Vec<FeedbackAnswer>, ) -> TestMyCodeClientResult<SubmissionFeedbackResponse>
Posts feedback to the given URL. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn wait_for_submission(
&self,
submission_id: u32,
) -> TestMyCodeClientResult<SubmissionFinished>
pub fn wait_for_submission( &self, submission_id: u32, ) -> TestMyCodeClientResult<SubmissionFinished>
Waits for a submission to finish. Requires authentication.
§Errors
If not authenticated, there’s some problem reaching the API, or if the API returns an error.
Sourcepub fn wait_for_submission_at(
&self,
submission_url: Url,
) -> TestMyCodeClientResult<SubmissionFinished>
pub fn wait_for_submission_at( &self, submission_url: Url, ) -> TestMyCodeClientResult<SubmissionFinished>
Waits for a submission to finish at the given URL. May require authentication
§Errors
If authentication is required but the client is not authenticated, there’s some problem reaching the API, or if the API returns an error.
Trait Implementations§
Source§impl Clone for TestMyCodeClient
impl Clone for TestMyCodeClient
Source§fn clone(&self) -> TestMyCodeClient
fn clone(&self) -> TestMyCodeClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more