Skip to content

Commit cc27051

Browse files
committed
Update tmc-langs to 0.19.0
1 parent 0014f12 commit cc27051

8 files changed

Lines changed: 87 additions & 89 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ serde = "1"
2222
serde_json = "1"
2323
log = "0.4"
2424
dirs = "3"
25-
tmc-langs-util = { git = "https://github.com/rage/tmc-langs-rust/", rev = "13f3d55" }
26-
tmc-langs-framework = { git = "https://github.com/rage/tmc-langs-rust/", rev = "13f3d55" }
27-
tmc-langs = { git = "https://github.com/rage/tmc-langs-rust/", rev = "13f3d55" }
28-
tmc-client = { git = "https://github.com/rage/tmc-langs-rust/", rev = "13f3d55" }
25+
# rev 12f021b = 0.19.0
26+
tmc-langs-util = { git = "https://github.com/rage/tmc-langs-rust/", rev = "12f021b" }
27+
tmc-langs-framework = { git = "https://github.com/rage/tmc-langs-rust/", rev = "12f021b" }
28+
tmc-langs = { git = "https://github.com/rage/tmc-langs-rust/", rev = "12f021b" }
29+
tmc-client = { git = "https://github.com/rage/tmc-langs-rust/", rev = "12f021b" }
2930
rpassword = "5.0.1"
3031
mockall = "0.9.0"
3132
indicatif = "0.15.0"

src/commands/command_util.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use isolang::Language;
2+
use reqwest::Url;
23
use std::path::Path;
34
use std::path::PathBuf;
45

