japanda 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b6f742d4af878f7abb31f306a4eb627dac08ee7
4
- data.tar.gz: 1f9002401e828188a0de0a37c0e8585043e5d8b5
3
+ metadata.gz: c88d5e552e2c67042dd5da76188c48ffefc2f8b7
4
+ data.tar.gz: b871098f94298c6ad6c0acb22c7d12a01a6bbd25
5
5
  SHA512:
6
- metadata.gz: 1640cc2ebf9a6e41fa780dff1fdff3b0d5c7b53513ef0e15bba66acd8ca50c353d84846bf7259e863f4c0284bcdc5c21e1c0a929fda2d1a8b2b13343db9a50cd
7
- data.tar.gz: b95aa945713407aab3ea9b3bad1bebe94a81a186dc632a9cd10027a8e5d02f270ce59726498f07109b61bfc95294bc0497520fe1310ef36746b5af74c39ea50f
6
+ metadata.gz: cdbcc9424cd02a9923fed5121c7d74638888ab9cb37e25e7286f1ecaa0b70a9c46109ee688fdcfa149c28f81bbccca3eba977d613f8d979a1bad148c692c8012
7
+ data.tar.gz: e4c24a8f9858ebd769ce85723066772e46be305456020c90d6ebdba950cab3f5f53f5753d9569b8c87cdab79d27742e6d6bdb15100824171bea160757533414c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- japanda (0.1.3)
4
+ japanda (0.1.4)
5
5
  rest-client
6
6
 
7
7
  GEM
@@ -11,6 +11,7 @@ GEM
11
11
  domain_name (0.5.24)
12
12
  unf (>= 0.0.5, < 1.0.0)
13
13
  dotenv (2.0.2)
14
+ hashie (2.0.5)
14
15
  http-cookie (1.0.2)
15
16
  domain_name (~> 0.5)
16
17
  mime-types (2.6.2)
@@ -43,9 +44,10 @@ PLATFORMS
43
44
  DEPENDENCIES
44
45
  bundler (>= 1.0.0)
45
46
  dotenv
47
+ hashie
46
48
  japanda!
47
49
  rake (~> 10.0)
48
50
  rspec
49
51
 
50
52
  BUNDLED WITH
51
- 1.10.5
53
+ 1.10.6
data/README.md CHANGED
@@ -1,20 +1,21 @@
1
1
  # Japanda
2
- Japanda provides an object oriented wrapper and functional wrapper around canvas api
3
- Disclaimer: For testing purposes only
4
2
 
5
- v0.1.3: Features
6
- a) Create canvas learner user and admin user
7
- b) Create canvas course
8
- c) Add sections to canvas
9
- d) Add module(s) with assignment(s)
3
+ Japanda provides an object-oriented wrapper and functional wrapper around Instructure Canvas Api's
4
+
5
+ Disclaimer: For testing purposes only.
6
+
7
+ v0.1.3 Features
8
+
9
+ 1. Create canvas learner user and admin user
10
+ 2. Create canvas course
11
+ 3. Add sections to canvas
12
+ 4. Add module(s) with assignment(s)
10
13
 
11
14
  ## Installation
12
15
 
13
16
  Add this line to your application's Gemfile:
14
17
 
15
- ```ruby
16
- gem 'japanda'
17
- ```
18
+ gem 'japanda'
18
19
 
19
20
  And then execute:
20
21
 
@@ -25,34 +26,45 @@ Or install it yourself as:
25
26
  $ gem install japanda
26
27
 
27
28
  ## Usage
29
+
28
30
  Set a few enviroment variables( or use .env.example file)
29
31
 
30
- ```ruby
31
- export CANVAS_API_HOST=
32
- export CANVAS_API_TOKEN=
33
- export CANVAS_ACCOUNT_ID=
34
- ```
32
+ export CANVAS_API_HOST=
33
+ export CANVAS_API_TOKEN=
34
+ export CANVAS_ACCOUNT_ID=
35
+
36
+ To create a new course
35
37
 
