Skip to content

Commit 047a3e7

Browse files
Refactoring submission 3
1 parent 3c8bdcd commit 047a3e7

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

tmcrstudioaddin/R/HTTPQueries.R

+38-37
Original file line numberDiff line numberDiff line change
@@ -123,43 +123,6 @@ download_exercise <- function(exercise_id,
123123
url_config = url_config)
124124
}
125125

126-
127-
#' @title Upload an exercise to the TMC server
128-
#'
129-
#' @description Upload an exercise to the TMC server
130-
#'
131-
#' @usage upload_exercise(token, exercise_id, project_path, server_address,
132-
#' zip_name = "temp", remove_zip = TRUE)
133-
#'
134-
#' @param token \code{OAuth2} token associated with the current login
135-
#' session.
136-
#' @param exercise_id ID of the submitted exercise.
137-
#' @param project_path File path to the directory of the submitted
138-
#' exercise.
139-
#' @param server_address Address of the TMC server where the exercise is
140-
#' submitted to.
141-
#' @param zip_name Name of the \code{zip} file which contains the
142-
#' exercise submission. Default is \code{temp}
143-
#' @param remove_zip \code{TRUE} or \code{FALSE} depending on if you
144-
#' wish to delete the submission \code{zip} file after sending it to the
145-
#' server. Defaults to \code{TRUE}.
146-
#'
147-
#' @details Packs the exercise directory into a \code{zip} file and
148-
#' sends it to the TMC server as a list.
149-
#'
150-
#' @return \code{HTTP} response to the submission attempt.
151-
#'
152-
#' @seealso \code{\link[httr]{add_headers}},
153-
#' \code{\link[httr]{upload_file}}, \code{\link[httr]{POST}},
154-
#' \code{\link[base]{file.remove}}
155-
156-
# Zips and uploads a single exercise, which is located in project_path.
157-
# Returns the response, which contains a field $submission_url
158-
# containing the details of the submission.
159-
upload_exercise <- function(token, exercise_id, project_path,
160-
server_address, zip_name = "temp",
161-
remove_zip = TRUE) {
162-
url_data <- .upload_exercise1(token, exercise_id, server_address)
163126
.upload_exercise2 <- function(url_data, project_path, remove_zip) {
164127
exercises_response <- list()
165128
exercises_url <- url_data$exercises_url
@@ -212,6 +175,44 @@ upload_exercise <- function(token, exercise_id, project_path,
212175

213176
return(exercises_response)
214177
}
178+
179+
180+
#' @title Upload an exercise to the TMC server
181+
#'
182+
#' @description Upload an exercise to the TMC server
183+
#'
184+
#' @usage upload_exercise(token, exercise_id, project_path, server_address,
185+
#' zip_name = "temp", remove_zip = TRUE)
186+
#'
187+
#' @param token \code{OAuth2} token associated with the current login
188+
#' session.
189+
#' @param exercise_id ID of the submitted exercise.
190+
#' @param project_path File path to the directory of the submitted
191+
#' exercise.
192+
#' @param server_address Address of the TMC server where the exercise is
193+
#' submitted to.
194+
#' @param zip_name Name of the \code{zip} file which contains the
195+
#' exercise submission. Default is \code{temp}
196+
#' @param remove_zip \code{TRUE} or \code{FALSE} depending on if you
197+
#' wish to delete the submission \code{zip} file after sending it to the
198+
#' server. Defaults to \code{TRUE}.
199+
#'
200+
#' @details Packs the exercise directory into a \code{zip} file and
201+
#' sends it to the TMC server as a list.
202+
#'
203+
#' @return \code{HTTP} response to the submission attempt.
204+
#'
205+
#' @seealso \code{\link[httr]{add_headers}},
206+
#' \code{\link[httr]{upload_file}}, \code{\link[httr]{POST}},
207+
#' \code{\link[base]{file.remove}}
208+
209+
# Zips and uploads a single exercise, which is located in project_path.
210+
# Returns the response, which contains a field $submission_url
211+
# containing the details of the submission.
212+
upload_exercise <- function(token, exercise_id, project_path,
213+
server_address, zip_name = "temp",
214+
remove_zip = TRUE) {
215+
url_data <- .upload_exercise1(token, exercise_id, server_address)
215216
.upload_exercise2(url_data, project_path, remove_zip)
216217
}
217218

tmcrstudioaddin/R/Submissions.R

+7-6
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ upload_current_exercise <- function(credentials,
113113
remove_zip = TRUE) {
114114
upload_with_id <- function(id) {
115115
token <- credentials$token
116+
upload_exercise <- function(exercise_id,
117+
server_address) {
118+
url_data <- .upload_exercise1(token, exercise_id, server_address)
119+
.upload_exercise2(url_data, project_path, remove_zip)
120+
}
116121
address <- paste(sep = "", credentials$serverAddress, "/")
117122
#
118123
# uploading starts
119124
tryCatch({
120-
response <- upload_exercise(token = credentials$token,
121-
exercise_id = id,
122-
project_path = project_path,
123-
server_address = address,
124-
zip_name = zip_name,
125-
remove_zip = remove_zip)
125+
response <- upload_exercise(exercise_id = id,
126+
server_address = address)
126127
return(response)
127128
}, error = function(e) {
128129
cat("Uploading exercise failed.\n")

0 commit comments

Comments
 (0)