Class: GithubToCanvas
- Inherits:
-
Object
- Object
- GithubToCanvas
- Defined in:
- lib/github-to-canvas.rb,
lib/github-to-canvas/version.rb
Constant Summary collapse
- VERSION =
"0.1.4"
Instance Method Summary collapse
-
#initialize(options) ⇒ GithubToCanvas
constructor
A new instance of GithubToCanvas.
Constructor Details
#initialize(options) ⇒ GithubToCanvas
Returns a new instance of GithubToCanvas.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/github-to-canvas.rb', line 17 def initialize() case [:mode] when 'version' puts VERSION when 'query' CanvasInterface.get_course_info([:course_id], [:id]) when 'map' CanvasInterface.map_course_info() when 'csv' CanvasInterface.csv([:file_to_convert]) when 'canvas_read' puts CanvasInterface.read_lesson([:filepath]) when 'github_read' html = RepositoryConverter.remote_file_conversion() puts RepositoryConverter.adjust_converted_html(, html) when 'create' # used with a local repo html = RepositoryConverter.local_file_conversion() name = RepositoryInterface.get_name([:filepath], html) html = RepositoryConverter.adjust_converted_html(, html) response = CanvasInterface.create_lesson(, name, html) RepositoryInterface.local_repo_post_submission(, response) puts "Canvas lesson created. Lesson available at #{response['html_url']}" when 'align' # used with a local repo html = RepositoryConverter.local_file_conversion() name = [:name] ? [:name] : RepositoryInterface.get_name([:filepath], html) html = RepositoryConverter.adjust_converted_html(, html) CanvasInterface.(, name, html) when 'github_create' html = RepositoryConverter.remote_file_conversion() name = [:name] ? [:name] : RepositoryInterface.get_name([:filepath], html) html = RepositoryConverter.adjust_converted_html(, html) response = CanvasInterface.create_lesson(, name, html) puts "Canvas lesson created. Lesson available at #{response['html_url']}" when 'github_align' html = RepositoryConverter.remote_file_conversion() name = [:name] ? [:name] : RepositoryInterface.get_name([:filepath], html) html = RepositoryConverter.adjust_converted_html(, html) response = CanvasInterface.update_existing_lesson(, name, html) puts "Canvas lesson updated. Lesson available at #{response['html_url']}" when 'build_course' course_yaml = YAML.load(File.read([:file_to_convert])) # Create Course created_course_info = CanvasInterface.create_course(course_yaml) puts "Course created - #{created_course_info["id"]}" course_yaml[:modules].each { |module_info| # Create each module created_module_info = CanvasInterface.create_module(created_course_info["id"], module_info) puts "Module created - #{created_module_info['name']}" module_info[:lessons].each { |lesson| # Create each lesson [:type] = lesson["type"].downcase [:course_id] = created_course_info["id"] [:filepath] = lesson["repository"] html = RepositoryConverter.remote_file_conversion() # Add each lesson to it's module html = RepositoryConverter.adjust_converted_html(, html) created_lesson_info = CanvasInterface.create_lesson(, lesson["title"], html) lesson = lesson.merge(created_lesson_info) lesson["page_url"] = lesson["url"] if !lesson["page_url"] response = CanvasInterface.add_to_module(created_course_info["id"], created_module_info, lesson) puts "Lesson added to #{created_module_info['name']} - #{lesson['title']}" sleep(1) } } when 'add_to_course' course_yaml = YAML.load(File.read([:file_to_convert])) course_yaml[:modules].each { |module_info| # Create each module created_module_info = CanvasInterface.create_module([:course_id], module_info) puts "Module created - #{created_module_info['name']}" module_info[:lessons].each { |lesson| # Create each lesson [:type] = lesson["type"].downcase [:filepath] = lesson["repository"] html = RepositoryConverter.remote_file_conversion() # Add each lesson to it's module html = RepositoryConverter.adjust_converted_html(, html) created_lesson_info = CanvasInterface.create_lesson(, lesson["title"], html) lesson = lesson.merge(created_lesson_info) response = CanvasInterface.add_to_module([:course_id], created_module_info, lesson) puts "Lesson added to #{created_module_info['name']} - #{lesson['title']}" sleep(1) } } when 'update_course_lessons' course_yaml = YAML.load(File.read([:file_to_convert])) [:course_id] = course_yaml[:id] course_yaml[:modules].each { |module_info| puts "Updating #{module_info[:name]}" module_info[:lessons].each { |lesson| if lesson["repository"] == "" puts "No repository found for #{lesson['title']}" next end [:id] = lesson['id'] [:type] = lesson["type"].downcase [:filepath] = lesson["repository"] [:branch] = 'master' html = RepositoryConverter.remote_file_conversion() html = RepositoryConverter.adjust_converted_html(, html) created_lesson_info = CanvasInterface.update_existing_lesson(, lesson["title"], html) lesson = lesson.merge(created_lesson_info) puts "Lesson updated - #{lesson['title']}" sleep(1) } } when 'clone_course' course_yaml = YAML.load(File.read([:file_to_convert])) new_dir = "#{course_yaml[:name].downcase.gsub(' ','-')}" cmd = "mkdir #{new_dir}" `#{cmd}` course_yaml[:modules].each { |module_info| puts "Cloning #{module_info[:name]}" module_info[:lessons].each { |lesson| if lesson["repository"] == "" puts "No repository found for #{lesson['title']}" next else cmd = "git clone #{lesson['repository']}" puts cmd GithubInterface.cd_into_and(new_dir, cmd) end } } else puts VERSION end end |