-
Notifications
You must be signed in to change notification settings - Fork 7.2k
/
customTests.R
48 lines (43 loc) · 1.38 KB
/
customTests.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Get the swirl state
getState <- function(){
# Whenever swirl is running, its callback is at the top of its call stack.
# Swirl's state, named e, is stored in the environment of the callback.
environment(sys.function(1))$e
}
# Get the value which a user either entered directly or was computed
# by the command he or she entered.
getVal <- function(){
getState()$val
}
# Get the last expression which the user entered at the R console.
getExpr <- function(){
getState()$expr
}
coursera_on_demand <- function(){
selection <- getState()$val
if(selection == "Yes"){
email <- readline("What is your email address? ")
token <- readline("What is your assignment token? ")
payload <- sprintf('{
"assignmentKey": "-ACWUq8VEeWyvg4disSh_Q",
"submitterEmail": "%s",
"secret": "%s",
"parts": {
"bMOHi": {
"output": "correct"
}
}
}', email, token)
url <- 'https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1'
respone <- httr::POST(url, body = payload)
if(respone$status_code >= 200 && respone$status_code < 300){
message("Grade submission succeeded!")
} else {
message("Grade submission failed.")
message("Press ESC if you want to exit this lesson and you")
message("want to try to submit your grade at a later time.")
return(FALSE)
}
}
TRUE
}