Skip to content

Commit b6cc14f

Browse files
authored
Merge pull request #177 from rage/client-refactoring
Client refactoring
2 parents 7a141a5 + 5103601 commit b6cc14f

File tree

24 files changed

+3412
-1847
lines changed

24 files changed

+3412
-1847
lines changed

plugins/python3/src/plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,25 @@ impl Python3Plugin {
7474
}
7575
}
7676

77-
fn get_local_python_ver() -> Result<(usize, usize, usize), PythonError> {
77+
fn get_local_python_ver() -> Result<(u32, u32, u32), PythonError> {
7878
let output = Self::get_local_python_command()
7979
.with(|e| e.args(&["-c", "import sys; print(sys.version_info.major); print(sys.version_info.minor); print(sys.version_info.micro);"]))
8080
.output_checked()?;
8181
let stdout = String::from_utf8_lossy(&output.stdout);
8282
let mut lines = stdout.lines();
83-
let major: usize = lines
83+
let major: u32 = lines
8484
.next()
8585
.ok_or_else(|| PythonError::VersionPrintError(stdout.clone().into_owned()))?
8686
.trim()
8787
.parse()
8888
.map_err(|e| PythonError::VersionParseError(stdout.clone().into_owned(), e))?;
89-
let minor: usize = lines
89+
let minor: u32 = lines
9090
.next()
9191
.ok_or_else(|| PythonError::VersionPrintError(stdout.clone().into_owned()))?
9292
.trim()
9393
.parse()
9494
.map_err(|e| PythonError::VersionParseError(stdout.clone().into_owned(), e))?;
95-
let patch: usize = lines
95+
let patch: u32 = lines
9696
.next()
9797
.ok_or_else(|| PythonError::VersionPrintError(stdout.clone().into_owned()))?
9898
.trim()

tmc-client/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub enum ClientError {
4444

4545
#[error("Failed to download some exercises")]
4646
IncompleteDownloadResult {
47-
downloaded: Vec<usize>,
48-
failed: Vec<(usize, Box<ClientError>)>,
47+
downloaded: Vec<u32>,
48+
failed: Vec<(u32, Box<ClientError>)>,
4949
},
5050

5151
#[error("Already authenticated")]

tmc-client/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! ```rust,no_run
66
//! use tmc_client::TmcClient;
77
//!
8-
//! let mut client = TmcClient::new_in_config("https://tmc.mooc.fi".to_string(), "some_client".to_string(), "some_version".to_string()).unwrap();
8+
//! let mut client = TmcClient::new("https://tmc.mooc.fi".parse().unwrap(), "some_client".to_string(), "some_version".to_string());
99
//! client.authenticate("client_name", "email".to_string(), "password".to_string());
1010
//! let organizations = client.get_organizations();
1111
//! ```
@@ -24,6 +24,6 @@ pub use self::response::{
2424
SubmissionFeedbackResponse, SubmissionFinished, SubmissionProcessingStatus, SubmissionStatus,
2525
UpdateResult, User,
2626
};
27-
pub use self::tmc_client::{ClientUpdateData, TmcClient, Token};
27+
pub use self::tmc_client::{api_v8, ClientUpdateData, TmcClient, Token};
2828
pub use oauth2;
2929
pub use tmc_langs_plugins::{Language, RunResult, StyleValidationResult, StyleValidationStrategy};

tmc-client/src/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
33
/// Used to respond to feedback questions. See TmcClient::send_feedback.
44
pub struct FeedbackAnswer {
5-
pub question_id: usize,
5+
pub question_id: u32,
66
pub answer: String,
77
}

tmc-client/src/response.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Credentials {
3434

3535
#[derive(Debug, Deserialize)]
3636
pub struct User {
37-
pub id: usize,
37+
pub id: u32,
3838
pub username: String,
3939
pub email: String,
4040
pub administrator: bool,
@@ -53,7 +53,7 @@ pub struct Organization {
5353
/// Information for a course.
5454
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
5555
pub struct Course {
56-
pub id: usize,
56+
pub id: u32,
5757
pub name: String,
5858
pub title: String,
5959
pub description: Option<String>,
@@ -70,21 +70,21 @@ pub struct CourseData {
7070
pub name: String,
7171
pub hide_after: Option<String>,
7272
pub hidden: bool,
73-
pub cache_version: Option<usize>,
73+
pub cache_version: Option<u32>,
7474
pub spreadsheet_key: Option<String>,
7575
pub hidden_if_registered_after: Option<String>,
7676
pub refreshed_at: Option<DateTime<FixedOffset>>,
7777
pub locked_exercise_points_visible: bool,
7878
pub description: Option<String>,
79-
pub paste_visibility: Option<String>,
79+
pub paste_visibility: Option<u32>,
8080
pub formal_name: Option<String>,
8181
pub certificate_downloadable: Option<bool>,
8282
pub certificate_unlock_spec: Option<String>,
83-
pub organization_id: Option<usize>,
83+
pub organization_id: Option<u32>,
8484
pub disabled_status: Option<String>,
8585
pub title: Option<String>,
8686
pub material_url: Option<String>,
87-
pub course_template_id: Option<usize>,
87+
pub course_template_id: Option<u32>,
8888
pub hide_submission_results: bool,
8989
pub external_scoreboard_url: Option<String>,
9090
pub organization_slug: Option<String>,
@@ -128,7 +128,7 @@ impl From<CourseDetailsWrapper> for CourseDetails {
128128

129129
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
130130
pub struct Exercise {
131-
pub id: usize,
131+
pub id: u32,
132132
pub name: String,
133133
pub locked: bool,
134134
pub deadline_description: Option<String>,
@@ -144,20 +144,20 @@ pub struct Exercise {
144144
pub completed: bool,
145145
pub reviewed: bool,
146146
pub all_review_points_given: bool,
147-
pub memory_limit: Option<usize>,
147+
pub memory_limit: Option<u32>,
148148
pub runtime_params: Vec<String>,
149149
pub valgrind_strategy: String,
150150
pub code_review_requests_enabled: bool,
151151
pub run_tests_locally_action_enabled: bool,
152152
pub latest_submission_url: Option<String>,
153-
pub latest_submission_id: Option<usize>,
153+
pub latest_submission_id: Option<u32>,
154154
pub solution_zip_url: Option<String>,
155155
}
156156

157157
/// Exercise for a course.
158158
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
159159
pub struct CourseExercise {
160-
pub id: usize,
160+
pub id: u32,
161161
pub available_points: Vec<ExercisePoint>,
162162
pub awarded_points: Vec<String>,
163163
pub name: String,
@@ -171,7 +171,7 @@ pub struct CourseExercise {
171171

172172
#[derive(Debug, Deserialize)]
173173
pub struct CourseDataExercise {
174-
pub id: usize,
174+
pub id: u32,
175175
pub available_points: Vec<ExercisePoint>,
176176
pub name: String,
177177
pub publish_time: Option<String>,
@@ -182,24 +182,24 @@ pub struct CourseDataExercise {
182182

183183
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
184184
pub struct ExercisePoint {
185-
pub id: usize,
186-
pub exercise_id: usize,
185+
pub id: u32,
186+
pub exercise_id: u32,
187187
pub name: String,
188188
pub requires_review: bool,
189189
}
190190

191191
#[derive(Debug, Deserialize)]
192192
pub struct CourseDataExercisePoint {
193193
awarded_point: AwardedPoint,
194-
exercise_id: usize,
194+
exercise_id: u32,
195195
}
196196

197197
#[derive(Debug, Deserialize)]
198198
pub struct AwardedPoint {
199-
id: usize,
200-
course_id: usize,
201-
user_id: usize,
202-
submission_id: usize,
199+
id: u32,
200+
course_id: u32,
201+
user_id: u32,
202+
submission_id: u32,
203203
name: String,
204204
created_at: DateTime<FixedOffset>,
205205
}
@@ -208,19 +208,19 @@ pub struct AwardedPoint {
208208
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
209209
pub struct ExerciseDetails {
210210
pub course_name: String,
211-
pub course_id: usize,
211+
pub course_id: u32,
212212
pub code_review_requests_enabled: bool,
213213
pub run_tests_locally_action_enabled: bool,
214214
pub exercise_name: String,
215-
pub exercise_id: usize,
215+
pub exercise_id: u32,
216216
pub unlocked_at: Option<String>,
217217
pub deadline: Option<String>,
218218
pub submissions: Vec<ExerciseSubmission>,
219219
}
220220

221221
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
222222
pub struct ExercisesDetails {
223-
pub id: usize,
223+
pub id: u32,
224224
pub course_name: String,
225225
pub exercise_name: String,
226226
pub checksum: String,
@@ -229,19 +229,19 @@ pub struct ExercisesDetails {
229229
/// Exercise submission.
230230
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
231231
pub struct Submission {
232-
pub id: usize,
233-
pub user_id: usize,
232+
pub id: u32,
233+
pub user_id: u32,
234234
pub pretest_error: Option<String>,
235235
pub created_at: DateTime<FixedOffset>,
236236
pub exercise_name: String,
237-
pub course_id: usize,
237+
pub course_id: u32,
238238
pub processed: bool,
239239
pub all_tests_passed: bool,
240240
pub points: Option<String>,
241241
pub processing_tried_at: Option<DateTime<FixedOffset>>,
242242
pub processing_began_at: Option<DateTime<FixedOffset>>,
243243
pub processing_completed_at: Option<DateTime<FixedOffset>>,
244-
pub times_sent_to_sandbox: usize,
244+
pub times_sent_to_sandbox: u32,
245245
pub processing_attempts_started_at: DateTime<FixedOffset>,
246246
pub params_json: Option<String>,
247247
pub requires_review: bool,
@@ -258,15 +258,15 @@ pub struct Submission {
258258
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
259259
pub struct ExerciseSubmission {
260260
pub exercise_name: String,
261-
pub id: usize,
262-
pub user_id: usize,
263-
pub course_id: usize,
261+
pub id: u32,
262+
pub user_id: u32,
263+
pub course_id: u32,
264264
pub created_at: DateTime<FixedOffset>,
265265
pub all_tests_passed: bool,
266266
pub points: Option<String>,
267267
pub submitted_zip_url: String,
268268
pub paste_url: Option<String>,
269-
pub processing_time: Option<usize>,
269+
pub processing_time: Option<u32>,
270270
pub reviewed: bool,
271271
pub requests_review: bool,
272272
}
@@ -303,9 +303,9 @@ pub enum SandboxStatus {
303303
/// Finished submission.
304304
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
305305
pub struct SubmissionFinished {
306-
pub api_version: usize,
306+
pub api_version: u32,
307307
pub all_tests_passed: Option<bool>,
308-
pub user_id: usize,
308+
pub user_id: u32,
309309
pub login: String,
310310
pub course: String,
311311
pub exercise_name: String,
@@ -315,7 +315,7 @@ pub struct SubmissionFinished {
315315
pub submission_url: String,
316316
pub solution_url: Option<String>,
317317
pub submitted_at: String,
318-
pub processing_time: Option<usize>,
318+
pub processing_time: Option<u32>,
319319
pub reviewed: bool,
320320
pub requests_review: bool,
321321
pub paste_url: Option<String>,
@@ -341,7 +341,7 @@ pub enum SubmissionStatus {
341341
/// Response to feedback.
342342
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
343343
pub struct SubmissionFeedbackResponse {
344-
pub api_version: usize,
344+
pub api_version: u32,
345345
pub status: SubmissionStatus,
346346
}
347347

@@ -356,15 +356,15 @@ pub struct TestCase {
356356

357357
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)]
358358
pub struct SubmissionFeedbackQuestion {
359-
pub id: usize,
359+
pub id: u32,
360360
pub question: String,
361361
pub kind: SubmissionFeedbackKind,
362362
}
363363

364364
#[derive(Debug, PartialEq, Eq, JsonSchema)]
365365
pub enum SubmissionFeedbackKind {
366366
Text,
367-
IntRange { lower: usize, upper: usize },
367+
IntRange { lower: u32, upper: u32 },
368368
}
369369

370370
impl<'de> Deserialize<'de> for SubmissionFeedbackKind {
@@ -411,14 +411,14 @@ impl<'de> Visitor<'de> for SubmissionFeedbackKindVisitor {
411411
Ok(SubmissionFeedbackKind::Text)
412412
} else if let Some(captures) = RANGE.captures(&value) {
413413
let lower = &captures[1];
414-
let lower = usize::from_str(lower).map_err(|e| {
414+
let lower = u32::from_str(lower).map_err(|e| {
415415
E::custom(format!(
416416
"error parsing intrange lower bound {}: {}",
417417
lower, e
418418
))
419419
})?;
420420
let upper = &captures[2];
421-
let upper = usize::from_str(upper).map_err(|e| {
421+
let upper = u32::from_str(upper).map_err(|e| {
422422
E::custom(format!(
423423
"error parsing intrange upper bound {}: {}",
424424
upper, e
@@ -434,9 +434,9 @@ impl<'de> Visitor<'de> for SubmissionFeedbackKindVisitor {
434434
/// Code review.
435435
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
436436
pub struct Review {
437-
pub submission_id: String,
437+
pub submission_id: u32,
438438
pub exercise_name: String,
439-
pub id: usize,
439+
pub id: u32,
440440
pub marked_as_read: bool,
441441
pub reviewer_name: String,
442442
pub review_body: String,
@@ -445,7 +445,7 @@ pub struct Review {
445445
pub url: String,
446446
pub update_url: String,
447447
pub created_at: DateTime<FixedOffset>,
448-
pub updated_at: String,
448+
pub updated_at: DateTime<FixedOffset>,
449449
}
450450

451451
/// Updated exercises.

0 commit comments

Comments
 (0)