github-to-canvas-quiz 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/github_to_canvas_quiz/cli.rb +24 -6
- data/lib/github_to_canvas_quiz/model/answer/fill_in_multiple_blanks.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/matching.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/multiple_answers.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/multiple_choice.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/multiple_dropdowns.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/short_answer.rb +4 -3
- data/lib/github_to_canvas_quiz/model/answer/true_false.rb +4 -3
- data/lib/github_to_canvas_quiz/synchronizer/quiz.rb +23 -0
- data/lib/github_to_canvas_quiz/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d17233ef60255fbf44c319a9f603698fce38bfdca6ef875fba36a9904a8b9e4
|
4
|
+
data.tar.gz: c6f727a34b726a41bfdc5a5a57fd9cebb2e3f07799fa2d8c69afdb858cee126a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ca6d0b1a7855fbf8445f857f715cf68eaa948017c40181e455516349249b03531a2812e3640e3195fdb02d560c38614c2843e3cd8a31b06d41946307e67f07
|
7
|
+
data.tar.gz: 29353d35a5a6a6f10155d26f96d5945ffe04521cd1824875996ec1344e4d660b5bdabbf13266c01e740a7d5eee5608968d4acf3809ebcff83bc2dd2d8bb7545e
|
@@ -4,17 +4,26 @@ module GithubToCanvasQuiz
|
|
4
4
|
class CLI < Thor
|
5
5
|
option :course, type: :numeric, required: true, desc: 'Canvas Course ID'
|
6
6
|
option :quiz, type: :numeric, required: true, desc: 'Canvas Quiz ID'
|
7
|
-
option :directory,
|
8
|
-
|
7
|
+
option :directory,
|
8
|
+
default: '.',
|
9
|
+
desc:
|
10
|
+
'(optional) Directory to output markdown files. Defaults to current directory'
|
9
11
|
desc 'backup', 'Backup a Canvas quiz and its questions as markdown'
|
10
12
|
def backup
|
11
13
|
puts '⬇️ Converting quiz...'
|
12
|
-
Builder::Quiz.new(
|
14
|
+
Builder::Quiz.new(
|
15
|
+
client,
|
16
|
+
options[:course],
|
17
|
+
options[:quiz],
|
18
|
+
options[:directory],
|
19
|
+
).build
|
13
20
|
puts '✅ Done'
|
14
21
|
end
|
15
22
|
|
16
|
-
option :directory,
|
17
|
-
|
23
|
+
option :directory,
|
24
|
+
default: '.',
|
25
|
+
desc:
|
26
|
+
'(optional) Directory with markdown files to align. Defaults to current directory'
|
18
27
|
desc 'align', 'Updates a Canvas quiz from Markdown files.'
|
19
28
|
def align
|
20
29
|
puts '⬆️ Aligning quiz...'
|
@@ -22,10 +31,19 @@ module GithubToCanvasQuiz
|
|
22
31
|
puts '✅ Done'
|
23
32
|
end
|
24
33
|
|
34
|
+
desc 'version', 'Display the Gem version'
|
35
|
+
def version
|
36
|
+
puts VERSION
|
37
|
+
end
|
38
|
+
|
25
39
|
private
|
26
40
|
|
27
41
|
def client
|
28
|
-
@client ||=
|
42
|
+
@client ||=
|
43
|
+
CanvasAPI::Client.new(
|
44
|
+
api_key: ENV['CANVAS_API_KEY'],
|
45
|
+
host: ENV['CANVAS_API_PATH'],
|
46
|
+
)
|
29
47
|
end
|
30
48
|
end
|
31
49
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class FillInMultipleBlanks
|
7
|
-
attr_accessor :title, :text, :comments, :blank_id
|
7
|
+
attr_accessor :id, :title, :text, :comments, :blank_id
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -25,8 +25,9 @@ module GithubToCanvasQuiz
|
|
25
25
|
'answer_text' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
27
|
'answer_comment_html' => comments,
|
28
|
-
'blank_id' => blank_id
|
29
|
-
|
28
|
+
'blank_id' => blank_id,
|
29
|
+
'id' => id
|
30
|
+
}.reject { |_,v| v.nil? }
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class Matching
|
7
|
-
attr_accessor :title, :text, :comments, :left, :right
|
7
|
+
attr_accessor :id, :title, :text, :comments, :left, :right
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -26,8 +26,9 @@ module GithubToCanvasQuiz
|
|
26
26
|
'answer_weight' => 100,
|
27
27
|
'answer_comment_html' => comments,
|
28
28
|
'answer_match_left' => left,
|
29
|
-
'answer_match_right' => right
|
30
|
-
|
29
|
+
'answer_match_right' => right,
|
30
|
+
'id' => id
|
31
|
+
}.reject { |_,v| v.nil? }
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class MultipleAnswers
|
7
|
-
attr_accessor :title, :text, :comments
|
7
|
+
attr_accessor :id, :title, :text, :comments
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -24,8 +24,9 @@ module GithubToCanvasQuiz
|
|
24
24
|
{
|
25
25
|
'answer_html' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
|
-
'answer_comment_html' => comments
|
28
|
-
|
27
|
+
'answer_comment_html' => comments,
|
28
|
+
'id' => id
|
29
|
+
}.reject { |_,v| v.nil? }
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class MultipleChoice
|
7
|
-
attr_accessor :title, :text, :comments
|
7
|
+
attr_accessor :id, :title, :text, :comments
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -24,8 +24,9 @@ module GithubToCanvasQuiz
|
|
24
24
|
{
|
25
25
|
'answer_html' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
|
-
'answer_comment_html' => comments
|
28
|
-
|
27
|
+
'answer_comment_html' => comments,
|
28
|
+
'id' => id
|
29
|
+
}.reject { |_,v| v.nil? }
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class MultipleDropdowns
|
7
|
-
attr_accessor :title, :text, :comments, :blank_id
|
7
|
+
attr_accessor :id, :title, :text, :comments, :blank_id
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -25,8 +25,9 @@ module GithubToCanvasQuiz
|
|
25
25
|
'answer_text' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
27
|
'answer_comment_html' => comments,
|
28
|
-
'blank_id' => blank_id
|
29
|
-
|
28
|
+
'blank_id' => blank_id,
|
29
|
+
'id' => id
|
30
|
+
}.reject { |_,v| v.nil? }
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class ShortAnswer
|
7
|
-
attr_accessor :title, :text, :comments
|
7
|
+
attr_accessor :id, :title, :text, :comments
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -24,8 +24,9 @@ module GithubToCanvasQuiz
|
|
24
24
|
{
|
25
25
|
'answer_text' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
|
-
'answer_comment_html' => comments
|
28
|
-
|
27
|
+
'answer_comment_html' => comments,
|
28
|
+
'id' => id
|
29
|
+
}.reject { |_,v| v.nil? }
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -4,7 +4,7 @@ module GithubToCanvasQuiz
|
|
4
4
|
module Model
|
5
5
|
module Answer
|
6
6
|
class TrueFalse
|
7
|
-
attr_accessor :title, :text, :comments
|
7
|
+
attr_accessor :id, :title, :text, :comments
|
8
8
|
|
9
9
|
def initialize(options)
|
10
10
|
options.each do |key, value|
|
@@ -24,8 +24,9 @@ module GithubToCanvasQuiz
|
|
24
24
|
{
|
25
25
|
'answer_text' => text,
|
26
26
|
'answer_weight' => title == 'Correct' ? 100 : 0,
|
27
|
-
'answer_comment_html' => comments
|
28
|
-
|
27
|
+
'answer_comment_html' => comments,
|
28
|
+
'id' => id
|
29
|
+
}.reject { |_,v| v.nil? }
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -48,14 +48,37 @@ module GithubToCanvasQuiz
|
|
48
48
|
|
49
49
|
# Get question data from Markdown files and return a Model::Question along with its path
|
50
50
|
def parse_questions_with_path
|
51
|
+
# read Canvas question data
|
52
|
+
canvas_questions = client.list_questions(quiz.course_id, quiz.id)
|
53
|
+
|
54
|
+
# read Markdown data
|
51
55
|
Dir["#{path}/questions/*.md"].map do |question_path|
|
52
56
|
question = Parser::Markdown::Question.new(File.read(question_path)).parse
|
53
57
|
question.quiz_id = quiz.id
|
54
58
|
question.course_id = quiz.course_id
|
59
|
+
|
60
|
+
# find the matching Canvas answer
|
61
|
+
canvas_question = canvas_questions.find { |canvas_question| canvas_question['id'] == question.id }
|
62
|
+
get_answer_ids!(question, canvas_question) if canvas_question
|
63
|
+
|
55
64
|
[question, question_path] # need that question path... gotta be a better way!
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
def get_answer_ids!(question, canvas_question)
|
69
|
+
question.answers.each do |answer|
|
70
|
+
# match the markdown answer to the Canvas answer based on the answer text
|
71
|
+
canvas_answer = canvas_question['answers'].find do |canvas_answer|
|
72
|
+
if canvas_answer['html'].nil? || canvas_answer['html'].empty?
|
73
|
+
canvas_answer['text'] == answer.text
|
74
|
+
else
|
75
|
+
canvas_answer['html'] == answer.text
|
76
|
+
end
|
77
|
+
end
|
78
|
+
answer.id = canvas_answer['id'].to_i if canvas_answer
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
59
82
|
# create or update quiz on Canvas
|
60
83
|
def sync_quiz!
|
61
84
|
if quiz.id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-to-canvas-quiz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ihollander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: front_matter_parser
|