TriviaMD 0.1.0 → 0.1.1
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/quizzes_v1.rb +59 -0
- metadata +2 -1
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TriviaMD
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bence Pjatacsuk
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- bin/trivia-md
|
63
|
+
- lib/quizzes_v1.rb
|
63
64
|
- lib/trivia_md.rb
|
64
65
|
- lib/trivia_parser.rb
|
65
66
|
homepage: https://rubygems.org/gems/trivia_md
|