ims-lti 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ims/lti/extensions.rb +2 -0
- data/lib/ims/lti/extensions/canvas.rb +109 -0
- data/lib/ims/lti/extensions/content.rb +209 -0
- metadata +5 -2
data/lib/ims/lti/extensions.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
module IMS::LTI
|
2
|
+
module Extensions
|
3
|
+
# Module that adds Canvas specific LTI extensions
|
4
|
+
#
|
5
|
+
# It adds convenience methods for generating common canvas use case LTI configurations
|
6
|
+
#
|
7
|
+
# == Usage
|
8
|
+
# To generate an XML configuration:
|
9
|
+
#
|
10
|
+
# # Create a config object and set some options
|
11
|
+
# tc = IMS::LTI::ToolConfig.new(:title => "Example Sinatra Tool Provider", :launch_url => url)
|
12
|
+
# tc.description = "This example LTI Tool Provider supports LIS Outcome pass-back."
|
13
|
+
#
|
14
|
+
# # Extend the Canvas Tool config and add canvas related extensions
|
15
|
+
# tc.extend IMS::LTI::Extensions::Canvas::ToolConfig
|
16
|
+
# tc.homework_submission! 'http://someplace.com/homework', 'Find Homework'
|
17
|
+
#
|
18
|
+
# # generate the XML
|
19
|
+
# tc.to_xml
|
20
|
+
#
|
21
|
+
# Or to create a config object from an XML String:
|
22
|
+
#
|
23
|
+
# tc = IMS::LTI::ToolConfig.create_from_xml(xml)
|
24
|
+
|
25
|
+
module Canvas
|
26
|
+
module ToolConfig
|
27
|
+
PLATFORM = 'canvas.instructure.com'
|
28
|
+
|
29
|
+
# Canvas extension defaults
|
30
|
+
# These properties will cascade down to any options that are configured
|
31
|
+
|
32
|
+
def canvas_privacy_public!()
|
33
|
+
set_ext_param(PLATFORM, :privacy_level, 'public')
|
34
|
+
end
|
35
|
+
|
36
|
+
def canvas_privacy_name_only!()
|
37
|
+
set_ext_param(PLATFORM, :privacy_level, 'name_only')
|
38
|
+
end
|
39
|
+
|
40
|
+
def canvas_privacy_anonymous!()
|
41
|
+
set_ext_param(PLATFORM, :privacy_level, 'anonymous')
|
42
|
+
end
|
43
|
+
|
44
|
+
def canvas_domain!(domain)
|
45
|
+
set_ext_param(PLATFORM, :domain, domain)
|
46
|
+
end
|
47
|
+
|
48
|
+
def canvas_text!(text)
|
49
|
+
set_ext_param(PLATFORM, :text, text)
|
50
|
+
end
|
51
|
+
|
52
|
+
def canvas_icon_url!(icon_url)
|
53
|
+
set_ext_param(PLATFORM, :icon_url, icon_url)
|
54
|
+
end
|
55
|
+
|
56
|
+
def canvas_selector_dimensions!(width, height)
|
57
|
+
set_ext_param(PLATFORM, :selection_width, width)
|
58
|
+
set_ext_param(PLATFORM, :selection_height, height)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Canvas options
|
62
|
+
# These configure canvas to expose the tool in various locations. Any properties that are set
|
63
|
+
# at this level will override the defaults for this launch of the tool
|
64
|
+
|
65
|
+
# Enables homework submissions via the tool
|
66
|
+
# Valid properties are url, text, selection_width, selection_height, enabled
|
67
|
+
def canvas_homework_submission!(params = {})
|
68
|
+
set_ext_param(PLATFORM, :homework_submission, params)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Adds the tool to canvas' rich text editor
|
72
|
+
# Valid properties are url, icon_url, text, selection_width, selection_height, enabled
|
73
|
+
def canvas_editor_button!(params = {})
|
74
|
+
set_ext_param(PLATFORM, :editor_button, params)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Adds the tool to canvas' rich text editor
|
78
|
+
# Valid properties are url, icon_url, text, selection_width, selection_height, enabled
|
79
|
+
def canvas_resource_selection!(params = {})
|
80
|
+
set_ext_param(PLATFORM, :resource_selection, params)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Adds the tool to account level navigation in canvas
|
84
|
+
# Valid properties are url, text, enabled
|
85
|
+
def canvas_account_navigation!(params = {})
|
86
|
+
set_ext_param(PLATFORM, :account_navigation, params)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Adds the tool to course level navigation in canvas
|
90
|
+
# Valid properties are url, text, visibility, default, enabled
|
91
|
+
# Visibility describes who will see the navigation element. Possible values are "admins", "members", and nil
|
92
|
+
# Default determines if it is on or off by default. Possible values are "admins", "members", and nil
|
93
|
+
def canvas_course_navigation!(params = {})
|
94
|
+
set_ext_param(PLATFORM, :course_navigation, params)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Adds the tool to user level navigation in canvas
|
98
|
+
# Valid properties are url, text, enabled
|
99
|
+
def canvas_user_navigation!(params = {})
|
100
|
+
set_ext_param(PLATFORM, :user_navigation, params)
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_canvas_param(param_key)
|
104
|
+
get_ext_param PLATFORM, param_key
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
module IMS::LTI
|
2
|
+
module Extensions
|
3
|
+
|
4
|
+
# An LTI extension that adds support for content back to the consumer
|
5
|
+
#
|
6
|
+
# # Initialize TP object with OAuth creds and post parameters
|
7
|
+
# provider = IMS::LTI::ToolProvider.new(consumer_key, consumer_secret, params)
|
8
|
+
# # add extension
|
9
|
+
# provider.extend IMS::LTI::Extensions::Content::ToolProvider
|
10
|
+
#
|
11
|
+
# If the tool was launched as an content request and it supports the content extension
|
12
|
+
# you can redirect the user to the tool consumer using the return url helper methods.
|
13
|
+
# The tool consumer is then responsible for consuming the content.
|
14
|
+
#
|
15
|
+
# #Check if a certain response type is available
|
16
|
+
# if provider.accepts_url? do
|
17
|
+
# #Generate the URL for the user
|
18
|
+
# redirect provider.url_content_return_url(url)
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
module Content
|
22
|
+
module ToolProvider
|
23
|
+
include IMS::LTI::Extensions::ExtensionBase
|
24
|
+
include Base
|
25
|
+
|
26
|
+
# a list of the supported outcome data types
|
27
|
+
def accepted_content_types
|
28
|
+
return @content_types if @content_types
|
29
|
+
@content_types = []
|
30
|
+
if val = @ext_params["content_return_types"]
|
31
|
+
@content_types = val.split(',').map {|i| i.to_sym}
|
32
|
+
end
|
33
|
+
|
34
|
+
@content_types
|
35
|
+
end
|
36
|
+
|
37
|
+
def accepted_file_extensions
|
38
|
+
return @file_extensions if @file_extensions
|
39
|
+
@file_extensions = []
|
40
|
+
if val = @ext_params["content_file_extensions"]
|
41
|
+
@file_extensions = val.split(',').map {|i| i.downcase.strip}
|
42
|
+
end
|
43
|
+
|
44
|
+
@file_extensions
|
45
|
+
end
|
46
|
+
|
47
|
+
def accepts_file?(file_name = nil)
|
48
|
+
accepted_content_types.include?(:file) &&
|
49
|
+
( file_name.nil? ||
|
50
|
+
accepted_file_extensions.empty? ||
|
51
|
+
accepted_file_extensions.any?{|ext| file_name.downcase[/#{ext}$/]} )
|
52
|
+
end
|
53
|
+
|
54
|
+
def accepts_url?
|
55
|
+
accepted_content_types.include?(:url)
|
56
|
+
end
|
57
|
+
|
58
|
+
def accepts_lti_launch_url?
|
59
|
+
accepted_content_types.include?(:lti_launch_url)
|
60
|
+
end
|
61
|
+
|
62
|
+
def accepts_image_url?
|
63
|
+
accepted_content_types.include?(:image_url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def accepts_iframe?
|
67
|
+
accepted_content_types.include?(:iframe)
|
68
|
+
end
|
69
|
+
|
70
|
+
def accepts_oembed?
|
71
|
+
accepted_content_types.include?(:oembed)
|
72
|
+
end
|
73
|
+
|
74
|
+
def content_intended_use
|
75
|
+
@ext_params["content_intended_use"].to_sym if @ext_params["content_intended_use"]
|
76
|
+
end
|
77
|
+
|
78
|
+
# check if the content extension is supported
|
79
|
+
def accepts_content?
|
80
|
+
!!@ext_params["content_return_types"]
|
81
|
+
end
|
82
|
+
|
83
|
+
# check if the consumer accepts a given type of content
|
84
|
+
def accepts_content_type?(content_type)
|
85
|
+
accepted_content_types.include? content_type.to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
#check the use of the content
|
89
|
+
def is_content_for? (intended_use)
|
90
|
+
content_intended_use == intended_use
|
91
|
+
end
|
92
|
+
|
93
|
+
def content_return_url
|
94
|
+
@ext_params["content_return_url"]
|
95
|
+
end
|
96
|
+
|
97
|
+
#generates the return url for file submissions
|
98
|
+
def file_content_return_url(url, text, content_type = nil)
|
99
|
+
url = CGI::escape(url)
|
100
|
+
text = CGI::escape(text)
|
101
|
+
content_type = CGI::escape(content_type) if content_type
|
102
|
+
|
103
|
+
return_url = "#{content_return_url}?return_type=file&url=#{url}&text=#{text}"
|
104
|
+
return_url = "#{return_url}&content_type=#{content_type}" if content_type
|
105
|
+
|
106
|
+
return return_url
|
107
|
+
end
|
108
|
+
|
109
|
+
#generates the return url for url submissions
|
110
|
+
def url_content_return_url(url, title = nil, text = 'link', target = '_blank')
|
111
|
+
url = CGI::escape(url)
|
112
|
+
text = CGI::escape(text)
|
113
|
+
target = CGI::escape(target)
|
114
|
+
|
115
|
+
return_url = "#{content_return_url}?return_type=url&url=#{url}&text=#{text}&target=#{target}"
|
116
|
+
return_url = "#{return_url}&title=#{CGI::escape(title)}" if title
|
117
|
+
|
118
|
+
return return_url
|
119
|
+
end
|
120
|
+
|
121
|
+
#generates the return url for lti launch submissions
|
122
|
+
def lti_launch_content_return_url(url, text='link', title=nil)
|
123
|
+
url = CGI::escape(url)
|
124
|
+
text = CGI::escape(text)
|
125
|
+
|
126
|
+
return_url = "#{content_return_url}?return_type=lti_launch_url&url=#{url}&text=#{text}"
|
127
|
+
return_url = "#{return_url}&title=#{CGI::escape(title)}" if title
|
128
|
+
|
129
|
+
return return_url
|
130
|
+
end
|
131
|
+
|
132
|
+
#generates the return url for image submissions
|
133
|
+
def image_content_return_url(url, width, height, alt = '')
|
134
|
+
url = CGI::escape(url)
|
135
|
+
width = CGI::escape(width.to_s)
|
136
|
+
height = CGI::escape(height.to_s)
|
137
|
+
alt = CGI::escape(alt)
|
138
|
+
|
139
|
+
"#{content_return_url}?return_type=image_url&url=#{url}&width=#{width}&height=#{height}&alt=#{alt}"
|
140
|
+
end
|
141
|
+
|
142
|
+
#generates the return url for iframe submissions
|
143
|
+
def iframe_content_return_url(url, width, height, title = nil)
|
144
|
+
url = CGI::escape(url)
|
145
|
+
width = CGI::escape(width.to_s)
|
146
|
+
height = CGI::escape(height.to_s)
|
147
|
+
|
148
|
+
return_url = "#{content_return_url}?return_type=iframe&url=#{url}&width=#{width}&height=#{height}"
|
149
|
+
return_url = "#{return_url}&title=#{CGI::escape(title)}" if title
|
150
|
+
|
151
|
+
return return_url
|
152
|
+
end
|
153
|
+
|
154
|
+
#generates the return url for oembed submissions
|
155
|
+
def oembed_content_return_url(url, endpoint)
|
156
|
+
url = CGI::escape(url)
|
157
|
+
endpoint = CGI::escape(endpoint)
|
158
|
+
|
159
|
+
"#{content_return_url}?return_type=oembed&url=#{url}&endpoint=#{endpoint}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
module ToolConsumer
|
164
|
+
include IMS::LTI::Extensions::ExtensionBase
|
165
|
+
include Base
|
166
|
+
|
167
|
+
# a list of the content types accepted
|
168
|
+
#
|
169
|
+
# tc.add_content_return_types=(['url', 'text'])
|
170
|
+
# tc.add_content_return_types=("url,text")
|
171
|
+
def content_return_types=(val)
|
172
|
+
val = val.join(',') if val.is_a? Array
|
173
|
+
set_ext_param('content_return_types', val)
|
174
|
+
end
|
175
|
+
|
176
|
+
# a comma-separated string of the supported outcome data types
|
177
|
+
def content_return_types
|
178
|
+
get_ext_param('content_return_types')
|
179
|
+
end
|
180
|
+
|
181
|
+
def content_intended_use=(val)
|
182
|
+
set_ext_param('content_intended_use', val)
|
183
|
+
end
|
184
|
+
|
185
|
+
def content_intended_use
|
186
|
+
get_ext_param('content_intended_use')
|
187
|
+
end
|
188
|
+
|
189
|
+
# convenience method for setting support for homework content
|
190
|
+
def support_homework_content!
|
191
|
+
self.content_intended_use = 'homework'
|
192
|
+
self.content_return_types = 'file,url'
|
193
|
+
end
|
194
|
+
|
195
|
+
# convenience method for setting support for embed content
|
196
|
+
def support_embed_content!
|
197
|
+
self.content_intended_use = 'embed'
|
198
|
+
self.content_return_types = 'oembed,lti_launch_url,url,image_url,iframe'
|
199
|
+
end
|
200
|
+
|
201
|
+
# convenience method for setting support for navigation content
|
202
|
+
def support_navigation_content!
|
203
|
+
self.content_intended_use = 'navigation'
|
204
|
+
self.content_return_types = 'lti_launch_url'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ims-lti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -98,6 +98,8 @@ extensions: []
|
|
98
98
|
extra_rdoc_files:
|
99
99
|
- LICENSE
|
100
100
|
files:
|
101
|
+
- lib/ims/lti/extensions/canvas.rb
|
102
|
+
- lib/ims/lti/extensions/content.rb
|
101
103
|
- lib/ims/lti/extensions/outcome_data.rb
|
102
104
|
- lib/ims/lti/extensions.rb
|
103
105
|
- lib/ims/lti/launch_params.rb
|
@@ -113,7 +115,8 @@ files:
|
|
113
115
|
- README.md
|
114
116
|
- Changelog
|
115
117
|
homepage: http://github.com/instructure/ims-lti
|
116
|
-
licenses:
|
118
|
+
licenses:
|
119
|
+
- MIT
|
117
120
|
post_install_message:
|
118
121
|
rdoc_options: []
|
119
122
|
require_paths:
|