36
- ```ruby
37
- new canvas course, uses default course_config
38
- CanvasFactory::Course.new
38
+ CanvasFactory::Course.new
39
+
40
+ To create a canvas course by specifying the course config
39
41
 
40
- create a canvas course by specifying the course config
41
- course_config = CanvasFactory::CourseConfig.new({ name: 'Candy Tasting' })
42
- course = CanvasFactory::Course.new course_config
43
- ```
42
+ course_config = CanvasFactory::CourseConfig.new({ name: 'Candy Tasting' })
43
+ course = CanvasFactory::Course.new course_config
44
+
45
+ To create a canvas learner user
46
+
47
+ user_config = CanvasFactory::UserConfig.new(short_name: 'John Doe', password: 'Password01')
48
+ user = CanvasFactory::User.new(user_config)
49
+ learner_user = user.create_learner_user
44
50
 
45
51
  ## Development
46
52
 
47
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
54
+ To install this gem onto your local machine, run `bundle exec rake install`.
55
+
56
+ ## Release a new version
57
+
58
+ 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).
48
59
 
49
- 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).
50
60
 
51
61
  ## Contributing
52
62
 
53
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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.
63
+ 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.
54
64
 
55
65
 
56
66
  ## License
57
- For testing purposes only
67
+
68
+ For testing purposes only.
69
+
58
70
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -6,8 +6,8 @@ require 'japanda/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'japanda'
8
8
  spec.version = Japanda::VERSION
9
- spec.authors = ['Santosh Natarajan']
10
- spec.email = ['snatarajan@instructure.com']
9
+ spec.authors = ['Santosh Natarajan', 'Robert Lamb']
10
+ spec.email = ['snatarajan@instructure.com', 'rlamb@instructure.com']
11
11
 
12
12
  spec.summary = %q{Library to create custom course.}
13
13
  spec.description = %q{Library to create custom course. wip.}
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '>= 1.0.0'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
32
  spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'hashie'
33
34
  spec.add_development_dependency 'dotenv'
34
35
  spec.add_dependency 'rest-client'
35
36
  end
@@ -1,17 +1,31 @@
1
- # assignment class
2
1
  module CanvasFactory
2
+ # assignment class
3
3
  class Assignment
4
- attr_reader :id, :name, :course_id, :html_url, :grading_type, :published, :due_at, :created_at
4
+ attr_reader :id, :name, :course_id, :html_url, :grading_type, :published, :due_at,
5
+ :created_at, :request, :response
5
6
 
6
- def initialize(course_id, assignment_config = CanvasFactory::AssignmentConfig.new)
7
- fail 'invalid course_id' if course_id.nil?
7
+ def initialize(course_id, opts = {}, merge = true)
8
8
  @course_id = course_id
9
- create_assignment course_id, assignment_config
9
+ @request = {
10
+ assignment: {
11
+ name: "Assignment-#{Time.now.to_i}",
12
+ grading_type: %w(pass_fail percent letter_grade gpa_scale points).sample,
13
+ submission_types: ['online_text_entry'],
14
+ points_possible: 10,
15
+ due_at: (DateTime.now + 1).iso8601,
16
+ published: true
17
+ }
18
+ }
19
+ @request = Mergie.deep_merge(@request, opts, merge)
20
+ create_assignment
21
+ self
10
22
  end
11
23
 
12
- def create_assignment(course_id, assignment_config)
13
- assign_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/assignments"
14
- response = CanvasFactory.perform_post(assign_end_point, assignment_config.request_body)
24
+ private
25
+
26
+ def create_assignment
27
+ assign_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/assignments"
28
+ @response = CanvasFactory.perform_post(assign_end_point, @request)
15
29
  @id = response['id']
16
30
  @name = response['name']
17
31
  @html_url = response['html_url']
@@ -19,7 +33,6 @@ module CanvasFactory
19
33
  @published = response['published']
20
34
  @created_at = response['created_at']
21
35
  @due_at = response['due_at']
22
- self
23
36
  end
24
37
  end
25
38
  end
@@ -1,16 +1,78 @@
1
- # canvas course class
2
1
  module CanvasFactory
2
+ # canvas course class
3
3
  class Course
4
- attr_reader :course_response, :course_id, :course_code, :course_name, :offer
4
+ attr_reader :course_response, :course_id, :course_code, :course_name, :course_request,
5
+ :sections, :modules, :assignments, :quizzes
5
6
 
6
- def initialize(course_config = CanvasFactory::CourseConfig.new)
7
- @offer = course_config.offer
8
- create_course course_config
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 create_course(course_config)
12
- course_end_point = "#{CANVAS_API_V1}/accounts/#{course_config.account_id}/courses"
13
- @course_response = CanvasFactory.perform_post(course_end_point, course_config.request_body)
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
+ private
72
+
73
+ def create_course
74
+ course_end_point = "#{CANVAS_API_V1}/accounts/#{@course_request[:account_id]}/courses"
75
+ @course_response = CanvasFactory.perform_post(course_end_point, @course_request)
14
76
  @course_id = @course_response['id']
