# canvas module class module CanvasFactory class Module attr_reader :modules def create_modules(opts) @modules = [] opts[:module][:size].times do @modules << create_module_add_item_publish(opts) end @modules end def create_module_add_item_publish(opts) body = { module: { name: "Course-Module-#{Time.now.to_i}", unlock_at: DateTime.now.iso8601, require_sequential_progress: true } } body.deep_merge!(opts[:module_options]) unless opts[:module_options].nil? m_item_end_point = "#{CANVAS_API_V1}/courses/#{opts[:course_id]}/modules" response = RestClient.post m_item_end_point, body, CANVAS_AUTH_HEADER m = JSON.parse(response) mi = CanvasFactory::ModuleItem.new mi.add_module_items(m['id'], opts) update_module opts[:course_id], m['id'] { module: m, module_items: mi.module_items } end def update_module(course_id, module_id) body = { module: { published: true } } m_p_end_point = "#{CANVAS_API_V1}/courses/#{course_id}/modules/#{module_id}" response = RestClient.put m_p_end_point, body, CANVAS_AUTH_HEADER JSON.parse(response) end end end