github-to-canvas 0.0.36 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a277f51430eb482d411f25b2458151b29509ccf6b5d93ed37a161a43d2d198a0
4
- data.tar.gz: 345c466354af608b95cc34b5291d7b7966fdca89fba2cc4754efc2da7de868d3
3
+ metadata.gz: b5765e93e52076bb10758faf8ceba6b0d6c918f8667e5ccb7020b79e000d6292
4
+ data.tar.gz: d0cea8096a5ec9232073a336e6e7e8d911570f2b96215321281b266eb821ca00
5
5
  SHA512:
6
- metadata.gz: 7936e708b7afc380dbfe3bb9f1c1b1502193652048ffc24f0549473b2903f00a311776db0c7c458b8ff3465ae08dc8aa8e999c53c38b9727d6036385e129a621
7
- data.tar.gz: e8013f2e39e4f83be58e17f2ffdb2cce1dd00e28466b4663b3199b64cd78475b650bee6fab0988353f02138053c84569c6950641f59fe7cd0198222c56abbf97
6
+ metadata.gz: ff502c71c949c5b2f84d43bcb28e1dcbecb511f0f39c0201fedfcd367c16a1f7599f8eb4a1a50f15291564b24664e2071ac738752b7216c313db698e69929621
7
+ data.tar.gz: 87461ccffd44eae8dd8006332c1d5a26198a60f104eb58abe972baf27f8fbf1d9418c0e5da368f05963af28ed9f605363c6702a5321c7d7ce36e76c88a71a68d
@@ -21,6 +21,7 @@ OptionParser.new do |opts|
21
21
  github-to-canvas --create-lesson COURSE [--fis-links] [--remove-header-and-footer]
22
22
  github-to-canvas --align
23
23
  github-to-canvas --align [--branch BRANCH]
24
+ github-to-canvas --align [--only-content]
24
25
  github-to-canvas --align [--branch BRANCH] [--fis-links]
25
26
  github-to-canvas --version
26
27
 
@@ -86,6 +87,10 @@ OptionParser.new do |opts|
86
87
  "Removes top lesson header and any Learn.co specific footer links before converting to HTML") do |r|
87
88
  options[:remove_header_and_footer] = true
88
89
  end
90
+ opts.on("-o", "--only-content",
91
+ "For align functionality only - updates the HTML content of a lesson without changing the name") do |o|
92
+ options[:only_content] = true
93
+ end
89
94
 
90
95
  end.parse!
91
96
 
@@ -128,7 +133,8 @@ if options[:create_lesson]
128
133
  type: options[:type],
129
134
  save_to_github: !!options[:save_to_github],
130
135
  fis_links: !!options[:fis],
131
- remove_header_and_footer: !!options[:remove_header_and_footer])
136
+ remove_header_and_footer: !!options[:remove_header_and_footer]),
137
+ only_update_content: !!options[:only_content]
132
138
  end
133
139
 
134
140
  if options[:align]
@@ -141,5 +147,6 @@ if options[:align]
141
147
  type: options[:type],
142
148
  save_to_github: !!options[:save_to_github],
143
149
  fis_links: !!options[:fis],
144
- remove_header_and_footer: !!options[:remove_header_and_footer])
150
+ remove_header_and_footer: !!options[:remove_header_and_footer]),
151
+ only_update_content: !!options[:only_content]
145
152
  end
@@ -18,7 +18,8 @@ class GithubToCanvas
18
18
  type:"page",
19
19
  save_to_github:false,
20
20
  fis_links:false,
21
- remove_header_and_footer:false)
21
+ remove_header_and_footer:false,
22
+ only_update_content: false)
22
23
 
23
24
  if mode == 'version'
24
25
  puts VERSION
@@ -32,7 +33,7 @@ class GithubToCanvas
32
33
 
33
34
  if mode == 'align'
34
35
  puts "github-to-canvas will now align any existing Canvas lessons based on the current repo. NOTE: .canvas file must be present"