15
77
  @course_name = @course_response['name']
16
78
  @course_code = @course_response['course_code']
@@ -0,0 +1,9 @@
1
+ require 'hashie/extensions/deep_merge'
2
+
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
@@ -1,58 +1,51 @@
1
- # canvas module class
2
1
  module CanvasFactory
2
+ # canvas module class
3
3
  class Module
4
- attr_reader :module, :course_id, :name, :id, :position, :unlock_at, :require_sequential_progress,
5
- :publish_final_grade, :prerequisite_module_ids, :published, :items_count, :items_url,
6
- :assignments
4
+ attr_reader :course_id, :name, :module_id, :published, :request, :response,
5
+ :module_items, :publish_response, :publish_request
7
6
 
8
- def initialize(course_id, module_config = CanvasFactory::ModuleConfig.new)
9
- @assignments = []
10
- create_module course_id, module_config
11
- publish_module
7
+ def initialize(course_id, opts = {}, merge = true)
8
+ @module_items = []
9
+ @course_id = course_id
10
+ @request = {
11
+ module: {
12
+ name: "module-#{Time.now.to_i}",
13
+ unlock_at: DateTime.now.iso8601,
14
+ require_sequential_progress: true
15
+ }
16
+ }
17
+ @request = Mergie.deep_merge(@request, opts, merge)
18
+ create_module
19
+ self
12
20
  end
13
21
 
14
- def create_module(course_id, module_config)
15
- m_item_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/modules"
16
- response = CanvasFactory.perform_post(m_item_end_point, module_config.request_body)
17
- @course_id = course_id
18
- @id = response['id']
19
- @name = response['name']
20
- @position = response['position']
21
- @unlock_at = response['unlock_at']
22
- @require_sequential_progress = response['require_sequential_progress']
23
- @publish_final_grade = response['publish_final_grade']
24
- @prerequisite_module_ids = response['prerequisite_module_ids']
25
- @published = response['published']
26
- @items_count = response['items_count']
27
- @items_url = response['items_url']
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
28
26
  end
29
27
 
30
- def publish_module
31
- body = {
28
+ def publish(opts = {}, merge = true)
29
+ @publish_request = {
32
30
  module: {
33
31
  published: true
34
32
  }
35
33
  }
36
- m_p_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@id}"
37
- response = CanvasFactory.perform_put(m_p_end_point, body)
38
- @published = response['published']
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']
39
38
  end
40
39
 
41
- def add_module_item(module_item_request)
42
- item_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@id}/items"
43
- CanvasFactory.perform_post(item_end_point, module_item_request)
44
- publish_module
45
- end
40
+ private
46
41
 
47
- def add_assignment(title = 'module_assignment', assignment_config = CanvasFactory::AssignmentConfig.new)
48
- assignment = CanvasFactory::Assignment.new(@course_id, assignment_config)
49
- module_item_config = CanvasFactory::ModuleItemConfig.new(module_item_type: 'Assignment',
50
- completion_type: 'must_view')
51
- module_item_config.content_id = assignment.id
52
- module_item_config.title = title
53
- add_module_item(module_item_config.request_body)
54
- @assignments << assignment
55
- assignment
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']
56
49
  end
57
50
  end
58
51
  end
@@ -0,0 +1,37 @@
1
+ module CanvasFactory
2
+ # module item class
3
+ class ModuleItem
4
+ attr_reader :item_id, :name, :course_id, :html_url, :title, :published, :type,
5
+ :created_at, :request, :response, :module_id
6
+
7
+ def initialize(course_id, module_id, content, opts = {}, merge = true)
8
+ @course_id = course_id
9
+ @module_id = module_id
10
+ @request = {
11
+ module_item: {
12
+ title: "module-item#{SecureRandom.hex}",
13
+ type: content.class.name.split('::').last || '',
14
+ content_id: content.id,
15
+ completion_requirement: {
16
+ type: 'must_view'
17
+ }
18
+ }
19
+ }
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']
35
+ end
36
+ end
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,26 +1,36 @@
1
- # canvas section class
2
1
  module CanvasFactory
