japanda 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/README.md +2 -0
- data/lib/japanda.rb +0 -11
- data/lib/japanda/canvas_factory.rb +10 -0
- data/lib/{canvas_factory → japanda/canvas_factory}/assignment.rb +0 -0
- data/lib/japanda/canvas_factory/course.rb +22 -0
- data/lib/japanda/canvas_factory/course_config.rb +28 -0
- data/lib/{canvas_factory → japanda/canvas_factory}/module.rb +0 -0
- data/lib/{canvas_factory → japanda/canvas_factory}/module_item.rb +0 -0
- data/lib/{canvas_factory → japanda/canvas_factory}/section.rb +0 -0
- data/lib/japanda/canvas_factory/user.rb +31 -0
- data/lib/{canvas_factory → japanda/canvas_factory}/user_config.rb +10 -10
- data/lib/japanda/catalog_factory.rb +6 -0
- data/lib/{catalog_factory → japanda/catalog_factory}/course_program.rb +0 -0
- data/lib/japanda/version.rb +1 -1
- metadata +13 -10
- data/lib/canvas_factory/course.rb +0 -55
- data/lib/canvas_factory/user.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abbd951e967108454451a2dead9d17e93c1c2ba7
|
4
|
+
data.tar.gz: a2c8ee97e2f6ac89b5374365008609639600026f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dcce860b5fede22513b30ff8fb051b249a797d8b0bb2e2b03ac53c0350d34abc7aa11f700ab7ade14414f568e07bbe13a1300e8d0b904af508cbba9b5536e5d
|
7
|
+
data.tar.gz: 6318804d2b3153d09bd9077d910be80e11e9b96644d498e3dd18e0aaf07b2d650e923ef5044c4b04e9f0e94ebb3d230f4f0325c0e604b285fedfeed2d789edcb
|
data/README.md
CHANGED
@@ -23,11 +23,13 @@ Or install it yourself as:
|
|
23
23
|
## Usage
|
24
24
|
Set a few enviroment variables:
|
25
25
|
|
26
|
+
```ruby
|
26
27
|
export CANVAS_API_HOST=
|
27
28
|
export CANVAS_API_TOKEN=
|
28
29
|
export CANVAS_ACCOUNT_ID=
|
29
30
|
export GALLERY_API_HOST=
|
30
31
|
export GALLERY_API_TOKEN=
|
32
|
+
```
|
31
33
|
|
32
34
|
## Development
|
33
35
|
|
data/lib/japanda.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
require 'japanda/version'
|
2
2
|
require 'securerandom'
|
3
|
-
require 'dotenv'
|
4
3
|
|
5
4
|
module Japanda
|
6
|
-
Dotenv.load
|
7
|
-
CANVAS_USER_DOMAIN ||= ENV['CANVAS_USER_DOMAIN']
|
8
|
-
CANVAS_API_V1 ||= "#{ENV['CANVAS_API_HOST']}/api/v1"
|
9
|
-
CANVAS_AUTH_HEADER ||= {
|
10
|
-
Authorization: "Bearer #{ENV['CANVAS_API_TOKEN']}",
|
11
|
-
content_type: 'application/json'
|
12
|
-
}
|
13
|
-
CANVAS_ACCOUNT_ID ||= ENV['CANVAS_ACCOUNT_ID']
|
14
|
-
GALLERY_API_TOKEN ||= ENV['GALLERY_API_TOKEN']
|
15
|
-
GALLERY_API_HOST = ENV['GALLERY_API_HOST']
|
16
5
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
module CanvasFactory
|
3
|
+
Dotenv.load
|
4
|
+
CANVAS_API_V1 ||= "#{ENV['CANVAS_API_HOST']}/api/v1"
|
5
|
+
CANVAS_AUTH_HEADER ||= {
|
6
|
+
Authorization: "Bearer #{ENV['CANVAS_API_TOKEN']}",
|
7
|
+
content_type: 'application/json'
|
8
|
+
}
|
9
|
+
CANVAS_ACCOUNT_ID ||= ENV['CANVAS_ACCOUNT_ID']
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# canvas course class
|
2
|
+
module CanvasFactory
|
3
|
+
class Course
|
4
|
+
attr_reader :course_response, :course_id, :course_config, :course_code, :course_name
|
5
|
+
|
6
|
+
def initialize(course_config = nil)
|
7
|
+
@course_config = course_config
|
8
|
+
@course_config = CanvasFactory::CourseConfig.new if course_config.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@course_config.set_course_request
|
13
|
+
course_end_point = "#{CANVAS_API_V1}/accounts/#{@course_config.account_id}/courses"
|
14
|
+
response = RestClient.post course_end_point, @course_config.course_request, CANVAS_AUTH_HEADER
|
15
|
+
@course_response = JSON.parse(response)
|
16
|
+
@course_id = @course_response['id']
|
17
|
+
@course_name = @course_response['name']
|
18
|
+
@course_code = @course_response['course_code']
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
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
|
+
|
6
|
+
def initialize(user_config = nil)
|
7
|
+
@user_config = user_config
|
8
|
+
@user_config = CanvasFactory::UserConfig.new if user_config.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_learner_user
|
12
|
+
@user_config.set_up_user_hash
|
13
|
+
body = @user_config.config_user_hash
|
14
|
+
user_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/users"
|
15
|
+
response = RestClient.post user_end_point, body, CANVAS_AUTH_HEADER
|
16
|
+
@user_response = JSON.parse(response)
|
17
|
+
@user_response_id = @user_response['id']
|
18
|
+
@user_response_email_id = @user_response['login_id']
|
19
|
+
@user_short_name = @user_config.short_name
|
20
|
+
@user_password = @user_config.password
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_admin_user
|
24
|
+
create_learner_user
|
25
|
+
@user_config.set_up_admin_hash(@user_response['id'].to_i)
|
26
|
+
body = @user_config.config_admin_hash
|
27
|
+
a_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/admins"
|
28
|
+
RestClient.post a_end_point, body, CANVAS_AUTH_HEADER
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module CanvasFactory
|
2
2
|
class UserConfig
|
3
3
|
attr_reader :config_user_hash, :config_admin_hash
|
4
|
-
|
4
|
+
attr_accessor :email_prefix, :password, :short_name, :terms_of_use, :send_confirmation, :force_validations, :role_id, :email_id
|
5
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
|
-
@
|
14
|
-
@
|
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
15
|
end
|
16
16
|
|
17
17
|
def set_up_user_hash
|
File without changes
|
data/lib/japanda/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Santosh Natarajan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,15 +112,18 @@ files:
|
|
112
112
|
- bin/console
|
113
113
|
- bin/setup
|
114
114
|
- japanda.gemspec
|
115
|
-
- lib/canvas_factory/assignment.rb
|
116
|
-
- lib/canvas_factory/course.rb
|
117
|
-
- lib/canvas_factory/module.rb
|
118
|
-
- lib/canvas_factory/module_item.rb
|
119
|
-
- lib/canvas_factory/section.rb
|
120
|
-
- lib/canvas_factory/user.rb
|
121
|
-
- lib/canvas_factory/user_config.rb
|
122
|
-
- lib/catalog_factory/course_program.rb
|
123
115
|
- lib/japanda.rb
|
116
|
+
- lib/japanda/canvas_factory.rb
|
117
|
+
- lib/japanda/canvas_factory/assignment.rb
|
118
|
+
- lib/japanda/canvas_factory/course.rb
|
119
|
+
- lib/japanda/canvas_factory/course_config.rb
|
120
|
+
- lib/japanda/canvas_factory/module.rb
|
121
|
+
- lib/japanda/canvas_factory/module_item.rb
|
122
|
+
- lib/japanda/canvas_factory/section.rb
|
123
|
+
- 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
|
124
127
|
- lib/japanda/version.rb
|
125
128
|
homepage: https://github.com/babababili/japanda
|
126
129
|
licenses:
|
@@ -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
|
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
|