@@ -4,8 +4,8 @@ use crate::error::{CoreError, Result};
44use crate :: request:: * ;
55use crate :: response:: * ;
66use crate :: response:: { Course , CourseDetails , Organization } ;
7+ use crate :: { Language , RunResult , ValidationResult } ;
78
8- use isolang:: Language ;
99use oauth2:: basic:: BasicClient ;
1010use oauth2:: prelude:: * ;
1111use oauth2:: {
@@ -21,7 +21,6 @@ use std::path::Path;
2121use std:: path:: PathBuf ;
2222use tempfile:: NamedTempFile ;
2323use tmc_langs_util:: task_executor;
24- use tmc_langs_util:: { RunResult , ValidationResult } ;
2524use url1:: Url as Url1 ;
2625
2726pub type Token =
@@ -40,7 +39,12 @@ pub struct TmcCore {
4039impl TmcCore {
4140 pub fn new ( config_dir : PathBuf , root_url : String ) -> Result < Self > {
4241 // guarantee a trailing slash, otherwise join will drop the last component
43- let tmc_url = Url :: parse ( & format ! ( "{}/" , root_url) ) ?;
42+ let root_url = if root_url. ends_with ( '/' ) {
43+ root_url
44+ } else {
45+ format ! ( "{}/" , root_url)
46+ } ;
47+ let tmc_url = Url :: parse ( & root_url) ?;
4448 let api_url = tmc_url. join ( "api/v8/" ) ?;
4549 let auth_url = tmc_url. join ( "oauth/token" ) ?;
4650 Ok ( Self {
@@ -94,14 +98,17 @@ impl TmcCore {
9498 Ok ( ( ) )
9599 }
96100
101+ /// Fetches all organizations.
97102 pub fn get_organizations ( & self ) -> Result < Vec < Organization > > {
98103 self . organizations ( )
99104 }
100105
106+ /// UNIMPLEMENTED
101107 pub fn send_diagnostics ( & self ) {
102108 unimplemented ! ( )
103109 }
104110
111+ /// Downloads the given exercises.
105112 pub fn download_or_update_exercises ( & self , exercises : Vec < ( usize , & Path ) > ) -> Result < ( ) > {
106113 for ( exercise_id, target) in exercises {
107114 let zip_file = NamedTempFile :: new ( ) . map_err ( CoreError :: TempFile ) ?;
@@ -111,14 +118,17 @@ impl TmcCore {
111118 Ok ( ( ) )
112119 }
113120
121+ /// Fetches the course's information.
114122 pub fn get_course_details ( & self , course_id : usize ) -> Result < CourseDetails > {
115123 self . core_course ( course_id)
116124 }
117125
126+ /// Fetches all courses under the given organization.
118127 pub fn list_courses ( & self , organization_slug : & str ) -> Result < Vec < Course > > {
119128 self . organization_courses ( organization_slug)
120129 }
121130
131+ /// Sends the given submission as a paste.
122132 pub fn paste_with_comment (
123133 & self ,
124134 submission_url : Url ,
@@ -135,6 +145,7 @@ impl TmcCore {
135145 self . post_submission_to_paste ( submission_url, file. path ( ) , paste_message, locale)
136146 }
137147
148+ /// Runs checkstyle for the project.
138149 pub fn run_checkstyle (
139150 & self ,
140151 path : & Path ,
@@ -143,10 +154,12 @@ impl TmcCore {
143154 Ok ( task_executor:: run_check_code_style ( path, locale) ?)
144155 }
145156
157+ /// Runs tests for the project.
146158 pub fn run_tests ( & self , path : & Path ) -> Result < RunResult > {
147159 Ok ( task_executor:: run_tests ( path) ?)
148160 }
149161
162+ /// Sends feedback.
150163 pub fn send_feedback (
151164 & self ,
152165 feedback_url : Url ,
@@ -155,10 +168,12 @@ impl TmcCore {
155168 self . post_feedback ( feedback_url, feedback)
156169 }
157170
171+ /// UNIMPLEMENTED
158172 pub fn send_snapshot_events ( & self ) {
159173 unimplemented ! ( )
160174 }
161175
176+ /// Sends the submission to the server.
162177 pub fn submit (
163178 & self ,
164179 submission_url : Url ,
@@ -205,14 +220,17 @@ impl TmcCore {
205220 } )
206221 }
207222
223+ /// Mark the review as read on the server.
208224 pub fn mark_review_as_read ( & self , review_update_url : String ) -> Result < ( ) > {
209225 self . mark_review ( review_update_url, true )
210226 }
211227
228+ /// Fetches all reviews.
212229 pub fn get_unread_reviews ( & self , reviews_url : Url ) -> Result < Vec < Review > > {
213230 self . get_json_from_url ( reviews_url)
214231 }
215232
233+ /// Request code review.
216234 pub fn request_code_review (
217235 & self ,
218236 submission_url : Url ,
@@ -229,13 +247,15 @@ impl TmcCore {
229247 self . post_submission_for_review ( submission_url, file. path ( ) , message_for_reviewer, locale)
230248 }
231249
250+ /// Downloads the model solution from the given url.
232251 pub fn download_model_solution ( & self , solution_download_url : Url , target : & Path ) -> Result < ( ) > {
233252 let zip_file = NamedTempFile :: new ( ) . map_err ( CoreError :: TempFile ) ?;
234253 self . download_from ( solution_download_url, zip_file. path ( ) ) ?;
235254 task_executor:: extract_project ( zip_file. path ( ) , target) ?;
236255 Ok ( ( ) )
237256 }
238257
258+ /// Checks the status of a submission on the server.
239259 pub fn check_submission ( & self , submission_url : & str ) -> Result < SubmissionProcessingStatus > {
240260 if self . token . is_none ( ) {
241261 return Err ( CoreError :: AuthRequired ) ;
@@ -247,6 +267,7 @@ impl TmcCore {
247267 Ok ( res)
248268 }
249269
270+ // convenience function for requesting JSON data from the TMC server
250271 fn request_json < T : DeserializeOwned + Debug > ( & self , url : Url ) -> Result < T > {
251272 log:: debug!( "requesting {}" , url) ;
252273 let mut req = self . client . get ( url) ;
0 commit comments