Class: CanvasDotfile
- Inherits:
-
Object
- Object
- CanvasDotfile
- Defined in:
- lib/github-to-canvas/canvas_dotfile.rb
Class Method Summary collapse
- .create_assignment_data(response, course, type) ⇒ Object
- .create_canvas_dotfile(filepath, canvas_data) ⇒ Object
- .create_page_data(response, course, type) ⇒ Object
- .exists? ⇒ Boolean
- .read_canvas_data ⇒ Object
- .update_assignment_data(response, course, type) ⇒ Object
- .update_or_create(options, response) ⇒ Object
- .update_page_data(response, course, type) ⇒ Object
Class Method Details
.create_assignment_data(response, course, type) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 52 def self.create_assignment_data(response, course, type) { lessons: [ { id: response['id'], course_id: course.to_i, canvas_url: response['html_url'], type: type } ] } end |
.create_canvas_dotfile(filepath, canvas_data) ⇒ Object
25 26 27 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 25 def self.create_canvas_dotfile(filepath, canvas_data) File.write("#{filepath}/.canvas", canvas_data.to_yaml) end |
.create_page_data(response, course, type) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 79 def self.create_page_data(response, course, type) { lessons: [ { id: response['page_id'], course_id: course.to_i, canvas_url: response['html_url'], type: type } ] } end |
.exists? ⇒ Boolean
4 5 6 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 4 def self.exists? File.file?(".canvas") end |
.read_canvas_data ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 29 def self.read_canvas_data if File.file?(".canvas") YAML.load(File.read(".canvas")) else puts 'ERROR: Align functionalty requires .canvas file to be present' abort end end |
.update_assignment_data(response, course, type) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 38 def self.update_assignment_data(response, course, type) canvas_data = YAML.load(File.read(".canvas")) if canvas_data[:lessons].none? { |lesson| lesson[:id] == response['id'] && lesson[:course_id] == course.to_i && lesson[:canvas_url] == response['html_url']} lesson_data = { id: response['id'], course_id: course.to_i, canvas_url: response['html_url'], type: type } canvas_data[:lessons] << lesson_data end canvas_data end |
.update_or_create(options, response) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 8 def self.update_or_create(, response) if self.exists? if [:type] == "assignment" || [:type] == "discussion" canvas_data = self.update_assignment_data(response, [:course_id], [:type]) else canvas_data = self.update_page_data(response, [:course_id], [:type]) end else if [:type] == "assignment" || [:type] == "discussion" canvas_data = self.create_assignment_data(response, [:course_id], [:type]) else canvas_data = self.create_page_data(response, [:course_id], [:type]) end end self.create_canvas_dotfile([:filepath], canvas_data) end |
.update_page_data(response, course, type) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/github-to-canvas/canvas_dotfile.rb', line 65 def self.update_page_data(response, course, type) canvas_data = YAML.load(File.read(".canvas")) if canvas_data[:lessons].none? { |lesson| lesson[:id] == response['page_id'] && lesson[:course_id] == course.to_i && lesson[:canvas_url] == response['html_url']} lesson_data = { id: response['page_id'], course_id: course.to_i, canvas_url: response['html_url'], type: type } canvas_data[:lessons] << lesson_data end canvas_data end |