github-to-canvas-quiz 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92070ddfabd669585e03a0483a6c037285ede7ef273203b9f657ca2d8a31591a
4
- data.tar.gz: 793083a3619e931c5a0f443186b851a30c62dcfc165e3c993ea418ba896b6506
3
+ metadata.gz: 1d17233ef60255fbf44c319a9f603698fce38bfdca6ef875fba36a9904a8b9e4
4
+ data.tar.gz: c6f727a34b726a41bfdc5a5a57fd9cebb2e3f07799fa2d8c69afdb858cee126a
5
5
  SHA512:
6
- metadata.gz: 9ab93d1c07ccd0552abda64b9fcc7e5b1eb23f084f8386f1c6287531471858eb9887555799ea1c7c942b1a4216d04d0f2ced48b7d3502874c76fac04c6f1fc4c
7
- data.tar.gz: 638e64bc77c6de8db38526556e35c9f2a9b84e7a74afed6be9d30b034761671418f0bf9e3f362f9064aa594122dea34f155251ca7b1921bf3c6f59a1dc123c8e
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, default: '.',
8
- desc: '(optional) Directory to output markdown files. Defaults to current directory'
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(client, options[:course], options[:quiz], options[:directory]).build
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, default: '.',
17
- desc: '(optional) Directory with markdown files to align. Defaults to current directory'
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 ||= CanvasAPI::Client.new(api_key: ENV['CANVAS_API_KEY'], host: ENV['CANVAS_API_PATH'])
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GithubToCanvasQuiz
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
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.2
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-10-04 00:00:00.000000000 Z
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