forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.rb
More file actions
42 lines (34 loc) · 1.04 KB
/
Copy pathlaunch.rb
File metadata and controls
42 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Lti
class Launch
attr_writer :analytics_id, :analytics_message_type
attr_accessor :link_text, :resource_url, :params, :launch_type, :tool_dimensions
def initialize(options = {})
@post_only = options[:post_only]
@tool_dimensions = options[:tool_dimensions] || {selection_height: '100%', selection_width: '100%'}
end
def resource_url
begin
url = URI(@resource_url)
if ['http', 'https'].include?(url.scheme)
@post_only ? @resource_url.split('?').first : @resource_url
else
'about:blank'
end
rescue
'about:blank'
end
end
def resource_path
url = URI.parse(resource_url)
url.path.blank? ? '/' : url.path
end
def analytics_id
@analytics_id || URI.parse(resource_url).host || 'unknown'
end
def analytics_message_type
@analytics_message_type ||
(params['lti_message_type'] == 'basic-lti-launch-request' ? 'tool_launch' : params['lti_message_type']) ||
'tool_launch'
end
end
end