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.18"
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# 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 'canvas_copy' CanvasInterface.copy_lesson() 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' if (![:branch]) [:branch] = 'master' end html = RepositoryConverter.remote_file_conversion() html = RepositoryConverter.adjust_converted_html(, html) name = [:name] ? [:name] : RepositoryInterface.get_name([:filepath], html) puts name response = CanvasInterface.create_lesson(, name, html) puts "Canvas lesson created. Lesson available at #{response['html_url']}" when 'github_align' if (![:branch]) [:branch] = 'master' end 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 } } when 'csv_build' if ![:course_id] course_info = { name: "CSV Build Test", course_code: "CSV-TEST" } created_course_info = CanvasInterface.create_course(course_info) puts "Course created - #{created_course_info["id"]}" puts "Make sure to add yourself as a teacher to this course before continuing, then press Enter/Return" input = gets [:course_id] = created_course_info["id"] else puts "Adding to course #{[:course_id]}" end csv_data = CSV.read([:file_to_convert]) created_module_info = { "id" => "", "name" => "" } csv_data.each { |lesson| # lesson[0] == repo # lesson[1] == name # lesson[2] == module # lesson[3] == type # lesson[4] == yes/no contains HTML module_info = { name: lesson[2] } if created_module_info["name"] != module_info[:name] created_module_info = CanvasInterface.create_module([:course_id], module_info) puts "New module created - #{created_module_info["id"]} - #{created_module_info["name"]}" end [:filepath] = lesson[0] [:name] = lesson[1] [:type] = lesson[3] [:branch] = "master" if ![:branch] html = RepositoryConverter.remote_file_conversion() html = RepositoryConverter.adjust_converted_html(, html) created_lesson_info = CanvasInterface.create_lesson(, lesson[1], html) created_lesson_info["page_url"] = created_lesson_info["url"] if !created_lesson_info["page_url"] created_lesson_info["id"] = created_lesson_info["page_url"] if !created_lesson_info["id"] created_lesson_info["type"] = [:type] puts "Creating lesson - #{[:name]}" response = CanvasInterface.add_to_module([:course_id], created_module_info, created_lesson_info) } when 'csv_align' csv_data = CSV.read([:file_to_convert]) created_module_info = { "id" => "", "name" => "" } csv_data.each { |lesson| # lesson[0] == repo # lesson[1] == name # lesson[2] == module # lesson[3] == type # lesson[4] == yes/no contains HTML # lesson[5] == lesson id # lesson[6] == course id module_info = { name: lesson[2] } [:filepath] = lesson[0] [:name] = lesson[1] [:type] = lesson[3] [:id] = lesson[5] [:course_id] = lesson[6] [:branch] = "master" if ![:branch] html = RepositoryConverter.remote_file_conversion() html = RepositoryConverter.adjust_converted_html(, html) updated_lesson_info = CanvasInterface.update_existing_lesson(, lesson[1], html) updated_lesson_info["page_url"] = updated_lesson_info["url"] if !updated_lesson_info["page_url"] updated_lesson_info["id"] = updated_lesson_info["page_url"] if !updated_lesson_info["id"] updated_lesson_info["type"] = [:type] puts "Updating lesson - #{[:name]}" } else puts VERSION end end |