2
+ # canvas section class
3
3
  class Section
4
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
5
+ :integration_id, :sis_import_id, :nonxlist_course_id, :request, :response
6
6
 
7
- def initialize(course_id, section_config = CanvasFactory::SectionConfig.new)
8
- create_section course_id, section_config
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
17
+ }
18
+ }
19
+ @request = Mergie.deep_merge(@request, opts, merge)
20
+ create_section
21
+ self
9
22
  end
10
23
 
11
- def create_section(course_id, section_config)
12
- section_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/sections"
13
- response = CanvasFactory.perform_post(section_end_point, section_config.request_body)
24
+ private
25
+
26
+ def create_section
27
+ section_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/sections"
28
+ @response = CanvasFactory.perform_post(section_end_point, @request)
14
29
  @course_id = response['course_id']
15
30
  @id = response['id']
16
31
  @name = response['name']
17
32
  @end_at = response['end_at']
18
33
  @start_at = response['start_at']
19
- @sis_section_id = response['sis_section_id']
20
- @sis_course_id = response['sis_course_id']
21
- @integration_id = response['integration_id']
22
- @sis_import_id = response['sis_import_id']
23
- @nonxlist_course_id = response['nonxlist_course_id']
24
34
  end
25
35
  end
26
36
  end
@@ -1,27 +1,58 @@
1
- # canvas user class
2
1
  module CanvasFactory
2
+ # canvas user class
3
3
  class User
4
- attr_reader :user_config, :user_response, :user_response_id,
5
- :user_response_email_id, :user_short_name, :user_password
4
+ attr_reader :learner_request, :user_response, :id, :admin_request,
5
+ :email_id, :short_name, :password
6
6
 
7
- def initialize(user_config = CanvasFactory::UserConfig.new)
8
- @user_config = user_config
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
9
24
  end
10
25
 
26
+ private
27
+
11
28
  def create_learner_user
12
29
  user_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/users"
13
- @user_response = CanvasFactory.perform_post(user_end_point, @user_config.user_request_body)
14
- @user_response_id = @user_response['id']
15
- @user_response_email_id = @user_response['login_id']
16
- @user_short_name = @user_config.short_name
17
- @user_password = @user_config.password
30
+ @user_response = CanvasFactory.perform_post(user_end_point, @learner_request)
31
+ @id = @user_response['id']
32
+ @email_id = @user_response['login_id']
33
+ @short_name = @user_response['short_name']
34
+ @password = @learner_request[:pseudonym][:password]
35
+ @user_response
18
36
  end
37
+ end
19
38
 
20
- def create_admin_user
21
- create_learner_user
22
- body = @user_config.admin_request_body(@user_response['id'].to_i)
39
+ # canvas admin user class
40
+ class AdminUser < User
41
+ def initialize(opts = {}, merge = true)
42
+ super(opts, merge)
43
+ make_admin_user
44
+ end
45
+
46
+ private
47
+
48
+ def make_admin_user
49
+ @admin_request = {
50
+ user_id: @id,
51
+ role_id: 'AccountAdmin',
52
+ send_confirmation: true
53
+ }
23
54
  admin_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/admins"
24
- CanvasFactory.perform_post(admin_end_point, body)
55
+ CanvasFactory.perform_post(admin_end_point, @admin_request)
25
56
  end
26
57
  end
27
58
  end
@@ -1,3 +1,3 @@
1
1
  module Japanda
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santosh Natarajan
8
+ - Robert Lamb
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
12
+ date: 2015-12-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -52,6 +53,20 @@ dependencies:
52
53
  - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: hashie
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
55
70
  - !ruby/object:Gem::Dependency
56
71
  name: dotenv
57
72
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +98,7 @@ dependencies:
83
98
  description: Library to create custom course. wip.
84
99
  email:
85
100
  - snatarajan@instructure.com
101
+ - rlamb@instructure.com
86
102
  executables: []
87
103
  extensions: []
88
104
  extra_rdoc_files: []
@@ -102,16 +118,13 @@ files:
102
118
  - lib/japanda.rb
103
119
  - lib/japanda/canvas_factory.rb
104
120
  - lib/japanda/canvas_factory/assignment.rb
105
- - lib/japanda/canvas_factory/assignment_config.rb
106
121
  - lib/japanda/canvas_factory/course.rb
