japanda 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env.example +4 -0
- data/.gitignore +2 -2
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Dockerfile +9 -0
- data/Gemfile.lock +62 -0
- data/Jenkinsfile +64 -0
- data/README.md +57 -15
- data/docker-compose.yml +11 -0
- data/japanda.gemspec +19 -19
- data/lib/japanda.rb +3 -11
- data/lib/japanda/canvas_factory.rb +24 -0
- data/lib/japanda/canvas_factory/assignment.rb +38 -0
- data/lib/japanda/canvas_factory/course.rb +82 -0
- data/lib/japanda/canvas_factory/mergie.rb +10 -0
- data/lib/japanda/canvas_factory/module.rb +51 -0
- data/lib/japanda/canvas_factory/module_item.rb +37 -0
- data/lib/japanda/canvas_factory/quiz.rb +52 -0
- data/lib/japanda/canvas_factory/section.rb +36 -0
- data/lib/japanda/canvas_factory/user.rb +67 -0
- data/lib/japanda/version.rb +1 -1
- metadata +72 -38
- data/LICENSE.txt +0 -21
- data/lib/canvas_factory/assignment.rb +0 -31
- data/lib/canvas_factory/course.rb +0 -55
- data/lib/canvas_factory/module.rb +0 -46
- data/lib/canvas_factory/module_item.rb +0 -31
- data/lib/canvas_factory/section.rb +0 -22
- data/lib/canvas_factory/user.rb +0 -28
- data/lib/canvas_factory/user_config.rb +0 -41
- data/lib/catalog_factory/course_program.rb +0 -61
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Santosh Natarajan
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# assignment class
|
2
|
-
module CanvasFactory
|
3
|
-
class Assignment
|
4
|
-
attr_reader :assignments
|
5
|
-
|
6
|
-
def add_assignments(opts)
|
7
|
-
@assignments = []
|
8
|
-
opts[:module][:assignment][:size].times do |i|
|
9
|
-
@assignments << add_assignment(opts, i)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_assignment(opts, i)
|
14
|
-
body = {
|
15
|
-
assignment: {
|
16
|
-
name: "Assignment-#{i}-#{Time.now.to_i}",
|
17
|
-
grading_type: %w(pass_fail percent letter_grade gpa_scale points).sample,
|
18
|
-
submission_types: ['online_text_entry'],
|
19
|
-
points_possible: 10,
|
20
|
-
due_at: (DateTime.now + 1).iso8601,
|
21
|
-
published: true
|
22
|
-
}
|
23
|
-
}
|
24
|
-
body.deep_merge!(opts[:assignment_options]) unless opts[:assignment_options].nil?
|
25
|
-
|
26
|
-
assign_end_point = "#{CANVAS_API_V1}/courses/#{opts[:course_id]}/assignments"
|
27
|
-
response = RestClient.post assign_end_point, body, CANVAS_AUTH_HEADER
|
28
|
-
JSON.parse(response)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# canvas course class
|
2
|
-
module CanvasFactory
|
3
|
-
class Course
|
4
|
-
attr_reader :course_response, :modules, :sections
|
5
|
-
|
6
|
-
def initialize(opts = {})
|
7
|
-
@options = {
|
8
|
-
name: 'catauto',
|
9
|
-
module: {
|
10
|
-
size: 1,
|
11
|
-
assignment:
|
12
|
-
{ size: 2 }
|
13
|
-
},
|
14
|
-
section: { size: 3 }
|
15
|
-
}.update(opts)
|
16
|
-
|
17
|
-
add_a_course @options
|
18
|
-
add_modules(@options)
|
19
|
-
add_sections(@options)
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_sections(opts)
|
23
|
-
s = CanvasFactory::Section.new
|
24
|
-
s.create_multiple_sections(opts)
|
25
|
-
@sections = s.sections
|
26
|
-
end
|
27
|
-
|
28
|
-
def add_modules(opts)
|
29
|
-
m = CanvasFactory::Module.new
|
30
|
-
m.create_modules(opts)
|
31
|
-
@modules = m.modules
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_a_course(opts = {})
|
35
|
-
name = "#{opts[:name]}#{SecureRandom.hex}"
|
36
|
-
body = {
|
37
|
-
account_id: CANVAS_ACCOUNT_ID,
|
38
|
-
course: {
|
39
|
-
name: name,
|
40
|
-
course_code: name,
|
41
|
-
start_at: Time.now,
|
42
|
-
end_at: Time.now + (30 * 24 * 60 * 60)
|
43
|
-
},
|
44
|
-
offer: true
|
45
|
-
}
|
46
|
-
body.deep_merge!(opts[:course_options]) unless opts[:course_options].nil?
|
47
|
-
|
48
|
-
course_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/courses"
|
49
|
-
response = RestClient.post course_end_point, body, CANVAS_AUTH_HEADER
|
50
|
-
@course_response = JSON.parse(response)
|
51
|
-
fail 'create canvas course failed' unless @course_response['workflow_state'].eql? 'available'
|
52
|
-
@options[:course_id] = @course_response['id']
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# canvas module class
|
2
|
-
module CanvasFactory
|
3
|
-
class Module
|
4
|
-
attr_reader :modules
|
5
|
-
|
6
|
-
def create_modules(opts)
|
7
|
-
@modules = []
|
8
|
-
opts[:module][:size].times do
|
9
|
-
@modules << create_module_add_item_publish(opts)
|
10
|
-
end
|
11
|
-
@modules
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_module_add_item_publish(opts)
|
15
|
-
body = {
|
16
|
-
module: {
|
17
|
-
name: "Course-Module-#{Time.now.to_i}",
|
18
|
-
unlock_at: DateTime.now.iso8601,
|
19
|
-
require_sequential_progress: true
|
20
|
-
}
|
21
|
-
}
|
22
|
-
body.deep_merge!(opts[:module_options]) unless opts[:module_options].nil?
|
23
|
-
|
24
|
-
m_item_end_point = "#{CANVAS_API_V1}/courses/#{opts[:course_id]}/modules"
|
25
|
-
response = RestClient.post m_item_end_point, body, CANVAS_AUTH_HEADER
|
26
|
-
m = JSON.parse(response)
|
27
|
-
|
28
|
-
mi = CanvasFactory::ModuleItem.new
|
29
|
-
mi.add_module_items(m['id'], opts)
|
30
|
-
|
31
|
-
update_module opts[:course_id], m['id']
|
32
|
-
{ module: m, module_items: mi.module_items }
|
33
|
-
end
|
34
|
-
|
35
|
-
def update_module(course_id, module_id)
|
36
|
-
body = {
|
37
|
-
module: {
|
38
|
-
published: true
|
39
|
-
}
|
40
|
-
}
|
41
|
-
m_p_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/modules/#{module_id}"
|
42
|
-
response = RestClient.put m_p_end_point, body, CANVAS_AUTH_HEADER
|
43
|
-
JSON.parse(response)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# canvas module_item class
|
2
|
-
module CanvasFactory
|
3
|
-
class ModuleItem
|
4
|
-
attr_reader :module_items
|
5
|
-
|
6
|
-
def add_module_items(module_id, opts)
|
7
|
-
@module_items = []
|
8
|
-
aa = CanvasFactory::Assignment.new
|
9
|
-
aa.add_assignments(opts)
|
10
|
-
aa.assignments.each do |a|
|
11
|
-
@module_items << add_module_item(module_id, 'Assignment', a['id'], opts)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_module_item(m_id, module_item_type, item_content_id, opts)
|
16
|
-
body = {
|
17
|
-
module_item: {
|
18
|
-
title: "mod-#{module_item_type}-#{item_content_id}",
|
19
|
-
type: module_item_type,
|
20
|
-
content_id: item_content_id,
|
21
|
-
completion_requirement: {
|
22
|
-
type: 'must_view'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
m_i = "#{CANVAS_API_V1}/courses/#{opts[:course_id]}/modules/#{m_id}/items"
|
27
|
-
response = RestClient.post m_i, body, CANVAS_AUTH_HEADER
|
28
|
-
JSON.parse(response)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# canvas section class
|
2
|
-
module CanvasFactory
|
3
|
-
class Section
|
4
|
-
attr_reader :sections
|
5
|
-
|
6
|
-
def create_multiple_sections(opts)
|
7
|
-
@sections = []
|
8
|
-
opts[:section][:size].times do |i|
|
9
|
-
body = {
|
10
|
-
course_section: {
|
11
|
-
name: "section-#{i}-#{Time.now.to_i}"
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
body.deep_merge!(opts[:section_options]) unless opts[:section_options].nil?
|
16
|
-
section_end_point = "#{CANVAS_API_V1}/courses/#{opts[:course_id]}/sections"
|
17
|
-
response = RestClient.post section_end_point, body, CANVAS_AUTH_HEADER
|
18
|
-
@sections << JSON.parse(response)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/canvas_factory/user.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# canvas user class
|
2
|
-
module CanvasFactory
|
3
|
-
class User
|
4
|
-
attr_reader :user_response, :user_response_id, :user_response_email_id, :user_short_name, :user_password
|
5
|
-
def initialize
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_catalog_user(user_config)
|
9
|
-
user_config.set_up_user_hash
|
10
|
-
body = user_config.config_user_hash
|
11
|
-
user_end_point = "#{Japanda::CANVAS_API_V1}/accounts/#{Japanda::CANVAS_ACCOUNT_ID}/users"
|
12
|
-
response = RestClient.post user_end_point, body, Japanda::CANVAS_AUTH_HEADER
|
13
|
-
@user_response = JSON.parse(response)
|
14
|
-
@user_response_id = @user_response['id']
|
15
|
-
@user_response_email_id = @user_response['login_id']
|
16
|
-
@user_short_name = user_config.config_user_hash[:user][:short_name]
|
17
|
-
@user_password = user_config.config_user_hash[:pseudonym][:password]
|
18
|
-
end
|
19
|
-
|
20
|
-
def create_admin_user(user_config)
|
21
|
-
create_catalog_user user_config
|
22
|
-
user_config.set_up_admin_hash(@user_response['id'].to_i)
|
23
|
-
body = user_config.config_admin_hash
|
24
|
-
a_end_point = "#{Japanda::CANVAS_API_V1}/accounts/#{Japanda::CANVAS_ACCOUNT_ID}/admins"
|
25
|
-
RestClient.post a_end_point, body, Japanda::CANVAS_AUTH_HEADER
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module CanvasFactory
|
2
|
-
class UserConfig
|
3
|
-
attr_reader :config_user_hash, :config_admin_hash
|
4
|
-
attr_writer :email_prefix, :password, :short_name, :terms_of_use, :send_confirmation, :force_validations, :role_id, :email_id
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@email_prefix = 'catauto'
|
8
|
-
@password = 'Testing01'
|
9
|
-
@short_name = 'cat auto'
|
10
|
-
@terms_of_use = '1'
|
11
|
-
@send_confirmation = true
|
12
|
-
@force_validations = true
|
13
|
-
@email_id = "#{@email_prefix}#{SecureRandom.hex}@example.com"
|
14
|
-
@role_id = 'AccountAdmin'
|
15
|
-
end
|
16
|
-
|
17
|
-
def set_up_user_hash
|
18
|
-
@config_user_hash = {
|
19
|
-
user: {
|
20
|
-
name: @email_id,
|
21
|
-
short_name: @short_name,
|
22
|
-
terms_of_use: @terms_of_use,
|
23
|
-
send_confirmation: @send_confirmation
|
24
|
-
},
|
25
|
-
pseudonym: {
|
26
|
-
unique_id: @email_id,
|
27
|
-
password: @password
|
28
|
-
},
|
29
|
-
force_validations: @force_validations
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_up_admin_hash(id)
|
34
|
-
@config_admin_hash = {
|
35
|
-
user_id: id,
|
36
|
-
role_id: @role_id,
|
37
|
-
send_confirmation: @send_confirmation
|
38
|
-
}
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# add course and program to catalog
|
2
|
-
module CatalogFactory
|
3
|
-
class CourseProgram
|
4
|
-
attr_reader :catalog_response, :course, :certificate_response
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@auth_token_content = {
|
8
|
-
Authorization: "Token token=#{GALLERY_API_TOKEN}",
|
9
|
-
content_type: 'application/json'
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_course_to_catalog(canvas_options = {}, catalog_options = {})
|
14
|
-
@course = CanvasFactory::Course.new(canvas_options)
|
15
|
-
add_to_catalog(@course, catalog_options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_to_catalog(canvas_course, opts = {})
|
19
|
-
@course = canvas_course
|
20
|
-
course_response = @course.course_response
|
21
|
-
body = {
|
22
|
-
course: {
|
23
|
-
title: course_response['name'],
|
24
|
-
description: 'created by api for testing',
|
25
|
-
path: course_response['name'],
|
26
|
-
canvas_course_id: course_response['id'],
|
27
|
-
teaser: 'created by api for testing',
|
28
|
-
enrollment_open: true,
|
29
|
-
visibility: 'listed',
|
30
|
-
enrollment_cap: 12,
|
31
|
-
enrollment_fee: 0.99,
|
32
|
-
days_to_complete: 45
|
33
|
-
}
|
34
|
-
}
|
35
|
-
body.deep_merge!(opts[:catalog_options]) unless opts[:catalog_options].nil?
|
36
|
-
|
37
|
-
course_end_point = "#{GALLERY_API_HOST}/api/v1/courses"
|
38
|
-
response = RestClient.post course_end_point, body, @auth_token_content
|
39
|
-
@catalog_response = JSON.parse(response)['course']
|
40
|
-
add_certificate @catalog_response['id'], opts
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_certificate(catalog_id, opts = {})
|
44
|
-
body = {
|
45
|
-
certificate: {
|
46
|
-
listing_id: catalog_id,
|
47
|
-
name: 'test api certificate',
|
48
|
-
template: 'Description test api certificate',
|
49
|
-
pdf_settings: {
|
50
|
-
orientation: %w(Landscape Portrait).sample
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
body.deep_merge!(opts[:certificate_options]) unless opts[:certificate_options].nil?
|
55
|
-
|
56
|
-
new_course_end_point = "#{GALLERY_API_HOST}/api/v1/certificates"
|
57
|
-
response = RestClient.post new_course_end_point, body, @auth_token_content
|
58
|
-
@certificate_response = JSON.parse(response)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|