Class: CanvasFactory::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/japanda/canvas_factory/module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(course_id, module_config = CanvasFactory::ModuleConfig.new) ⇒ Module

Returns a new instance of Module.



8
9
10
11
12
# File 'lib/japanda/canvas_factory/module.rb', line 8

def initialize(course_id, module_config = CanvasFactory::ModuleConfig.new)
  @assignments = []
  create_module course_id, module_config
  publish_module
end

Instance Attribute Details

#assignmentsObject (readonly)

Returns the value of attribute assignments.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def assignments
  @assignments
end

#course_idObject (readonly)

Returns the value of attribute course_id.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def course_id
  @course_id
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def id
  @id
end

#items_countObject (readonly)

Returns the value of attribute items_count.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def items_count
  @items_count
end

#items_urlObject (readonly)

Returns the value of attribute items_url.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def items_url
  @items_url
end

#moduleObject (readonly)

Returns the value of attribute module.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def name
  @name
end

#positionObject (readonly)

Returns the value of attribute position.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def position
  @position
end

#prerequisite_module_idsObject (readonly)

Returns the value of attribute prerequisite_module_ids.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def prerequisite_module_ids
  @prerequisite_module_ids
end

#publish_final_gradeObject (readonly)

Returns the value of attribute publish_final_grade.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def publish_final_grade
  @publish_final_grade
end

#publishedObject (readonly)

Returns the value of attribute published.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def published
  @published
end

#require_sequential_progressObject (readonly)

Returns the value of attribute require_sequential_progress.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def require_sequential_progress
  @require_sequential_progress
end

#unlock_atObject (readonly)

Returns the value of attribute unlock_at.



4
5
6
# File 'lib/japanda/canvas_factory/module.rb', line 4

def unlock_at
  @unlock_at
end

Instance Method Details

#add_assignment(title = 'module_assignment', assignment_config = CanvasFactory::AssignmentConfig.new) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/japanda/canvas_factory/module.rb', line 47

def add_assignment(title = 'module_assignment', assignment_config = CanvasFactory::AssignmentConfig.new)
  assignment = CanvasFactory::Assignment.new(@course_id, assignment_config)
  module_item_config = CanvasFactory::ModuleItemConfig.new(module_item_type: 'Assignment',
                                                           completion_type: 'must_view')
  module_item_config.content_id = assignment.id
  module_item_config.title = title
  add_module_item(module_item_config.request_body)
  @assignments << assignment
  assignment
end

#add_module_item(module_item_request) ⇒ Object



41
42
43
44
45
# File 'lib/japanda/canvas_factory/module.rb', line 41

def add_module_item(module_item_request)
  item_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@id}/items"
  CanvasFactory.perform_post(item_end_point, module_item_request)
  publish_module
end

#create_module(course_id, module_config) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/japanda/canvas_factory/module.rb', line 14

def create_module(course_id, module_config)
  m_item_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/modules"
  response = CanvasFactory.perform_post(m_item_end_point, module_config.request_body)
  @course_id = course_id
  @id = response['id']
  @name = response['name']
  @position = response['position']
  @unlock_at = response['unlock_at']
  @require_sequential_progress = response['require_sequential_progress']
  @publish_final_grade = response['publish_final_grade']
  @prerequisite_module_ids = response['prerequisite_module_ids']
  @published = response['published']
  @items_count = response['items_count']
  @items_url = response['items_url']
end

#publish_moduleObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/japanda/canvas_factory/module.rb', line 30

def publish_module
  body = {
    module: {
      published: true
    }
  }
  m_p_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/modules/#{@id}"
  response = CanvasFactory.perform_put(m_p_end_point, body)
  @published = response['published']
end