Skip to content

Commit

Permalink
Clean up canvas_course code
Browse files Browse the repository at this point in the history
  • Loading branch information
bfcoder committed Dec 12, 2016
1 parent 5e7b6b2 commit 7fe4f99
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/blacklight/canvas_course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def self.client
def self.from_metadata(metadata)
course_name = metadata[:name] || metadata[:title]
courses = client.list_active_courses_in_account(:self)
course = courses.detect { |c| c.name == course_name } ||
canvas_course = courses.detect { |course| course.name == course_name } ||
client.create_new_course(
:self,
course: {
name: metadata[:name],
name: course_name,
},
)
CanvasCourse.new(metadata, course)
CanvasCourse.new(metadata, canvas_course)
end

##
Expand All @@ -72,13 +72,18 @@ def upload_content(filename)
pre_attachment: { name: name },
)

puts "Uploading: #{name}"
upload_to_s3(migration, filename)
puts "Done uploading: #{name}"
end

def upload_to_s3(migration, filename)
# Attach the file to the S3 auth
pre_attachment = migration.pre_attachment
upload_url = pre_attachment["upload_url"]
upload_params = pre_attachment["upload_params"]
upload_params[:file] = File.new(filename, "rb")

puts "Uploading: #{name}"
# Post to S3
RestClient.post(
upload_url,
Expand All @@ -91,7 +96,6 @@ def upload_content(filename)
Authorization: "Bearer #{Blacklight.canvas_token}",
)
end
puts "Done uploading: #{name}"
end
end
end

0 comments on commit 7fe4f99

Please sign in to comment.