module LtiXml class BasePlatform attr_accessor :parsed_request_url, :platform, :main_app def initialize(platform, full_request_url, main_app) @platform = platform @parsed_request_url = URI.parse(full_request_url) @main_app = main_app end # Override one of the following formatter methods in your individual platform class, or if you must, you can override # the whole xml method and do it all custom. def xml ims_tool_config add_domain add_privacy_level add_lti_properties add_lti_custom_params add_lti_options add_lti_nav add_environments #strip the launch url xml = @tc.to_xml xml = xml.sub(/.*<\/blti:launch_url>/, '') if PandaPal.lti_options[:launch_url] === false return xml end private def ims_tool_config ims_lti_config = {title: PandaPal.lti_options[:title]} if PandaPal.lti_options[:secure_launch_url].present? # Assumes full URL is provided ims_lti_config[:secure_launch_url] = PandaPal.lti_options[:secure_launch_url] elsif PandaPal.lti_options[:secure_launch_path].present? # Assumes path is provided ims_lti_config[:secure_launch_url] = "#{parsed_request_url.host}#{PandaPal.lti_options[:secure_launch_path]}" elsif PandaPal.lti_options[:launch_url].present? # Assumes full URL is provided ims_lti_config[:launch_url] = PandaPal.lti_options[:launch_url] elsif PandaPal.lti_options[:launch_path].present? # Assumes path is provided ims_lti_config[:launch_url] = "#{parsed_request_url.host}#{PandaPal.lti_options[:launch_path]}" else ims_lti_config[:launch_url] = parsed_request_url.host end @tc = IMS::LTI::ToolConfig.new(ims_lti_config) end def add_domain @tc.set_ext_param(platform, :domain, parsed_request_url.host) unless PandaPal.lti_properties.has_key?(:domain) end def add_privacy_level @tc.set_ext_param(platform, :privacy_level, 'public') unless PandaPal.lti_properties.has_key?(:public) end def add_lti_properties PandaPal.lti_properties.each do |k, v| @tc.set_ext_param(platform, k, v) end end def add_lti_custom_params PandaPal.lti_custom_params.each do |k, v| @tc.set_custom_param k, v end end def add_lti_options if PandaPal.lti_options.has_key?(:custom_fields) @tc.set_ext_param(platform, :custom_fields, PandaPal.lti_options[:custom_fields]) PandaPal.lti_options[:custom_fields].each do |k, v| @tc.set_ext_param(platform, k, v) end end end def add_lti_nav PandaPal.lti_paths.each do |k, v| @tc.set_ext_param(platform, k.to_sym, ext_params(v, k)) end end def add_environments @tc.set_ext_param(platform, :environments, PandaPal.lti_environments) end def ext_params(options, k) options = PandaPal::LaunchUrlHelpers.normalize_lti_launch_desc(options) options[:url] = PandaPal::LaunchUrlHelpers.absolute_launch_url( k.to_sym, host: parsed_request_url, launch_handler: :v1p0_launch_path, default_auto_launch: false ) options end end end