Last active
September 10, 2015 19:20
-
-
Save adam-phillipps/d379bf9c23e258a42b4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
opts = {:name=>"catauto", :module=>{:size=>1, :assignment=>{:size=>2}}, :section=>{:size=>3}, :course_id=>7682} | |
******************************* | |
CanvasFactory::Course | |
****************************** | |
def initialize(opts = {}) | |
@options = { | |
name: 'catauto', | |
module: { | |
size: 1, | |
assignment: | |
{ size: 2 } | |
}, | |
section: { size: 3 } | |
}.update(opts) | |
add_a_course @options | |
add_modules(@options) | |
add_sections(@options) | |
end | |
********************** | |
********************** | |
*********************** | |
CanvasFactory::Module | |
*********************** | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
current_opts = {:name=>"catauto", :module=>{:size=>1, :assignment=>{:size=>2}}, :section=>{:size=>3}, :course_id=>7682} | |
suggested_op = {:name=>"catauto", :module=>{:size=>2}, :assignment=>{:size=>2}, :section=>{:size=>2}, :course_id=>7682} | |
note the nesting in the current model and the flat set up in the suggested model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
opts = {:module=>{size: 2, sequential: true}, :assignment=>{:size=>2}, :section=>{:size=>2},:course_id=>76882} | |
******************************* | |
CanvasFactory::Course | |
****************************** | |
def initialize(opts = {}) | |
@options = { | |
name: 'catauto', | |
module: { | |
size: 1, | |
assignment: | |
{ size: 1 }.update(opts[:assignment] | |
}.update(opts[:module]), | |
section: { size: 1}.update(opts[:section]) | |
} | |
add_a_course @options | |
add_modules(@options) | |
add_sections(@options) | |
end | |
********************** | |
********************** | |
************************** | |
CanvasFactory::Module | |
************************* | |
def create_modules(opts) | |
@modules = [] | |
number_of_modules = (opts[:module].delete(:size) || 1) | |
number_of_modules.times do | |
@modules << create_module_add_item_publish(opts) | |
end | |
@modules | |
end | |
def create_module_add_item_publish(opts) | |
number_of_modules = opts[:modules].delete(:size) # removes the :size key for it causes sadness in API calls | |
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[:modules].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 | |
********************** | |
********************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment