japanda 0.1.1 → 0.1.6
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 +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 +58 -18
- data/docker-compose.yml +11 -0
- data/japanda.gemspec +19 -19
- data/lib/japanda.rb +3 -0
- data/lib/japanda/canvas_factory.rb +14 -0
- data/lib/japanda/canvas_factory/assignment.rb +23 -16
- data/lib/japanda/canvas_factory/course.rb +75 -10
- data/lib/japanda/canvas_factory/mergie.rb +10 -0
- data/lib/japanda/canvas_factory/module.rb +33 -28
- data/lib/japanda/canvas_factory/module_item.rb +25 -19
- data/lib/japanda/canvas_factory/quiz.rb +52 -0
- data/lib/japanda/canvas_factory/section.rb +28 -14
- data/lib/japanda/canvas_factory/user.rb +55 -19
- data/lib/japanda/version.rb +1 -1
- metadata +65 -34
- data/LICENSE.txt +0 -21
- data/lib/japanda/canvas_factory/course_config.rb +0 -28
- data/lib/japanda/canvas_factory/user_config.rb +0 -41
- data/lib/japanda/catalog_factory.rb +0 -6
- data/lib/japanda/catalog_factory/course_program.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a8acb3a2a4f8a67997e25b5514be451f76dc2b6efaeb820b81d58384c773ef34
|
4
|
+
data.tar.gz: 82a46cfe03d449b9c308ce7606524a20c5e98712dea1d9bb67fb3e53786e8bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e3b3e50ce617851288635346953a729df02fc76f5026b9eabbbdccf7710d0c667d15b25733070437eced81b8f36bff63aaf80708368331be3525bfd72aa7e2
|
7
|
+
data.tar.gz: 84e487cf7c6f2da50af89266551992ba869b5d119a63848eafcebbc3d63b671dd469e570d4be8a960129fbd2af819d321b2c0e97422233cff05002dfa58ceb4b
|
data/.env.example
ADDED
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/Dockerfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
japanda (0.1.6)
|
5
|
+
rest-client (>= 2.1.0)
|
6
|
+
rspec_junit_formatter (~> 0.4.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
byebug (11.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
domain_name (0.5.20190701)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
dotenv (2.0.2)
|
16
|
+
hashie (4.0.0)
|
17
|
+
http-accept (1.7.0)
|
18
|
+
http-cookie (1.0.3)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
mime-types (3.3.1)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2020.1104)
|
23
|
+
netrc (0.11.0)
|
24
|
+
rake (10.4.2)
|
25
|
+
rest-client (2.1.0)
|
26
|
+
http-accept (>= 1.7.0, < 2.0)
|
27
|
+
http-cookie (>= 1.0.2, < 2.0)
|
28
|
+
mime-types (>= 1.16, < 4.0)
|
29
|
+
netrc (~> 0.8)
|
30
|
+
rspec (3.5.0)
|
31
|
+
rspec-core (~> 3.5.0)
|
32
|
+
rspec-expectations (~> 3.5.0)
|
33
|
+
rspec-mocks (~> 3.5.0)
|
34
|
+
rspec-core (3.5.4)
|
35
|
+
rspec-support (~> 3.5.0)
|
36
|
+
rspec-expectations (3.5.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.5.0)
|
39
|
+
rspec-mocks (3.5.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.5.0)
|
42
|
+
rspec-support (3.5.0)
|
43
|
+
rspec_junit_formatter (0.4.1)
|
44
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.7.7)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.5)
|
54
|
+
byebug
|
55
|
+
dotenv
|
56
|
+
hashie (~> 4.0.0)
|
57
|
+
japanda!
|
58
|
+
rake
|
59
|
+
rspec (~> 3.5.0)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.17.3
|
data/Jenkinsfile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#! /usr/bin/env groovy
|
2
|
+
|
3
|
+
String rspec_results = ''
|
4
|
+
String container_id = ''
|
5
|
+
|
6
|
+
pipeline {
|
7
|
+
agent { label 'docker' }
|
8
|
+
|
9
|
+
environment {
|
10
|
+
COMPOSE_PROJECT_NAME = 'japanda_build'
|
11
|
+
COMPOSE_FILE = 'docker-compose.yml'
|
12
|
+
}
|
13
|
+
|
14
|
+
options {
|
15
|
+
ansiColor("xterm")
|
16
|
+
}
|
17
|
+
|
18
|
+
stages {
|
19
|
+
stage('Build') {
|
20
|
+
steps {
|
21
|
+
echo 'Building the containers'
|
22
|
+
sh "docker-compose build --pull"
|
23
|
+
|
24
|
+
echo 'Starting containers'
|
25
|
+
sh "docker-compose up -d"
|
26
|
+
sh 'docker-compose run --no-deps -d testrunner tail -f /dev/null'
|
27
|
+
|
28
|
+
script {
|
29
|
+
sh "docker ps"
|
30
|
+
container_id = sh(script: "docker ps -qf 'name=testrunner'",
|
31
|
+
returnStdout: true
|
32
|
+
).trim()
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
stage('Run Rspec Tests') {
|
39
|
+
steps {
|
40
|
+
sh "docker exec $container_id bundle exec rspec spec/ >> rspec_results"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
post {
|
46
|
+
always {
|
47
|
+
script {
|
48
|
+
rspec_results = sh(script: 'cat rspec_results',
|
49
|
+
returnStdout: true
|
50
|
+
).trim()
|
51
|
+
|
52
|
+
sh "docker cp $container_id:/usr/src/app/junit ."
|
53
|
+
junit allowEmptyResults: true, testResults: 'junit/rspec.xml'
|
54
|
+
}
|
55
|
+
echo rspec_results
|
56
|
+
}
|
57
|
+
|
58
|
+
cleanup {
|
59
|
+
sh 'if [ -d "junit" ]; then rm -r "junit"; fi'
|
60
|
+
sh 'if [ -f "rspec_results" ]; then rm -rf "rspec_results"; fi'
|
61
|
+
sh "docker-compose down --remove-orphans --rmi=all --volumes"
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# Japanda
|
2
2
|
|
3
|
-
|
3
|
+
Japanda provides an object-oriented and a functional wrapper around Instructure Canvas Api's
|
4
4
|
|
5
|
-
|
5
|
+
Disclaimer: For testing purposes only.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
|
12
|
-
gem 'japanda'
|
13
|
-
```
|
11
|
+
gem 'japanda'
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
@@ -21,28 +19,70 @@ Or install it yourself as:
|
|
21
19
|
$ gem install japanda
|
22
20
|
|
23
21
|
## Usage
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
export CANVAS_API_HOST=
|
28
|
-
export CANVAS_API_TOKEN=
|
29
|
-
export CANVAS_ACCOUNT_ID=
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
|
23
|
+
Set a few enviroment variables( or use .env.example file)
|
24
|
+
|
25
|
+
export CANVAS_API_HOST=
|
26
|
+
export CANVAS_API_TOKEN=
|
27
|
+
export CANVAS_ACCOUNT_ID=
|
28
|
+
|
29
|
+
To create a new course
|
30
|
+
|
31
|
+
CanvasFactory::Course.new
|
32
|
+
|
33
|
+
To create a new course by providing a custom hash(merge)
|
34
|
+
|
35
|
+
opts = { course:{ name: 'coursename1', course_code: "code-change#{SecureRandom.hex}" } }
|
36
|
+
course = CanvasFactory::Course.new(opts)
|
37
|
+
|
38
|
+
To create a new course by providing a custom hash(no merge)
|
39
|
+
|
40
|
+
opts = {
|
41
|
+
account_id: '10',
|
42
|
+
course: {
|
43
|
+
name: "code-name#{SecureRandom.hex}",
|
44
|
+
course_code: "course_code#{SecureRandom.hex}"
|
45
|
+
},
|
46
|
+
offer: true
|
47
|
+
}
|
48
|
+
course = CanvasFactory::Course.new(opts, false)
|
33
49
|
|
34
50
|
## Development
|
35
51
|
|
36
|
-
After checking out the repo, run `
|
52
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
54
|
+
|
55
|
+
### Run in docker
|
56
|
+
|
57
|
+
Make sure your .env variable contains
|
58
|
+
```
|
59
|
+
CANVAS_API_HOST=<canvas_host>
|
60
|
+
CANVAS_API_TOKEN=<canvas_api_token>
|
61
|
+
CANVAS_ACCOUNT_ID=<canvas_account_id>
|
62
|
+
```
|
63
|
+
|
64
|
+
Building the testrunner
|
65
|
+
```
|
66
|
+
docker-compose build
|
67
|
+
```
|
68
|
+
|
69
|
+
Running the tests:
|
70
|
+
```
|
71
|
+
docker-compose run testrunner bundle exec rspec spec/
|
72
|
+
```
|
73
|
+
|
74
|
+
## Release a new version
|
75
|
+
|
76
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
77
|
|
38
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
78
|
|
40
79
|
## Contributing
|
41
80
|
|
42
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/babababili/japanda. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
43
82
|
|
44
83
|
|
45
84
|
## License
|
46
85
|
|
47
|
-
|
86
|
+
For testing purposes only.
|
48
87
|
|
88
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/docker-compose.yml
ADDED
data/japanda.gemspec
CHANGED
@@ -4,36 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'japanda/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'japanda'
|
8
8
|
spec.version = Japanda::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Santosh Natarajan', 'Robert Lamb']
|
10
|
+
spec.email = ['snatarajan@instructure.com', 'rlamb@instructure.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Library to create custom course
|
13
|
-
spec.description = %q{Library to create custom course
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = %q{Library to create custom course.}
|
13
|
+
spec.description = %q{Library to create custom course. wip.}
|
14
|
+
# spec.homepage = 'https://github.com/babababili/japanda'
|
15
|
+
# spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
19
19
|
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] =
|
20
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
21
21
|
# else
|
22
|
-
# raise
|
22
|
+
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
23
|
# end
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
|
34
|
-
|
35
|
-
spec.
|
36
|
-
spec.add_dependency
|
37
|
-
spec.add_dependency
|
30
|
+
spec.add_development_dependency 'bundler', '~>1.5'
|
31
|
+
spec.add_development_dependency 'byebug'
|
32
|
+
spec.add_development_dependency 'dotenv'
|
33
|
+
spec.add_development_dependency 'hashie', '~>4.0.0'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
36
|
+
spec.add_dependency 'rest-client', '>= 2.1.0'
|
37
|
+
spec.add_dependency 'rspec_junit_formatter', '~>0.4.1'
|
38
38
|
|
39
39
|
end
|
data/lib/japanda.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'dotenv'
|
2
|
+
|
2
3
|
module CanvasFactory
|
3
4
|
Dotenv.load
|
4
5
|
CANVAS_API_V1 ||= "#{ENV['CANVAS_API_HOST']}/api/v1"
|
@@ -7,4 +8,17 @@ module CanvasFactory
|
|
7
8
|
content_type: 'application/json'
|
8
9
|
}
|
9
10
|
CANVAS_ACCOUNT_ID ||= ENV['CANVAS_ACCOUNT_ID']
|
11
|
+
|
12
|
+
# JSON.generate see: https://github.com/rest-client/rest-client/issues/635/
|
13
|
+
def self.perform_post(end_point, body)
|
14
|
+
JSON.parse(RestClient.post end_point, JSON.generate(body), CANVAS_AUTH_HEADER)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.perform_put(end_point, body)
|
18
|
+
JSON.parse(RestClient.put end_point, JSON.generate(body), CANVAS_AUTH_HEADER)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.perform_delete(end_point)
|
22
|
+
JSON.parse(RestClient.delete end_point, CANVAS_AUTH_HEADER)
|
23
|
+
end
|
10
24
|
end
|
@@ -1,19 +1,14 @@
|
|
1
|
-
# assignment class
|
2
1
|
module CanvasFactory
|
2
|
+
# assignment class
|
3
3
|
class Assignment
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :id, :name, :course_id, :html_url, :grading_type, :published, :due_at,
|
5
|
+
:created_at, :request, :response
|
5
6
|
|
6
|
-
def
|
7
|
-
@
|
8
|
-
|
9
|
-
@assignments << add_assignment(opts, i)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_assignment(opts, i)
|
14
|
-
body = {
|
7
|
+
def initialize(course_id, opts = {}, merge = true)
|
8
|
+
@course_id = course_id
|
9
|
+
@request = {
|
15
10
|
assignment: {
|
16
|
-
name: "Assignment-#{
|
11
|
+
name: "Assignment-#{Time.now.to_i}",
|
17
12
|
grading_type: %w(pass_fail percent letter_grade gpa_scale points).sample,
|
18
13
|
submission_types: ['online_text_entry'],
|
19
14
|
points_possible: 10,
|
@@ -21,11 +16,23 @@ module CanvasFactory
|
|
21
16
|
published: true
|
22
17
|
}
|
23
18
|
}
|
24
|
-
|
19
|
+
@request = Mergie.deep_merge(@request, opts, merge)
|
20
|
+
create_assignment
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def create_assignment
|
27
|
+
assign_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/assignments"
|
28
|
+
@response = CanvasFactory.perform_post(assign_end_point, @request)
|
29
|
+
@id = response['id']
|
30
|
+
@name = response['name']
|
31
|
+
@html_url = response['html_url']
|
32
|
+
@grading_type = response['grading_type']
|
33
|
+
@published = response['published']
|
34
|
+
@created_at = response['created_at']
|
35
|
+
@due_at = response['due_at']
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
@@ -1,18 +1,83 @@
|
|
1
|
-
# canvas course class
|
2
1
|
module CanvasFactory
|
2
|
+
# canvas course class
|
3
3
|
class Course
|
4
|
-
attr_reader :course_response, :course_id, :
|
4
|
+
attr_reader :course_response, :course_id, :course_code, :course_name, :course_request,
|
5
|
+
:sections, :modules, :assignments, :quizzes
|
5
6
|
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
@
|
7
|
+
def initialize(opts = {}, merge = true)
|
8
|
+
@sections = []
|
9
|
+
@modules = []
|
10
|
+
@assignments = []
|
11
|
+
@quizzes = []
|
12
|
+
course_name_code = "auto#{SecureRandom.hex}"
|
13
|
+
@course_request = {
|
14
|
+
account_id: CANVAS_ACCOUNT_ID,
|
15
|
+
course: {
|
16
|
+
name: course_name_code,
|
17
|
+
course_code: course_name_code,
|
18
|
+
start_at: Time.now,
|
19
|
+
end_at: Time.now + (30 * 24 * 60 * 60),
|
20
|
+
license: 'public_domain',
|
21
|
+
is_public: true,
|
22
|
+
is_public_to_auth_users: false,
|
23
|
+
public_syllabus: false,
|
24
|
+
public_description: 'api created course',
|
25
|
+
allow_student_wiki_edits: true,
|
26
|
+
allow_wiki_comments: true,
|
27
|
+
allow_student_forum_attachments: true,
|
28
|
+
open_enrollment: true,
|
29
|
+
self_enrollment: false,
|
30
|
+
restrict_enrollments_to_course_dates: false,
|
31
|
+
term_id: nil,
|
32
|
+
# sis_course_id: '', # field is included only when user has permission to view SIS information
|
33
|
+
# integration_id: '', # field is included only when user has permission to view SIS information
|
34
|
+
hide_final_grades: true,
|
35
|
+
apply_assignment_group_weights: false,
|
36
|
+
syllabus_body: 'api syllabus',
|
37
|
+
grading_standard_id: nil,
|
38
|
+
course_format: 'online'
|
39
|
+
},
|
40
|
+
offer: true,
|
41
|
+
enroll_me: false,
|
42
|
+
enable_sis_reactivation: false
|
43
|
+
}
|
44
|
+
@course_request = Mergie.deep_merge(@course_request, opts, merge)
|
45
|
+
create_course
|
9
46
|
end
|
10
47
|
|
11
|
-
def
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
48
|
+
def add_section(opts = {}, merge = true)
|
49
|
+
section = CanvasFactory::Section.new(@course_id, opts, merge)
|
50
|
+
@sections << section
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_module(opts = {}, merge = true)
|
54
|
+
mod = CanvasFactory::Module.new(@course_id, opts, merge)
|
55
|
+
@modules << mod
|
56
|
+
mod
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_assignment(opts = {}, merge = true)
|
60
|
+
assignment = CanvasFactory::Assignment.new(@course_id, opts, merge)
|
61
|
+
@assignments << assignment
|
62
|
+
assignment
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_quiz(opts = {}, merge = true)
|
66
|
+
quiz = CanvasFactory::Quiz.new(@course_id, opts, merge)
|
67
|
+
@quizzes << quiz
|
68
|
+
quiz
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_course
|
72
|
+
delete_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}?event=delete"
|
73
|
+
CanvasFactory.perform_delete(delete_end_point)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def create_course
|
79
|
+
course_end_point = "#{CANVAS_API_V1}/accounts/#{@course_request[:account_id]}/courses"
|
80
|
+
@course_response = CanvasFactory.perform_post(course_end_point, @course_request)
|
16
81
|
@course_id = @course_response['id']
|
17
82
|
@course_name = @course_response['name']
|
18
83
|
@course_code = @course_response['course_code']
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'hashie/extensions/deep_merge'
|
2
|
+
module CanvasFactory
|
3
|
+
class Mergie < Hash
|
4
|
+
include Hashie::Extensions::DeepMerge
|
5
|
+
|
6
|
+
def self.deep_merge(default_hash, given_hash, should_merge)
|
7
|
+
should_merge ? Mergie[default_hash].deep_merge(Mergie[given_hash]).to_h: given_hash
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,46 +1,51 @@
|
|
1
|
-
# canvas module class
|
2
1
|
module CanvasFactory
|
2
|
+
# canvas module class
|
3
3
|
class Module
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :course_id, :name, :module_id, :published, :request, :response,
|
5
|
+
:module_items, :publish_response, :publish_request
|
5
6
|
|
6
|
-
def
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
@modules
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_module_add_item_publish(opts)
|
15
|
-
body = {
|
7
|
+
def initialize(course_id, opts = {}, merge = true)
|
8
|
+
@module_items = []
|
9
|
+
@course_id = course_id
|
10
|
+
@request = {
|
16
11
|
module: {
|
17
|
-
name: "
|
12
|
+
name: "module-#{Time.now.to_i}",
|
18
13
|
unlock_at: DateTime.now.iso8601,
|
19
14
|
require_sequential_progress: true
|
20
15
|
}
|
21
16
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
m = JSON.parse(response)
|
27
|
-
|
28
|
-
mi = CanvasFactory::ModuleItem.new
|
29
|
-
mi.add_module_items(m['id'], opts)
|
17
|
+
@request = Mergie.deep_merge(@request, opts, merge)
|
18
|
+
create_module
|
19
|
+
self
|
20
|
+
end
|
30
21
|
|
31
|
-
|
32
|
-
|
22
|
+
def add_module_item(content, opts = {}, merge = true) # content can be assignment or quiz ...
|
23
|
+
module_item = CanvasFactory::ModuleItem.new(@course_id, @module_id, content, opts, merge)
|
24
|
+
@module_items << module_item
|
25
|
+
module_item
|
33
26
|
end
|
34
27
|
|
35
|
-
def
|
36
|
-
|
28
|
+
def publish(opts = {}, merge = true)
|
29
|
+
@publish_request = {
|
37
30
|
module: {
|
38
31
|
published: true
|
39
32
|
}
|
40
33
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
@publish_request = Mergie.deep_merge(@publish_request, opts, merge)
|
35
|
+
publish_ep = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@module_id}"
|
36
|
+
@publish_response = CanvasFactory.perform_put(publish_ep, @publish_request)
|
37
|
+
@published = @publish_response['published']
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def create_module
|
43
|
+
m_item_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules"
|
44
|
+
@response = CanvasFactory.perform_post(m_item_end_point, @request)
|
45
|
+
@course_id = course_id
|
46
|
+
@module_id = response['id']
|
47
|
+
@name = response['name']
|
48
|
+
@published = response['published']
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
@@ -1,31 +1,37 @@
|
|
1
|
-
# canvas module_item class
|
2
1
|
module CanvasFactory
|
2
|
+
# module item class
|
3
3
|
class ModuleItem
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :item_id, :name, :course_id, :html_url, :title, :published, :type,
|
5
|
+
:created_at, :request, :response, :module_id
|
5
6
|
|
6
|
-
def
|
7
|
-
@
|
8
|
-
|
9
|
-
|
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 = {
|
7
|
+
def initialize(course_id, module_id, content, opts = {}, merge = true)
|
8
|
+
@course_id = course_id
|
9
|
+
@module_id = module_id
|
10
|
+
@request = {
|
17
11
|
module_item: {
|
18
|
-
title: "
|
19
|
-
type:
|
20
|
-
content_id:
|
12
|
+
title: "module-item#{SecureRandom.hex}",
|
13
|
+
type: content.class.name.split('::').last || '',
|
14
|
+
content_id: content.id,
|
21
15
|
completion_requirement: {
|
22
16
|
type: 'must_view'
|
23
17
|
}
|
24
18
|
}
|
25
19
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
@request = Mergie.deep_merge(@request, opts, merge)
|
21
|
+
create_item
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create_item
|
28
|
+
item_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@module_id}/items"
|
29
|
+
@response = CanvasFactory.perform_post(item_end_point, @request)
|
30
|
+
@published = response['published']
|
31
|
+
@item_id = response['id']
|
32
|
+
@type = response['type']
|
33
|
+
@title = response['title']
|
34
|
+
@html_url = response['html_url']
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module CanvasFactory
|
2
|
+
# Quiz class
|
3
|
+
class Quiz
|
4
|
+
attr_reader :id, :course_id, :html_url, :published, :due_at, :title,
|
5
|
+
:request, :response
|
6
|
+
|
7
|
+
def initialize(course_id, opts = {}, merge = true)
|
8
|
+
@course_id = course_id
|
9
|
+
@request = {
|
10
|
+
quiz: {
|
11
|
+
title: "quiz-#{Time.now.to_i}",
|
12
|
+
description: 'api created quiz',
|
13
|
+
quiz_type: %w(practice_quiz assignment graded_survey survey).sample,
|
14
|
+
assignment_group_id: nil,
|
15
|
+
time_limit: nil,
|
16
|
+
shuffle_answers: true,
|
17
|
+
hide_results: %w(always until_after_last_attempt).sample,
|
18
|
+
show_correct_answers: true,
|
19
|
+
show_correct_answers_last_attempt: true,
|
20
|
+
hide_correct_answers_at: true,
|
21
|
+
allowed_attempts: 1,
|
22
|
+
scoring_policy: %w(keep_highest keep_latest).sample,
|
23
|
+
one_question_at_a_time: false,
|
24
|
+
cant_go_back: false,
|
25
|
+
access_code: nil,
|
26
|
+
ip_filter: nil,
|
27
|
+
due_at: (DateTime.now + 10).iso8601,
|
28
|
+
lock_at: (DateTime.now + 10).iso8601,
|
29
|
+
unlock_at: (DateTime.now).iso8601,
|
30
|
+
published: true,
|
31
|
+
one_time_results: false
|
32
|
+
}
|
33
|
+
}
|
34
|
+
@request = Mergie.deep_merge(@request, opts, merge)
|
35
|
+
create_quiz
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def create_quiz
|
42
|
+
quiz_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/quizzes"
|
43
|
+
@response = CanvasFactory.perform_post(quiz_end_point, @request)
|
44
|
+
@id = response['id']
|
45
|
+
@title = response['title']
|
46
|
+
@html_url = response['html_url']
|
47
|
+
@published = response['published']
|
48
|
+
@due_at = response['due_at']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -1,22 +1,36 @@
|
|
1
|
-
# canvas section class
|
2
1
|
module CanvasFactory
|
2
|
+
# canvas section class
|
3
3
|
class Section
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :course_id, :id, :end_at, :start_at, :name, :sis_section_id, :sis_course_id,
|
5
|
+
:integration_id, :sis_import_id, :nonxlist_course_id, :request, :response
|
5
6
|
|
6
|
-
def
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def initialize(course_id, opts = {}, merge = true)
|
8
|
+
@course_id = course_id
|
9
|
+
@request = {
|
10
|
+
course_section: {
|
11
|
+
name: "section-#{Time.now.to_i}",
|
12
|
+
start_at: Time.now,
|
13
|
+
end_at: Time.now + (30 * 24 * 60 * 60),
|
14
|
+
restrict_enrollments_to_section_dates: false,
|
15
|
+
# enable_sis_reactivation: false,
|
16
|
+
# sis_section_id: nil
|
13
17
|
}
|
18
|
+
}
|
19
|
+
@request = Mergie.deep_merge(@request, opts, merge)
|
20
|
+
create_section
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
14
25
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
26
|
+
def create_section
|
27
|
+
section_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/sections"
|
28
|
+
@response = CanvasFactory.perform_post(section_end_point, @request)
|
29
|
+
@course_id = response['course_id']
|
30
|
+
@id = response['id']
|
31
|
+
@name = response['name']
|
32
|
+
@end_at = response['end_at']
|
33
|
+
@start_at = response['start_at']
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
@@ -1,31 +1,67 @@
|
|
1
|
-
# canvas user class
|
2
1
|
module CanvasFactory
|
2
|
+
# canvas user class
|
3
3
|
class User
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :learner_request, :user_response, :id, :admin_request,
|
5
|
+
:email_id, :short_name, :password
|
5
6
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
@
|
7
|
+
def initialize(opts = {}, merge = true)
|
8
|
+
unique_email = "#{@email_prefix}#{SecureRandom.hex}@example.com"
|
9
|
+
@learner_request = {
|
10
|
+
user: {
|
11
|
+
name: unique_email,
|
12
|
+
short_name: 'auto user',
|
13
|
+
terms_of_use: '1',
|
14
|
+
send_confirmation: true
|
15
|
+
},
|
16
|
+
pseudonym: {
|
17
|
+
unique_id: unique_email,
|
18
|
+
password: 'Testing01'
|
19
|
+
},
|
20
|
+
force_validations: true
|
21
|
+
}
|
22
|
+
@learner_request = Mergie.deep_merge(@learner_request, opts, merge)
|
23
|
+
create_learner_user
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_user
|
27
|
+
user_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/users/#{@id}"
|
28
|
+
@user_response = CanvasFactory.perform_delete(user_end_point)
|
9
29
|
end
|
10
30
|
|
31
|
+
private
|
32
|
+
|
11
33
|
def create_learner_user
|
12
|
-
@user_config.set_up_user_hash
|
13
|
-
body = @user_config.config_user_hash
|
14
34
|
user_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/users"
|
15
|
-
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
35
|
+
@user_response = CanvasFactory.perform_post(user_end_point, @learner_request)
|
36
|
+
@id = @user_response['id']
|
37
|
+
@email_id = @user_response['login_id']
|
38
|
+
@short_name = @user_response['short_name']
|
39
|
+
@password = @learner_request[:pseudonym][:password]
|
40
|
+
@user_response
|
21
41
|
end
|
42
|
+
end
|
22
43
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
44
|
+
# canvas admin user class
|
45
|
+
class AdminUser < User
|
46
|
+
def initialize(opts = {}, merge = true)
|
47
|
+
super(opts, merge)
|
48
|
+
make_admin_user
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def make_admin_user
|
54
|
+
@admin_request = {
|
55
|
+
user_id: @id,
|
56
|
+
role_id: 'AccountAdmin',
|
57
|
+
send_confirmation: true
|
58
|
+
}
|
59
|
+
admin_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/admins"
|
60
|
+
@admin_response = CanvasFactory.perform_post(admin_end_point, @admin_request)
|
61
|
+
@id = @admin_response['user']['id']
|
62
|
+
@email_id = @admin_response['user']['login_id']
|
63
|
+
@short_name = @admin_response['user']['short_name']
|
64
|
+
@admin_response
|
29
65
|
end
|
30
66
|
end
|
31
67
|
end
|
data/lib/japanda/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: japanda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Santosh Natarajan
|
8
|
-
|
8
|
+
- Robert Lamb
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -16,30 +17,30 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
20
|
+
version: '1.5'
|
20
21
|
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
27
|
+
version: '1.5'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: byebug
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: dotenv
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - ">="
|
@@ -53,83 +54,114 @@ dependencies:
|
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
+
name: hashie
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
57
72
|
requirement: !ruby/object:Gem::Requirement
|
58
73
|
requirements:
|
59
74
|
- - ">="
|
60
75
|
- !ruby/object:Gem::Version
|
61
76
|
version: '0'
|
62
|
-
type: :
|
77
|
+
type: :development
|
63
78
|
prerelease: false
|
64
79
|
version_requirements: !ruby/object:Gem::Requirement
|
65
80
|
requirements:
|
66
81
|
- - ">="
|
67
82
|
- !ruby/object:Gem::Version
|
68
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.5.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.5.0
|
69
98
|
- !ruby/object:Gem::Dependency
|
70
99
|
name: rest-client
|
71
100
|
requirement: !ruby/object:Gem::Requirement
|
72
101
|
requirements:
|
73
102
|
- - ">="
|
74
103
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
104
|
+
version: 2.1.0
|
76
105
|
type: :runtime
|
77
106
|
prerelease: false
|
78
107
|
version_requirements: !ruby/object:Gem::Requirement
|
79
108
|
requirements:
|
80
109
|
- - ">="
|
81
110
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
111
|
+
version: 2.1.0
|
83
112
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
113
|
+
name: rspec_junit_formatter
|
85
114
|
requirement: !ruby/object:Gem::Requirement
|
86
115
|
requirements:
|
87
|
-
- - "
|
116
|
+
- - "~>"
|
88
117
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
118
|
+
version: 0.4.1
|
90
119
|
type: :runtime
|
91
120
|
prerelease: false
|
92
121
|
version_requirements: !ruby/object:Gem::Requirement
|
93
122
|
requirements:
|
94
|
-
- - "
|
123
|
+
- - "~>"
|
95
124
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
description: Library to create custom course
|
125
|
+
version: 0.4.1
|
126
|
+
description: Library to create custom course. wip.
|
98
127
|
email:
|
99
128
|
- snatarajan@instructure.com
|
129
|
+
- rlamb@instructure.com
|
100
130
|
executables: []
|
101
131
|
extensions: []
|
102
132
|
extra_rdoc_files: []
|
103
133
|
files:
|
134
|
+
- ".env.example"
|
104
135
|
- ".gitignore"
|
105
136
|
- ".rspec"
|
137
|
+
- ".ruby-version"
|
106
138
|
- ".travis.yml"
|
107
139
|
- CODE_OF_CONDUCT.md
|
140
|
+
- Dockerfile
|
108
141
|
- Gemfile
|
109
|
-
-
|
142
|
+
- Gemfile.lock
|
143
|
+
- Jenkinsfile
|
110
144
|
- README.md
|
111
145
|
- Rakefile
|
112
146
|
- bin/console
|
113
147
|
- bin/setup
|
148
|
+
- docker-compose.yml
|
114
149
|
- japanda.gemspec
|
115
150
|
- lib/japanda.rb
|
116
151
|
- lib/japanda/canvas_factory.rb
|
117
152
|
- lib/japanda/canvas_factory/assignment.rb
|
118
153
|
- lib/japanda/canvas_factory/course.rb
|
119
|
-
- lib/japanda/canvas_factory/
|
154
|
+
- lib/japanda/canvas_factory/mergie.rb
|
120
155
|
- lib/japanda/canvas_factory/module.rb
|
121
156
|
- lib/japanda/canvas_factory/module_item.rb
|
157
|
+
- lib/japanda/canvas_factory/quiz.rb
|
122
158
|
- lib/japanda/canvas_factory/section.rb
|
123
159
|
- lib/japanda/canvas_factory/user.rb
|
124
|
-
- lib/japanda/canvas_factory/user_config.rb
|
125
|
-
- lib/japanda/catalog_factory.rb
|
126
|
-
- lib/japanda/catalog_factory/course_program.rb
|
127
160
|
- lib/japanda/version.rb
|
128
|
-
homepage:
|
129
|
-
licenses:
|
130
|
-
- MIT
|
161
|
+
homepage:
|
162
|
+
licenses: []
|
131
163
|
metadata: {}
|
132
|
-
post_install_message:
|
164
|
+
post_install_message:
|
133
165
|
rdoc_options: []
|
134
166
|
require_paths:
|
135
167
|
- lib
|
@@ -144,9 +176,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
176
|
- !ruby/object:Gem::Version
|
145
177
|
version: '0'
|
146
178
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
179
|
+
rubygems_version: 3.0.8
|
180
|
+
signing_key:
|
150
181
|
specification_version: 4
|
151
|
-
summary: Library to create custom course
|
182
|
+
summary: Library to create custom course.
|
152
183
|
test_files: []
|
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,28 +0,0 @@
|
|
1
|
-
module CanvasFactory
|
2
|
-
class CourseConfig
|
3
|
-
attr_accessor :course_request, :account_id, :name, :course_code, :start_at, :end_at, :offer
|
4
|
-
|
5
|
-
def initialize(opts = {})
|
6
|
-
course_name_code = "auto#{SecureRandom.hex}"
|
7
|
-
@account_id = opts[:account_id] || CANVAS_ACCOUNT_ID
|
8
|
-
@name = opts[:name] || course_name_code
|
9
|
-
@course_code = opts[:course_code] || course_name_code
|
10
|
-
@start_at = opts[:start_at] || Time.now
|
11
|
-
@end_at = opts[:end_at] || Time.now + (30 * 24 * 60 * 60)
|
12
|
-
@offer = opts[:offer] || true
|
13
|
-
end
|
14
|
-
|
15
|
-
def set_course_request
|
16
|
-
@course_request = {
|
17
|
-
account_id: @account_id,
|
18
|
-
course: {
|
19
|
-
name: @name,
|
20
|
-
course_code: @course_code,
|
21
|
-
start_at: @start_at,
|
22
|
-
end_at: @end_at
|
23
|
-
},
|
24
|
-
offer: @offer
|
25
|
-
}
|
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_accessor :email_prefix, :password, :short_name, :terms_of_use, :send_confirmation, :force_validations, :role_id, :email_id
|
5
|
-
|
6
|
-
def initialize(opts = {})
|
7
|
-
@email_prefix = opts[:email_prefix] || 'catauto'
|
8
|
-
@password = opts[:password] || 'Testing01'
|
9
|
-
@short_name = opts[:short_name] || 'cat auto'
|
10
|
-
@terms_of_use = opts[:terms_of_use] || '1'
|
11
|
-
@send_confirmation = opts[:send_confirmation] || true
|
12
|
-
@force_validations = opts[:force_validations] || true
|
13
|
-
@role_id = opts[:role_id] || 'AccountAdmin'
|
14
|
-
@email_id = opts[:email_id] || "#{@email_prefix}#{SecureRandom.hex}@example.com"
|
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
|