56
use std::env;
6-
use tmc_client::{
7-
ClientError, Course, CourseDetails, CourseExercise, ExercisesDetails, NewSubmission,
8-
Organization, SubmissionFinished, TmcClient, Token,
7+
use std::str::FromStr;
8+
use tmc_client::response::{
9+
Course, CourseDetails, CourseExercise, ExercisesDetails, NewSubmission, Organization,
10+
SubmissionFinished,
911
};
12+
use tmc_client::{ClientError, TmcClient, Token};
1013
use tmc_langs::Credentials;
1114
use tmc_langs::DownloadOrUpdateCourseExercisesResult;
1215
use tmc_langs::DownloadResult;
@@ -33,26 +36,26 @@ pub trait Client {
3336
fn list_courses(&mut self) -> Result<Vec<Course>, String>;
3437
fn get_organizations(&mut self) -> Result<Vec<Organization>, String>;
3538
fn logout(&mut self);
36-
fn wait_for_submission(&self, submission_url: &str) -> Result<SubmissionFinished, ClientError>;
39+
fn wait_for_submission(&self, submission_url: Url) -> Result<SubmissionFinished, ClientError>;
3740
fn submit(
3841
&self,
3942
projects_dir: &Path,
4043
course_slug: &str,
4144
exercise_slug: &str,
4245
locale: Option<Language>,
4346
) -> Result<NewSubmission, LangsError>;
44-
fn get_course_exercises(&mut self, course_id: usize) -> Result<Vec<CourseExercise>, String>;
47+
fn get_course_exercises(&mut self, course_id: u32) -> Result<Vec<CourseExercise>, String>;
4548
fn get_exercise_details(
4649
&mut self,
47-
exercise_ids: Vec<usize>,
50+
exercise_ids: Vec<u32>,
4851
) -> Result<Vec<ExercisesDetails>, String>;
4952
fn download_or_update_exercises(
5053
&mut self,
51-
download_params: &[usize],
54+
download_params: &[u32],
5255
path: &Path,
5356
) -> Result<DownloadResult, LangsError>;
5457
fn is_test_mode(&mut self) -> bool;
55-
fn get_course_details(&self, course_id: usize) -> Result<CourseDetails, ClientError>;
58+
fn get_course_details(&self, course_id: u32) -> Result<CourseDetails, ClientError>;
5659
fn get_organization(&self, organization_slug: &str) -> Result<Organization, ClientError>;
5760
fn update_exercises(
5861
&mut self,
@@ -68,11 +71,10 @@ pub trait Client {
6871
) -> Result<NewSubmission, String>;
6972
}
7073

71-
static SERVER_ADDRESS: &str = "https://tmc.mooc.fi";
7274
impl ClientProduction {
7375
pub fn new(test_mode: bool) -> Self {
7476
let (tmc_client, _credentials) = tmc_langs::init_tmc_client_with_credentials(
75-
SERVER_ADDRESS.to_string(),
77+
Url::from_str("https://tmc.mooc.fi").expect(""),
7678
PLUGIN,
7779
"1.0.0",
7880
)
@@ -165,10 +167,7 @@ impl Client for ClientProduction {
165167
}
166168

167169
if let Some(credentials) = get_credentials() {
168-
match self.tmc_client.set_token(credentials.token()) {
169-
Ok(()) => return Ok(()),
170-
_ => return Err("Setting login token failed".to_string()),
171-
}
170+
self.tmc_client.set_token(credentials.token());
172171
}
173172
Err("No login found. You need to be logged in to use this command".to_string())
174173
}
@@ -256,7 +255,7 @@ impl Client for ClientProduction {
256255
}
257256
Ok(course_list)
258257
}
259-
Err(ClientError::NotLoggedIn) => {
258+
Err(ClientError::NotAuthenticated) => {
260259
Err("Login token is invalid. Please try logging in again.".to_string())
261260
}
262261
_ => Err("Unknown error. Please try again.".to_string()),
@@ -318,8 +317,8 @@ impl Client for ClientProduction {
318317
credentials.remove().unwrap();
319318
}
320319

321-
fn wait_for_submission(&self, submission_url: &str) -> Result<SubmissionFinished, ClientError> {
322-
self.tmc_client.wait_for_submission(submission_url)
320+
fn wait_for_submission(&self, submission_url: Url) -> Result<SubmissionFinished, ClientError> {
321+
self.tmc_client.wait_for_submission_at(submission_url)
323322
}
324323
fn update_exercises(
325324
&mut self,
@@ -359,7 +358,7 @@ impl Client for ClientProduction {
359358
)
360359
}
361360

362-
fn get_course_exercises(&mut self, course_id: usize) -> Result<Vec<CourseExercise>, String> {
361+
fn get_course_exercises(&mut self, course_id: u32) -> Result<Vec<CourseExercise>, String> {
363362
if self.test_mode {
364363
return Ok(vec![CourseExercise {
365364
id: 0,
@@ -376,7 +375,7 @@ impl Client for ClientProduction {
376375
}
377376
match self.tmc_client.get_course_exercises(course_id) {
378377
Ok(exercises) => Ok(exercises),
379-
Err(ClientError::NotLoggedIn) => {
378+
Err(ClientError::NotAuthenticated) => {
380379
Err("Login token is invalid. Please try logging in again.".to_string())
381380
}
382381
_ => Err("Unknown error. Please try again.".to_string()),
@@ -385,7 +384,7 @@ impl Client for ClientProduction {
385384

386385
fn get_exercise_details(
387386
&mut self,
388-
exercise_ids: Vec<usize>,
387+
exercise_ids: Vec<u32>,
389388
) -> Result<Vec<ExercisesDetails>, String> {
390389
if self.test_mode {
391390
return Ok(vec![ExercisesDetails {
@@ -403,7 +402,7 @@ impl Client for ClientProduction {
403402

404403
fn download_or_update_exercises(
405404
&mut self,
406-
exercise_ids: &[usize],
405+
exercise_ids: &[u32],
407406
path: &Path,
408407
) -> Result<DownloadResult, LangsError> {
409408
if self.test_mode {
@@ -416,7 +415,7 @@ impl Client for ClientProduction {
416415
tmc_langs::download_or_update_course_exercises(&self.tmc_client, path, exercise_ids, true)
417416
}
418417

419-
fn get_course_details(&self, course_id: usize) -> Result<CourseDetails, ClientError> {
418+
fn get_course_details(&self, course_id: u32) -> Result<CourseDetails, ClientError> {
420419
if self.test_mode {
421420
let course = Course {
422421
id: 0,
@@ -496,11 +495,11 @@ pub fn set_organization(org: &str) -> Result<(), String> {
496495
Ok(())
497496
}
498497

499-
/// Returns course id as: Ok(Some(usize)) or Ok(None) if not found, Err(msg) if could not get id list
498+
/// Returns course id as: Ok(Some(u32)) or Ok(None) if not found, Err(msg) if could not get id list
500499
pub fn get_course_id_by_name(
501500
client: &mut dyn Client,
502501
course_name: String,
503-
) -> Result<Option<usize>, String> {
502+
) -> Result<Option<u32>, String> {
504503
match client.list_courses() {
505504
Ok(courses) => {
506505
for course in courses {

0 commit comments

Comments
 (0)