TriviaMD 0.0.5 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quizzes_v1.rb +59 -0
- data/lib/trivia_md.rb +16 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb0784d7cbf400d2e11cadfbcb9d8f7710b43e640009d131b3fd0edbc677725
|
4
|
+
data.tar.gz: baca2775605b69b019151f544bd8efd81ba76d7388011c31d4a2e43a7d987aa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39731789dbcde7931afd06c1b12c4d53ff5d1aad82e682279bdefcb1e8fb6ef6f6be13ecf8fe0bde06a9037ad6de486957f3f6807bd1f690b0d8550294cfcbb1
|
7
|
+
data.tar.gz: da71ebed756d91ac6c3b396e1e7a60bad35c57082fe443e8a4c81a5c5e5f6ad5430585a5f7d7c77afc2c2cfb144f7b05dffd89d5400c7de070d1c48dbb745109
|
data/lib/quizzes_v1.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'kramdown'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
class QuizzesV1
|
5
|
+
def initialize(course_id)
|
6
|
+
@course_id = course_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def quiz_base_url
|
10
|
+
"https://#{ENV.fetch("CANVAS_DOMAIN")}/api/v1/courses/#{@course_id}/quizzes"
|
11
|
+
end
|
12
|
+
|
13
|
+
def options(body=nil)
|
14
|
+
options = {
|
15
|
+
headers: { 'Authorization' => "Bearer #{ENV.fetch("CANVAS_API_TOKEN")}" },
|
16
|
+
format: :json
|
17
|
+
}
|
18
|
+
unless body.nil?
|
19
|
+
options[:headers]['Content-Type'] = 'application/json'
|
20
|
+
options[:body] = body.to_json
|
21
|
+
end
|
22
|
+
options
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_quiz(title)
|
26
|
+
body = {
|
27
|
+
quiz: {
|
28
|
+
title: title
|
29
|
+
}
|
30
|
+
}
|
31
|
+
response = HTTParty.send(:post, quiz_base_url, options(body)).parsed_response
|
32
|
+
response["id"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_question(quiz_id,question)
|
36
|
+
puts quiz_id
|
37
|
+
url = quiz_base_url + "/#{quiz_id}/questions"
|
38
|
+
body = {
|
39
|
+
question: {
|
40
|
+
question_text: question["question"],
|
41
|
+
question_type: "multiple_answers_question"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
body[:question][:answers] = question["answers"].map do |a|
|
45
|
+
{
|
46
|
+
answer_text: a["text"],
|
47
|
+
answer_weight: a["isAnswer"] == true ? 100 : 0
|
48
|
+
}
|
49
|
+
end
|
50
|
+
response = HTTParty.send(:post, url, options(body)).parsed_response
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_from_trivia(trivias)
|
55
|
+
parsed = JSON.parse(trivias)
|
56
|
+
quiz_id = create_quiz("Catalog quiz #{Time.now.iso8601}")
|
57
|
+
parsed.each { |q| create_question(quiz_id, q) }
|
58
|
+
end
|
59
|
+
end
|
data/lib/trivia_md.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
require "rubygems" # ruby1.9 doesn't "require" it though
|
3
3
|
require 'thor'
|
4
4
|
require 'kramdown'
|
5
|
-
require_relative './trivia_parser'
|
6
5
|
require 'json'
|
6
|
+
require_relative './trivia_parser'
|
7
|
+
require_relative './quizzes_v1'
|
8
|
+
|
7
9
|
|
8
10
|
class SubCommandBase < Thor
|
9
11
|
def self.banner(command, namespace = nil, subcommand = false)
|
@@ -26,9 +28,22 @@ module App
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
31
|
+
class Quizzes < SubCommandBase
|
32
|
+
include Thor::Actions
|
33
|
+
|
34
|
+
desc "create", 'create quiz from trivias'
|
35
|
+
option :trivias
|
36
|
+
def create_from_trivia(trivias)
|
37
|
+
QuizzesV1.new(ENV.fetch("COURSE_ID")).create_from_trivia(trivias)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
29
41
|
class CLI < Thor
|
30
42
|
desc "trivia", "parse trivias"
|
31
43
|
subcommand "trivia", Trivia
|
44
|
+
|
45
|
+
desc "quizzes", "create quizzes"
|
46
|
+
subcommand "quizzes", Quizzes
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TriviaMD
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bence Pjatacsuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.20.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.20.0
|
41
55
|
description: Parses markdown for trivia questions
|
42
56
|
email: pjatacsuk@gmail.com
|
43
57
|
executables:
|
@@ -46,6 +60,7 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- bin/trivia-md
|
63
|
+
- lib/quizzes_v1.rb
|
49
64
|
- lib/trivia_md.rb
|
50
65
|
- lib/trivia_parser.rb
|
51
66
|
homepage: https://rubygems.org/gems/trivia_md
|