35
- UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
36
+ UpdateCanvasLesson.new(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
36
37
  end
37
38
  end
38
39
 
@@ -17,7 +17,7 @@ class CanvasInterface
17
17
  else
18
18
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s"
19
19
  end
20
- payload = self.build_payload(type, name, new_readme)
20
+ payload = self.build_payload(type, name, new_readme, false)
21
21
  begin
22
22
  RestClient.post(url, payload, headers={
23
23
  "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
@@ -28,13 +28,13 @@ class CanvasInterface
28
28
  end
29
29
  end
30
30
 
31
- def self.update_existing_lesson(course_id, id, type, name, new_readme, dry_run)
31
+ def self.update_existing_lesson(course_id, id, type, name, new_readme, only_update_content)
32
32
  if type == "discussion"
33
33
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}_topics/#{id}"
34
34
  else
35
35
  url = "#{ENV['CANVAS_API_PATH']}/courses/#{course_id}/#{type}s/#{id}"
36
36
  end
37
- payload = self.build_payload(type, name, new_readme)
37
+ payload = self.build_payload(type, name, new_readme, only_update_content)
38
38
  begin
39
39
  RestClient.put(url, payload, headers={
40
40
  "Authorization" => "Bearer #{ENV['CANVAS_API_KEY']}"
@@ -45,23 +45,39 @@ class CanvasInterface
45
45
  end
46
46
  end
47
47
 
48
- def self.build_payload(type, name, new_readme)
49
- if type == "assignment"
50
- payload = {
51
- 'assignment[name]' => name,
52
- 'assignment[description]' => new_readme
53
- }
54
- elsif type == "discussion"
55
- payload = {
56
- 'title' => name,
57
- 'message' => new_readme
58
- }
48
+ def self.build_payload(type, name, new_readme, only_update_content)
49
+ if only_update_content
50
+ if type == "assignment"
51
+ payload = {
52
+ 'assignment[description]' => new_readme
53
+ }
54
+ elsif type == "discussion"
55
+ payload = {
56
+ 'message' => new_readme
57
+ }
58
+ else
59
+ payload = {
60
+ 'wiki_page[body]' => new_readme
61
+ }
62
+ end
59
63
  else
60
- payload = {
61
- 'wiki_page[title]' => name,
62
- 'wiki_page[body]' => new_readme,
63
- 'wiki_page[editing_roles]' => "teachers"
64
- }
64
+ if type == "assignment"
65
+ payload = {
66
+ 'assignment[name]' => name,
67
+ 'assignment[description]' => new_readme
68
+ }
69
+ elsif type == "discussion"
70
+ payload = {
71
+ 'title' => name,
72
+ 'message' => new_readme
73
+ }
74
+ else
75
+ payload = {
76
+ 'wiki_page[title]' => name,
77
+ 'wiki_page[body]' => new_readme,
78
+ 'wiki_page[editing_roles]' => "teachers"
79
+ }
80
+ end
65
81
  end
66
82
  end
67
83
  end
@@ -1,6 +1,6 @@
1
1
  class UpdateCanvasLesson
2
2
 
3
- def initialize(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
3
+ def initialize(filepath, file_to_convert, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
4
4
  name = name.split(/[- _]/).map(&:capitalize).join(' ')
5
5
  begin
6
6
  markdown = File.read("#{filepath}/#{file_to_convert}")
@@ -8,10 +8,10 @@ class UpdateCanvasLesson
8
8
  puts "#{file_to_convert} not found in current directory. Exiting..."
9
9
  abort
10
10
  end
11
- update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
11
+ update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
12
12
  end
13
13
 
14
- def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer)
14
+ def update_canvas_lesson(markdown, filepath, branch, name, type, save_to_github, fis_links, remove_header_and_footer, only_update_content)
15
15
  GithubInterface.get_updated_repo(filepath, branch)
16
16
  new_html = RepositoryConverter.convert(filepath, markdown, branch, remove_header_and_footer)
17
17
  if fis_links
@@ -19,7 +19,7 @@ class UpdateCanvasLesson
19
19
  end
20
20
  canvas_data = CanvasDotfile.read_canvas_data
21
21
  canvas_data[:lessons].each { |lesson|
22
- response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, save_to_github)
22
+ response = CanvasInterface.update_existing_lesson(lesson[:course_id], lesson[:id], lesson[:type], name, new_html, only_update_content)
23
23
  # puts "Canvas lesson created. Lesson available at #{response['html_url']}."
24
24
  }
25
25
  end
@@ -1,3 +1,3 @@
1
1
  class GithubToCanvas
2
- VERSION = "0.0.36"
2
+ VERSION = "0.0.37"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-to-canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxwellbenton