japanda 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a73546b584231b34570546f66db906083e5ed84a
4
- data.tar.gz: 9f91f3cbb072dc283ad8fa854ecfd85716883e9e
3
+ metadata.gz: 8b6f742d4af878f7abb31f306a4eb627dac08ee7
4
+ data.tar.gz: 1f9002401e828188a0de0a37c0e8585043e5d8b5
5
5
  SHA512:
6
- metadata.gz: 73c0643f7ac94f80fc9b0ad5f29812b301be7c61accd46fb1e87ad140c5ff7b552f7c7585e12daecaa6e731e8ffbb58ecf7c191f593324da0784bd2bf34f1764
7
- data.tar.gz: 25e70580ffa6e8e66f1611fd2801051280511281e370ba8e1ca450188778ed6df3eb9c7788cda4850b378f1ab7562bb33e48e6a454561d41182b9969d011d661
6
+ metadata.gz: 1640cc2ebf9a6e41fa780dff1fdff3b0d5c7b53513ef0e15bba66acd8ca50c353d84846bf7259e863f4c0284bcdc5c21e1c0a929fda2d1a8b2b13343db9a50cd
7
+ data.tar.gz: b95aa945713407aab3ea9b3bad1bebe94a81a186dc632a9cd10027a8e5d02f270ce59726498f07109b61bfc95294bc0497520fe1310ef36746b5af74c39ea50f
@@ -0,0 +1,4 @@
1
+ # canvas
2
+ CANVAS_API_HOST=<your canvas host>
3
+ CANVAS_API_TOKEN=<your canvas token>
4
+ CANVAS_ACCOUNT_ID=<your canvas account id>
data/.gitignore CHANGED
@@ -1,10 +1,9 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
- /.env/
8
+ .env
10
9
  /tmp/
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ japanda (0.1.3)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ domain_name (0.5.24)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ dotenv (2.0.2)
14
+ http-cookie (1.0.2)
15
+ domain_name (~> 0.5)
16
+ mime-types (2.6.2)
17
+ netrc (0.10.3)
18
+ rake (10.4.2)
19
+ rest-client (1.8.0)
20
+ http-cookie (>= 1.0.2, < 2.0)
21
+ mime-types (>= 1.16, < 3.0)
22
+ netrc (~> 0.7)
23
+ rspec (3.3.0)
24
+ rspec-core (~> 3.3.0)
25
+ rspec-expectations (~> 3.3.0)
26
+ rspec-mocks (~> 3.3.0)
27
+ rspec-core (3.3.2)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-expectations (3.3.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.3.0)
32
+ rspec-mocks (3.3.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.3.0)
35
+ rspec-support (3.3.0)
36
+ unf (0.1.4)
37
+ unf_ext
38
+ unf_ext (0.0.7.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (>= 1.0.0)
45
+ dotenv
46
+ japanda!
47
+ rake (~> 10.0)
48
+ rspec
49
+
50
+ BUNDLED WITH
51
+ 1.10.5
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Japanda
2
+ Japanda provides an object oriented wrapper and functional wrapper around canvas api
3
+ Disclaimer: For testing purposes only
2
4
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/japanda`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
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)
6
10
 
7
11
  ## Installation
8
12
 
@@ -21,14 +25,21 @@ Or install it yourself as:
21
25
  $ gem install japanda
22
26
 
23
27
  ## Usage
24
- Set a few enviroment variables:
28
+ Set a few enviroment variables( or use .env.example file)
25
29
 
26
30
  ```ruby
27
31
  export CANVAS_API_HOST=
28
32
  export CANVAS_API_TOKEN=
29
33
  export CANVAS_ACCOUNT_ID=
30
- export GALLERY_API_HOST=
31
- export GALLERY_API_TOKEN=
34
+ ```
35
+
36
+ ```ruby
37
+ new canvas course, uses default course_config
38
+ CanvasFactory::Course.new
39
+
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
32
43
  ```
33
44
 
34
45
  ## Development
@@ -43,6 +54,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
43
54
 
44
55
 
45
56
  ## License
46
-
57
+ For testing purposes only
47
58
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
-
@@ -4,36 +4,32 @@ $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 = "japanda"
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']
10
+ spec.email = ['snatarajan@instructure.com']
11
11
 
12
- spec.summary = %q{Library to create custom course, catalog.}
13
- spec.description = %q{Library to create custom course, catalog.}
14
- spec.homepage = "https://github.com/babababili/japanda"
15
- spec.license = "MIT"
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'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
21
21
  # else
22
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
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 = "exe"
26
+ spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_development_dependency "bundler", "~> 1.10.5"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "rspec"
33
- # spec.add_development_dependency "rest-client"
34
- # spec.add_development_dependency "deep_merge"
35
- spec.add_dependency "deep_merge"
36
- spec.add_dependency "rest-client"
37
- spec.add_dependency "dotenv"
28
+ spec.require_paths = ['lib']
38
29
 
30
+ spec.add_development_dependency 'bundler', '>= 1.0.0'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'dotenv'
34
+ spec.add_dependency 'rest-client'
39
35
  end
@@ -1,5 +1,6 @@
1
1
  require 'japanda/version'
2
2
  require 'securerandom'
3
+ require 'rest-client'
3
4
 
4
5
  module Japanda
5
6
  end
@@ -1,5 +1,4 @@
1
1
  require 'dotenv'
2
- require 'rest-client'
3
2
 
4
3
  module CanvasFactory
5
4
  Dotenv.load
@@ -9,4 +8,12 @@ module CanvasFactory
9
8
  content_type: 'application/json'
10
9
  }
11
10
  CANVAS_ACCOUNT_ID ||= ENV['CANVAS_ACCOUNT_ID']
11
+
12
+ def self.perform_post(end_point, body)
13
+ JSON.parse(RestClient.post end_point, body, CANVAS_AUTH_HEADER)
14
+ end
15
+
16
+ def self.perform_put(end_point, body)
17
+ JSON.parse(RestClient.put end_point, body, CANVAS_AUTH_HEADER)
18
+ end
12
19
  end
@@ -1,31 +1,25 @@
1
1
  # assignment class
2
2
  module CanvasFactory
3
3
  class Assignment
4
- attr_reader :assignments
4
+ attr_reader :id, :name, :course_id, :html_url, :grading_type, :published, :due_at, :created_at
5
5
 
6
- def add_assignments(opts)
7
- @assignments = []
8
- opts[:module][:assignment][:size].times do |i|
9
- @assignments << add_assignment(opts, i)
10
- end
6
+ def initialize(course_id, assignment_config = CanvasFactory::AssignmentConfig.new)
7
+ fail 'invalid course_id' if course_id.nil?
8
+ @course_id = course_id
9
+ create_assignment course_id, assignment_config
11
10
  end
12
11
 
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)
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)
15
+ @id = response['id']
16
+ @name = response['name']
17
+ @html_url = response['html_url']
18
+ @grading_type = response['grading_type']
19
+ @published = response['published']
20
+ @created_at = response['created_at']
21
+ @due_at = response['due_at']
22
+ self
29
23
  end
30
24
  end
31
25
  end
@@ -0,0 +1,27 @@
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,18 +1,16 @@
1
1
  # canvas course class
2
2
  module CanvasFactory
3
3
  class Course
4
- attr_reader :course_response, :course_id, :course_config, :course_code, :course_name
4
+ attr_reader :course_response, :course_id, :course_code, :course_name, :offer
5
5
 
6
- def initialize(course_config = nil)
7
- @course_config = course_config
8
- @course_config = CanvasFactory::CourseConfig.new if course_config.nil?
6
+ def initialize(course_config = CanvasFactory::CourseConfig.new)
7
+ @offer = course_config.offer
8
+ create_course course_config
9
9
  end
10
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)
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)
16
14
  @course_id = @course_response['id']
17
15
  @course_name = @course_response['name']
18
16
  @course_code = @course_response['course_code']
@@ -1,6 +1,6 @@
1
1
  module CanvasFactory
2
2
  class CourseConfig
3
- attr_accessor :course_request, :account_id, :name, :course_code, :start_at, :end_at, :offer
3
+ attr_accessor :account_id, :name, :course_code, :start_at, :end_at, :offer
4
4
 
5
5
  def initialize(opts = {})
6
6
  course_name_code = "auto#{SecureRandom.hex}"
@@ -12,18 +12,8 @@ module CanvasFactory
12
12
  @offer = opts[:offer] || true
13
13
  end
14
14
 
15
- # def initialize(account_id: CANVAS_ACCOUNT_ID, name: "auto", course_code: 'shouldbeunqiue', start_at: Time.now, end_at: Time.now + (30 * 24 * 60 * 60), offer = true)
16
- # course_name_code = "auto#{SecureRandom.hex}"
17
- # @account_id = account_id
18
- # @name = name
19
- # @course_code = course_code
20
- # @start_at = start_at
21
- # @end_at = end_at
22
- # @offer = offer
23
- # end
24
-
25
- def set_course_request
26
- @course_request = {
15
+ def request_body
16
+ {
27
17
  account_id: @account_id,
28
18
  course: {
29
19
  name: @name,
@@ -1,46 +1,58 @@
1
1
  # canvas module class
2
2
  module CanvasFactory
3
3
  class Module
4
- attr_reader :modules
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
5
7
 
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
8
+ def initialize(course_id, module_config = CanvasFactory::ModuleConfig.new)
9
+ @assignments = []
10
+ create_module course_id, module_config
11
+ publish_module
12
12
  end
13
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 }
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']
33
28
  end
34
29
 
35
- def update_module(course_id, module_id)
30
+ def publish_module
36
31
  body = {
37
32
  module: {
38
33
  published: true
39
34
  }
40
35
  }
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)
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']
39
+ end
40
+
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
46
+
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
44
56
  end
45
57
  end
46
58
  end
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,25 @@
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,22 +1,26 @@
1
1
  # canvas section class
2
2
  module CanvasFactory
3
3
  class Section
4
- attr_reader :sections
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
6
 
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
- }
7
+ def initialize(course_id, section_config = CanvasFactory::SectionConfig.new)
8
+ create_section course_id, section_config
9
+ end
14
10
 
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
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)
14
+ @course_id = response['course_id']
15
+ @id = response['id']
16
+ @name = response['name']
17
+ @end_at = response['end_at']
18
+ @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']
20
24
  end
21
25
  end
22
26
  end
@@ -0,0 +1,21 @@
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,19 +1,16 @@
1
1
  # canvas user class
2
2
  module CanvasFactory
3
3
  class User
4
- attr_reader :user_response, :user_response_id, :user_response_email_id, :user_short_name, :user_password
4
+ attr_reader :user_config, :user_response, :user_response_id,
5
+ :user_response_email_id, :user_short_name, :user_password
5
6
 
6
- def initialize(user_config = nil)
7
+ def initialize(user_config = CanvasFactory::UserConfig.new)
7
8
  @user_config = user_config
8
- @user_config = CanvasFactory::UserConfig.new if user_config.nil?
9
9
  end
10
10
 
11
11
  def create_learner_user
12
- @user_config.set_up_user_hash
13
- body = @user_config.config_user_hash
14
12
  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)
13
+ @user_response = CanvasFactory.perform_post(user_end_point, @user_config.user_request_body)
17
14
  @user_response_id = @user_response['id']
18
15
  @user_response_email_id = @user_response['login_id']
19
16
  @user_short_name = @user_config.short_name
@@ -22,10 +19,9 @@ module CanvasFactory
22
19
 
23
20
  def create_admin_user
24
21
  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
22
+ body = @user_config.admin_request_body(@user_response['id'].to_i)
23
+ admin_end_point = "#{CANVAS_API_V1}/accounts/#{CANVAS_ACCOUNT_ID}/admins"
24
+ CanvasFactory.perform_post(admin_end_point, body)
29
25
  end
30
26
  end
31
27
  end
@@ -1,7 +1,7 @@
1
1
  module CanvasFactory
2
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
3
+ attr_accessor :email_prefix, :password, :short_name, :terms_of_use, :send_confirmation,
4
+ :force_validations, :role_id, :email_id
5
5
 
6
6
  def initialize(opts = {})
7
7
  @email_prefix = opts[:email_prefix] || 'catauto'
@@ -14,8 +14,8 @@ module CanvasFactory
14
14
  @email_id = opts[:email_id] || "#{@email_prefix}#{SecureRandom.hex}@example.com"
15
15
  end
16
16
 
17
- def set_up_user_hash
18
- @config_user_hash = {
17
+ def user_request_body
18
+ {
19
19
  user: {
20
20
  name: @email_id,
21
21
  short_name: @short_name,
@@ -30,8 +30,8 @@ module CanvasFactory
30
30
  }
31
31
  end
32
32
 
33
- def set_up_admin_hash(id)
34
- @config_admin_hash = {
33
+ def admin_request_body(id)
34
+ {
35
35
  user_id: id,
36
36
  role_id: @role_id,
37
37
  send_confirmation: @send_confirmation
@@ -1,3 +1,3 @@
1
1
  module Japanda
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japanda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-16 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.10.5
19
+ version: 1.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.10.5
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: deep_merge
56
+ name: dotenv
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -80,33 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: dotenv
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- description: Library to create custom course, catalog.
83
+ description: Library to create custom course. wip.
98
84
  email:
99
85
  - snatarajan@instructure.com
100
86
  executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
90
+ - ".env.example"
104
91
  - ".gitignore"
105
92
  - ".rspec"
106
93
  - ".travis.yml"
107
94
  - CODE_OF_CONDUCT.md
108
95
  - Gemfile
109
- - LICENSE.txt
96
+ - Gemfile.lock
110
97
  - README.md
111
98
  - Rakefile
112
99
  - bin/console
@@ -115,19 +102,19 @@ files:
115
102
  - lib/japanda.rb
116
103
  - lib/japanda/canvas_factory.rb
117
104
  - lib/japanda/canvas_factory/assignment.rb
105
+ - lib/japanda/canvas_factory/assignment_config.rb
118
106
  - lib/japanda/canvas_factory/course.rb
119
107
  - lib/japanda/canvas_factory/course_config.rb
120
108
  - lib/japanda/canvas_factory/module.rb
121
- - lib/japanda/canvas_factory/module_item.rb
109
+ - lib/japanda/canvas_factory/module_config.rb
110
+ - lib/japanda/canvas_factory/module_item_config.rb
122
111
  - lib/japanda/canvas_factory/section.rb
112
+ - lib/japanda/canvas_factory/section_config.rb
123
113
  - lib/japanda/canvas_factory/user.rb
124
114
  - lib/japanda/canvas_factory/user_config.rb
125
- - lib/japanda/catalog_factory.rb
126
- - lib/japanda/catalog_factory/course_program.rb
127
115
  - lib/japanda/version.rb
128
- homepage: https://github.com/babababili/japanda
129
- licenses:
130
- - MIT
116
+ homepage:
117
+ licenses: []
131
118
  metadata: {}
132
119
  post_install_message:
133
120
  rdoc_options: []
@@ -148,5 +135,5 @@ rubyforge_project:
148
135
  rubygems_version: 2.4.5
149
136
  signing_key:
150
137
  specification_version: 4
151
- summary: Library to create custom course, catalog.
138
+ summary: Library to create custom course.
152
139
  test_files: []
@@ -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
- # 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,8 +0,0 @@
1
- require 'dotenv'
2
- require 'rest-client'
3
-
4
- module CatalogFactory
5
- Dotenv.load
6
- GALLERY_API_TOKEN ||= ENV['GALLERY_API_TOKEN']
7
- GALLERY_API_HOST = ENV['GALLERY_API_HOST']
8
- 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