forked from krakowski/ilias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_download.go
54 lines (44 loc) · 1.06 KB
/
exercise_download.go
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
49
50
51
52
53
54
package ilias
import (
"io/ioutil"
"net/http"
)
const (
downloadPath string = "ilias.php?vw=1&cmd=downloadReturned&cmdClass=ilexsubmissionfilegui&cmdNode=c8:o5:c9:cj&baseClass=ilExerciseHandlerGUI"
)
type Submission struct {
ContentType string
Content []byte
}
type DownloadParams struct {
Reference string `schema:"ref_id"`
Assignment string `schema:"ass_id"`
Member string `schema:"member_id"`
}
func (exercise *ExerciseService) Download(params *DownloadParams) (*Submission, error) {
// Prepare request url
path, err := addQueryParams(downloadPath, params)
if err != nil {
return nil, err
}
// Create request
req, err := exercise.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, err
}
// Retrieve the HTML source
resp, err := exercise.client.Do(req)
if err != nil {
return nil, err
}
// Read the responses content
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return &Submission{
ContentType: resp.Header.Get("Content-Type"),
Content: body,
}, nil
}