module IMS::LTI::LaunchParams
Mixin module for managing LTI
Launch Data
Launch data documentation: www.imsglobal.org/lti/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684
Constants
- LAUNCH_DATA_PARAMETERS
List of the standard launch parameters for an
LTI
launch
Attributes
Hash of custom parameters, the keys will be prepended with “custom_” at launch
Hash of extension parameters, the keys will be prepended with “ext_” at launch
Hash of parameters to add to the launch. These keys will not be prepended with any value at launch
Public Instance Methods
# File lib/ims/lti/launch_params.rb, line 110 def get_custom_param(key) @custom_params[key] end
# File lib/ims/lti/launch_params.rb, line 126 def get_ext_param(key) @ext_params[key] end
# File lib/ims/lti/launch_params.rb, line 118 def get_non_spec_param(key) @non_spec_params[key] end
Populates the launch data from a Hash
Only keys in LAUNCH_DATA_PARAMETERS
and that start with 'custom_' or 'ext_' will be pulled from the provided Hash
# File lib/ims/lti/launch_params.rb, line 143 def process_params(params) params.each_pair do |key, val| if LAUNCH_DATA_PARAMETERS.member?(key) self.send("#{key}=", val) elsif key =~ /\Acustom_(.+)\Z/ @custom_params[$1] = val elsif key =~ /\Aext_(.+)\Z/ @ext_params[$1] = val end end end
Set the roles for the current launch
Full list of roles can be found here: www.imsglobal.org/LTI/v1p1pd/ltiIMGv1p1pd.html#_Toc309649700
LIS
roles include:
-
Student
-
Faculty
-
Member
-
Learner
-
Instructor
-
Mentor
-
Staff
-
Alumni
-
ProspectiveStudent
-
Guest
-
Other
-
Administrator
-
Observer
-
None
@param roles_list [String,Array] An Array or comma-separated String of roles
# File lib/ims/lti/launch_params.rb, line 94 def roles=(roles_list) if roles_list if roles_list.is_a?(Array) @roles = roles_list else @roles = roles_list.split(",") end else @roles = nil end end
# File lib/ims/lti/launch_params.rb, line 106 def set_custom_param(key, val) @custom_params[key] = val end
# File lib/ims/lti/launch_params.rb, line 122 def set_ext_param(key, val) @ext_params[key] = val end
# File lib/ims/lti/launch_params.rb, line 114 def set_non_spec_param(key, val) @non_spec_params[key] = val end
Create a new Hash with all launch data. Custom/Extension keys will have the appropriate value prepended to the keys and the roles are set as a comma separated String
# File lib/ims/lti/launch_params.rb, line 133 def to_params params = launch_data_hash.merge(add_key_prefix(@custom_params, 'custom')).merge(add_key_prefix(@ext_params, 'ext')).merge(@non_spec_params) params["roles"] = @roles.join(",") if @roles params end
Private Instance Methods
# File lib/ims/lti/launch_params.rb, line 161 def add_key_prefix(hash, prefix) hash.keys.inject({}) { |h, k| h["#{prefix}_#{k}"] = hash[k]; h } end
# File lib/ims/lti/launch_params.rb, line 157 def launch_data_hash LAUNCH_DATA_PARAMETERS.inject({}) { |h, k| h[k] = self.send(k) if self.send(k); h } end