module AJIMS::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

custom_params[RW]

Hash of custom parameters, the keys will be prepended with “custom_” at launch

ext_params[RW]

Hash of extension parameters, the keys will be prepended with “ext_” at launch

non_spec_params[RW]

Hash of parameters to add to the launch. These keys will not be prepended with any value at launch

Public Instance Methods

get_custom_param(key) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 103
def get_custom_param(key)
  @custom_params[key]
end
get_ext_param(key) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 119
def get_ext_param(key)
  @ext_params[key]
end
get_non_spec_param(key) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 111
def get_non_spec_param(key)
  @non_spec_params[key]
end
process_params(params) click to toggle source

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/ajims/lti/launch_params.rb, line 136
def process_params(params)
  params.each_pair do |key, val|
    if LAUNCH_DATA_PARAMETERS.member?(key)
      self.send("#{key}=", val)
    elsif key =~ /custom_(.*)/
      @custom_params[$1] = val
    elsif key =~ /ext_(.*)/
      @ext_params[$1] = val
    end
  end
end
roles=(roles_list) click to toggle source

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/ajims/lti/launch_params.rb, line 87
def roles=(roles_list)
  if roles_list
    if roles_list.is_a?(Array)
      @roles = roles_list
    else
      @roles = roles_list.split(",").map(&:downcase)
    end
  else
    @roles = nil
  end
end
set_custom_param(key, val) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 99
def set_custom_param(key, val)
  @custom_params[key] = val
end
set_ext_param(key, val) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 115
def set_ext_param(key, val)
  @ext_params[key] = val
end
set_non_spec_param(key, val) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 107
def set_non_spec_param(key, val)
  @non_spec_params[key] = val
end
to_params() click to toggle source

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/ajims/lti/launch_params.rb, line 126
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

add_key_prefix(hash, prefix) click to toggle source
# File lib/ajims/lti/launch_params.rb, line 154
def add_key_prefix(hash, prefix)
  hash.keys.inject({}) { |h, k| h["#{prefix}_#{k}"] = hash[k]; h }
end
launch_data_hash() click to toggle source
# File lib/ajims/lti/launch_params.rb, line 150
def launch_data_hash
  LAUNCH_DATA_PARAMETERS.inject({}) { |h, k| h[k] = self.send(k) if self.send(k); h }
end