107
- - lib/japanda/canvas_factory/course_config.rb
122
+ - lib/japanda/canvas_factory/mergie.rb
108
123
  - lib/japanda/canvas_factory/module.rb
109
- - lib/japanda/canvas_factory/module_config.rb
110
- - lib/japanda/canvas_factory/module_item_config.rb
124
+ - lib/japanda/canvas_factory/module_item.rb
125
+ - lib/japanda/canvas_factory/quiz.rb
111
126
  - lib/japanda/canvas_factory/section.rb
112
- - lib/japanda/canvas_factory/section_config.rb
113
127
  - lib/japanda/canvas_factory/user.rb
114
- - lib/japanda/canvas_factory/user_config.rb
115
128
  - lib/japanda/version.rb
116
129
  homepage:
117
130
  licenses: []
@@ -1,27 +0,0 @@
1
- module CanvasFactory
2
- class AssignmentConfig
3
- attr_accessor :name, :grading_type, :submission_types, :points_possible, :due_at, :published
4
-
5
- def initialize(opts = {})
6
- @name = opts[:name] || "Assignment-#{Time.now.to_i}"
7
- @grading_type = opts[:grading_type] || %w(pass_fail percent letter_grade gpa_scale points).sample
8
- @submission_types = opts[:submission_types] || ['online_text_entry']
9
- @points_possible = opts[:points_possible] || 10
10
- @due_at = opts[:due_at] || (DateTime.now + 1).iso8601
11
- @published = opts[:published] || true
12
- end
13
-
14
- def request_body
15
- {
16
- assignment: {
17
- name: @name,
18
- grading_type: @grading_type,
19
- submission_types: @submission_types,
20
- points_possible: @points_possible,
21
- due_at: @due_at,
22
- published: @published
23
- }
24
- }
25
- end
26
- end
27
- end
@@ -1,28 +0,0 @@
1
- module CanvasFactory
2
- class CourseConfig
3
- attr_accessor :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 request_body
16
- {
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,22 +0,0 @@
1
- module CanvasFactory
2
- class ModuleConfig
3
- attr_accessor :name, :unlock_at, :require_sequential_progress
4
-
5
- def initialize(opts = {})
6
- @name = opts[:name] || "module-#{Time.now.to_i}"
7
- @unlock_at = opts[:unlock_at] || DateTime.now.iso8601
8
- @require_sequential_progress = opts[:require_sequential_progress] || true
9
- @published = opts[:published] || true
10
- end
11
-
12
- def request_body
13
- {
14
- module: {
15
- name: @name,
16
- unlock_at: @unlock_at,
17
- require_sequential_progress: @require_sequential_progress
18
- }
19
- }
20
- end
21
- end
22
- end
@@ -1,25 +0,0 @@
1
- module CanvasFactory
2
- class ModuleItemConfig
3
- attr_accessor :module_item_type, :content_id, :completion_type, :title
4
-
5
- def initialize(opts = {})
6
- @module_item_type = opts[:module_item_type] || 'Assignment'
7
- @content_id = opts[:content_id]
8
- @completion_type = opts[:completion_type] || 'must_view'
9
- @title = opts[:title] || 'module_assignment'
10
- end
11
-
12
- def request_body
13
- {
14
- module_item: {
15
- title: @title,
16
- type: @module_item_type,
17
- content_id: @content_id,
18
- completion_requirement: {
19
- type: @completion_type
20
- }
21
- }
22
- }
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- module CanvasFactory
2
- class SectionConfig
3
- attr_accessor :name, :start_at, :end_at
4
-
5
- def initialize(opts = {})
6
- @name = opts[:name] || "section-#{Time.now.to_i}"
7
- @start_at = opts[:start_at] || Time.now
8
- @end_at = opts[:end_at] || Time.now + (30 * 24 * 60 * 60)
9
- end
10
-
11
- def request_body
12
- {
13
- course_section: {
14
- name: @name,
15
- start_at: @start_at,
16
- end_at: @end_at
17
- }
18
- }
19
- end
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- module CanvasFactory
2
- class UserConfig
3
- attr_accessor :email_prefix, :password, :short_name, :terms_of_use, :send_confirmation,
4
- :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 user_request_body
18
- {
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 admin_request_body(id)
34
- {
35
- user_id: id,
36
- role_id: @role_id,
37
- send_confirmation: @send_confirmation
38
- }
39
- end
40
- end
41
- end