-
Notifications
You must be signed in to change notification settings - Fork 4
/
fetchAssignments.go
165 lines (151 loc) Β· 8.4 KB
/
fetchAssignments.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"github.com/spf13/viper"
// "fmt"
"time"
"strconv"
)
type Assignment struct {
ID int `json:"id"`
Description string `json:"description"`
DueAt time.Time `json:"due_at"`
UnlockAt interface{} `json:"unlock_at"`
LockAt time.Time `json:"lock_at"`
PointsPossible float64 `json:"points_possible"`
GradingType string `json:"grading_type"`
AssignmentGroupID int `json:"assignment_group_id"`
GradingStandardID interface{} `json:"grading_standard_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PeerReviews bool `json:"peer_reviews"`
AutomaticPeerReviews bool `json:"automatic_peer_reviews"`
Position int `json:"position"`
GradeGroupStudentsIndividually bool `json:"grade_group_students_individually"`
AnonymousPeerReviews bool `json:"anonymous_peer_reviews"`
GroupCategoryID interface{} `json:"group_category_id"`
PostToSis bool `json:"post_to_sis"`
ModeratedGrading bool `json:"moderated_grading"`
OmitFromFinalGrade bool `json:"omit_from_final_grade"`
IntraGroupPeerReviews bool `json:"intra_group_peer_reviews"`
AnonymousInstructorAnnotations bool `json:"anonymous_instructor_annotations"`
AnonymousGrading bool `json:"anonymous_grading"`
GradersAnonymousToGraders bool `json:"graders_anonymous_to_graders"`
GraderCount int `json:"grader_count"`
GraderCommentsVisibleToGraders bool `json:"grader_comments_visible_to_graders"`
FinalGraderID interface{} `json:"final_grader_id"`
GraderNamesVisibleToFinalGrader bool `json:"grader_names_visible_to_final_grader"`
AllowedAttempts int `json:"allowed_attempts"`
LockInfo LockInfo `json:"lock_info"`
SecureParams string `json:"secure_params"`
CourseID int `json:"course_id"`
Name string `json:"name"`
SubmissionTypes []string `json:"submission_types"`
HasSubmittedSubmissions bool `json:"has_submitted_submissions"`
DueDateRequired bool `json:"due_date_required"`
MaxNameLength int `json:"max_name_length"`
InClosedGradingPeriod bool `json:"in_closed_grading_period"`
VericiteEnabled bool `json:"vericite_enabled"`
VericiteSettings VericiteSettings `json:"vericite_settings"`
IsQuizAssignment bool `json:"is_quiz_assignment"`
CanDuplicate bool `json:"can_duplicate"`
OriginalCourseID interface{} `json:"original_course_id"`
OriginalAssignmentID interface{} `json:"original_assignment_id"`
OriginalAssignmentName interface{} `json:"original_assignment_name"`
OriginalQuizID interface{} `json:"original_quiz_id"`
WorkflowState string `json:"workflow_state"`
Muted bool `json:"muted"`
HTMLURL string `json:"html_url"`
QuizID int `json:"quiz_id"`
AnonymousSubmissions bool `json:"anonymous_submissions"`
AllDates []AllDates `json:"all_dates"`
Published bool `json:"published"`
OnlyVisibleToOverrides bool `json:"only_visible_to_overrides"`
Submission Submission `json:"submission"`
LockedForUser bool `json:"locked_for_user"`
LockExplanation string `json:"lock_explanation"`
SubmissionsDownloadURL string `json:"submissions_download_url"`
PostManually bool `json:"post_manually"`
AnonymizeStudents bool `json:"anonymize_students"`
RequireLockdownBrowser bool `json:"require_lockdown_browser"`
ExternalToolTagAttributes ExternalToolTagAttributes `json:"external_tool_tag_attributes,omitempty"`
URL string `json:"url,omitempty"`
}
type LockInfo struct {
LockAt time.Time `json:"lock_at"`
CanView bool `json:"can_view"`
AssetString string `json:"asset_string"`
}
type VericiteSettings struct {
OriginalityReportVisibility string `json:"originality_report_visibility"`
ExcludeQuoted bool `json:"exclude_quoted"`
ExcludeSelfPlag bool `json:"exclude_self_plag"`
StoreInIndex bool `json:"store_in_index"`
}
type AllDates struct {
DueAt time.Time `json:"due_at"`
UnlockAt interface{} `json:"unlock_at"`
LockAt time.Time `json:"lock_at"`
Base bool `json:"base"`
}
type Submission struct {
ID int `json:"id"`
Body string `json:"body"`
URL interface{} `json:"url"`
Grade string `json:"grade"`
Score float64 `json:"score"`
SubmittedAt time.Time `json:"submitted_at"`
AssignmentID int `json:"assignment_id"`
UserID int `json:"user_id"`
SubmissionType string `json:"submission_type"`
WorkflowState string `json:"workflow_state"`
GradeMatchesCurrentSubmission bool `json:"grade_matches_current_submission"`
GradedAt time.Time `json:"graded_at"`
GraderID int `json:"grader_id"`
Attempt int `json:"attempt"`
CachedDueDate time.Time `json:"cached_due_date"`
Excused interface{} `json:"excused"`
LatePolicyStatus interface{} `json:"late_policy_status"`
PointsDeducted interface{} `json:"points_deducted"`
GradingPeriodID interface{} `json:"grading_period_id"`
ExtraAttempts interface{} `json:"extra_attempts"`
PostedAt time.Time `json:"posted_at"`
Late bool `json:"late"`
Missing bool `json:"missing"`
SecondsLate int `json:"seconds_late"`
EnteredGrade string `json:"entered_grade"`
EnteredScore float64 `json:"entered_score"`
PreviewURL string `json:"preview_url"`
}
type ExternalToolTagAttributes struct {
URL string `json:"url"`
NewTab bool `json:"new_tab"`
ResourceLinkID string `json:"resource_link_id"`
}
func fetchAssignments(courseID int) *[]Assignment {
// Create URL string from config file
url := viper.Get("canvasdomain").(string)+"api/v1/courses/"+strconv.Itoa(courseID)+"/assignments?per_page=100&include[]=submission&include[]=all_dates"
// url := viper.Get("canvasdomain").(string)+"api/v1/courses/"+strconv.Itoa(courseID)+"/assignments?per_page=100&include[]=submission&include=all_dates"
// Create a Bearer string by appending string access token
var bearer = "Bearer " + viper.Get("canvastoken").(string)
// Create a new request using http
req, err := http.NewRequest("GET", url, nil)
// add authorization header to the req
req.Header.Add("Authorization", bearer)
// Send req using http Client
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
body, _ := ioutil.ReadAll(resp.Body)
assignments := make([]Assignment,0)
err = json.Unmarshal([]byte(body), &assignments)
if err != nil {
panic(err)
}
return &assignments
}