Struct TestMyCodeClient

Source
pub struct TestMyCodeClient(/* private fields */);
Expand description

A struct for interacting with the TestMyCode service, including authentication.

Implementations§

Source§

impl TestMyCodeClient

Source

pub fn require_authentication(&self) -> Result<(), TestMyCodeClientError>

Convenience function for checking authentication.

Source

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();
Source

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.

Source

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();
Source

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.

Source

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.

Source

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.

Source

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();
Source

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.

Source

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.

Source

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.

Source

pub fn download_model_solution_archive( &self, exercise_id: u32, target: &mut dyn Write, ) -> TestMyCodeClientResult<()>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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();
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> TestMyCodeClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,