module CanvasCc::CC::CCHelper

Constants

ASSESSMENT_CC_QTI

file names/paths

ASSESSMENT_META
ASSESSMENT_NON_CC_FOLDER
ASSESSMENT_TYPE

Common Cartridge 1.1 (What Canvas exports)

ASSIGNMENT_GROUPS
ASSIGNMENT_SETTINGS
BASIC_LTI
BLTI_NAMESPACE
CANVAS_NAMESPACE
CANVAS_PLATFORM
CC_ASSIGNMENT_FOLDER
CC_EXTENSION
CC_WIKI_FOLDER
COURSE_SETTINGS
COURSE_SETTINGS_DIR
COURSE_TOKEN
DISCUSSION_TOPIC
EVENTS
EXTERNAL_FEEDS
EXTERNAL_TOOLS
FILES_META
GRADING_STANDARDS
IMS_DATE

IMS formats/types

IMS_DATETIME
LEARNING_OUTCOMES
LOR
MANIFEST
MEDIA_OBJECTS_FOLDER
MODULE_META
MOODLE_FILEBASE_TOKEN
MOODLE_SLASH_TOKEN
OBJECT_TOKEN

substitution tokens

QTI_ASSESSMENT_TYPE

QTI-only export

QTI_EXTENSION
QUESTION_BANK
RUBRICS
SYLLABUS
WEBCONTENT
WEB_CONTENT_TOKEN
WEB_RESOURCES_FOLDER
WIKI_FOLDER
WIKI_TOKEN
XSD_URI

Public Class Methods

convert_file_path_tokens(content) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 132
def self.convert_file_path_tokens(content)
  content.gsub(MOODLE_FILEBASE_TOKEN, WEB_CONTENT_TOKEN).gsub(MOODLE_SLASH_TOKEN, '/')
end
create_key(object, prepend="") click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 105
def self.create_key(object, prepend="")
  key = object.to_s
  "i" + Digest::MD5.hexdigest(prepend + key)
end
create_mod_key(mod) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 110
def self.create_mod_key(mod)
  create_key("#{mod.mod_type}_#{mod.id}", 'mod_')
end
create_resource_key(mod) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 114
def self.create_resource_key(mod)
  create_key("#{mod.mod_type}_#{mod.id}", 'resource_')
end
file_query_string(sub_path) click to toggle source

sub_path is the last part of a file url: /courses/1/files/1(/download) we want to handle any sort of extra params to the file url, both in the path components and the query string

# File lib/canvas_cc/cc/cc_helper.rb, line 268
def self.file_query_string(sub_path)
  return if sub_path.blank?
  qs = []
  uri = URI.parse(sub_path)
  unless uri.path == "/preview" # defaults to preview, so no qs added
    qs << "canvas_#{Rack::Utils.escape(uri.path[1..-1])}=1"
  end

  Rack::Utils.parse_query(uri.query).each do |k,v|
    qs << "canvas_qs_#{Rack::Utils.escape(k)}=#{Rack::Utils.escape(v)}"
  end

  return nil if qs.blank?
  "?#{qs.join("&")}"
end
file_slug(name) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 128
def self.file_slug(name)
  slug = name.downcase.gsub(/\s/, '-').gsub(/[^a-z0-9\.\-]/, '').gsub(/\.*$/, '')
end
ims_date(date=nil) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 118
def self.ims_date(date=nil)
  date ||= Time.now
  date.respond_to?(:utc) ? date.utc.strftime(IMS_DATE) : date.strftime(IMS_DATE)
end
ims_datetime(date=nil) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 123
def self.ims_datetime(date=nil)
  date ||= Time.now
  date.respond_to?(:utc) ? date.utc.strftime(IMS_DATETIME) : date.strftime(IMS_DATETIME)
end
media_object_info(obj, client = nil, flavor = nil) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 247
def self.media_object_info(obj, client = nil, flavor = nil)
  unless client
    client = Kaltura::ClientV3.new
    client.startSession(Kaltura::SessionType::ADMIN)
  end
  if flavor
    assets = client.flavorAssetGetByEntryId(obj.media_id)
    asset = assets.sort_by { |f| f[:size].to_i }.reverse.find { |f| f[:containerFormat] == flavor }
    asset ||= assets.first
  else
    asset = client.flavorAssetGetOriginalAsset(obj.media_id)
  end
  # we use the media_id as the export filename, since it is guaranteed to
  # be unique
  filename = "#{obj.media_id}.#{asset[:fileExt]}" if asset
  { :asset => asset, :filename => filename }
end

Public Instance Methods

convert_file_path_tokens(content) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 101
def convert_file_path_tokens(content)
  CCHelper.convert_file_path_tokens(content)
end
create_key(object, prepend="") click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 77
def create_key(object, prepend="")
  CCHelper.create_key(object, prepend)
end
create_mod_key(mod) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 81
def create_mod_key(mod)
  CCHelper.create_mod_key(mod)
end
create_resource_key(mod) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 85
def create_resource_key(mod)
  CCHelper.create_resource_key(mod)
end
file_slug(name) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 97
def file_slug(name)
  CCHelper.file_slug(name)
end
get_html_title_and_body(doc) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 151
def get_html_title_and_body(doc)
  title = get_node_val(doc, 'html head title')
  body = doc.at_css('html body').to_s.gsub(%r{</?body>}, '').strip
  [title, body]
end
get_html_title_and_body_and_id(doc) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 136
def get_html_title_and_body_and_id(doc)
  id = get_node_val(doc, 'html head meta[name=identifier] @content')
  get_html_title_and_body(doc) << id
end
get_html_title_and_body_and_meta_fields(doc) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 141
def get_html_title_and_body_and_meta_fields(doc)
  meta_fields = {}
  doc.css('html head meta').each do |meta_node|
    if key = meta_node['name']
      meta_fields[key] = meta_node['content']
    end
  end
  get_html_title_and_body(doc) << meta_fields
end
ims_date(date=nil) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 89
def ims_date(date=nil)
  CCHelper.ims_date(date)
end
ims_datetime(date=nil) click to toggle source
# File lib/canvas_cc/cc/cc_helper.rb, line 93
def ims_datetime(date=nil)
  CCHelper.ims_datetime(date)
end