Module: IMS::LTI::LaunchParams

Included in:
ToolBase
Defined in:
lib/ims/lti/launch_params.rb

Overview

Mixin module for managing LTI Launch Data

Launch data documentation: www.imsglobal.org/lti/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684

Constant Summary collapse

LAUNCH_DATA_PARAMETERS =

List of the standard launch parameters for an LTI launch

%w{
  accept_media_types
  accept_multiple
  accept_presentation_document_targets
  accept_unsigned
  auto_create
  content_item_return_url
  context_id
  context_label
  context_title
  context_type
  launch_presentation_css_url
  launch_presentation_document_target
  launch_presentation_height
  launch_presentation_locale
  launch_presentation_return_url
  launch_presentation_width
  lis_course_offering_sourcedid
  lis_course_section_sourcedid
  lis_outcome_service_url
  lis_person_contact_email_primary
  lis_person_name_family
  lis_person_name_full
  lis_person_name_given
  lis_person_sourcedid
  lis_result_sourcedid
  lti_message_type
  lti_version
  oauth_callback
  oauth_consumer_key
  oauth_nonce
  oauth_signature
  oauth_signature_method
  oauth_timestamp
  oauth_version
  resource_link_description
  resource_link_id
  resource_link_title
  roles
  role_scope_mentor
  tool_consumer_info_product_family_code
  tool_consumer_info_version
  tool_consumer_instance_contact_email
  tool_consumer_instance_description
  tool_consumer_instance_guid
  tool_consumer_instance_name
  tool_consumer_instance_url
  user_id
  user_image
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_paramsObject

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



63
64
65
# File 'lib/ims/lti/launch_params.rb', line 63

def custom_params
  @custom_params
end

#ext_paramsObject

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



66
67
68
# File 'lib/ims/lti/launch_params.rb', line 66

def ext_params
  @ext_params
end

#non_spec_paramsObject

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



70
71
72
# File 'lib/ims/lti/launch_params.rb', line 70

def non_spec_params
  @non_spec_params
end

Instance Method Details

#get_custom_param(key) ⇒ Object



110
111
112
# File 'lib/ims/lti/launch_params.rb', line 110

def get_custom_param(key)
  @custom_params[key]
end

#get_ext_param(key) ⇒ Object



126
127
128
# File 'lib/ims/lti/launch_params.rb', line 126

def get_ext_param(key)
  @ext_params[key]
end

#get_non_spec_param(key) ⇒ Object



118
119
120
# File 'lib/ims/lti/launch_params.rb', line 118

def get_non_spec_param(key)
  @non_spec_params[key]
end

#process_params(params) ⇒ Object

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



143
144
145
146
147
148
149
150
151
152
153
# 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

#roles=(roles_list) ⇒ Object

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

Parameters:

  • roles_list (String, Array)

    An Array or comma-separated String of roles



94
95
96
97
98
99
100
101
102
103
104
# 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

#set_custom_param(key, val) ⇒ Object



106
107
108
# File 'lib/ims/lti/launch_params.rb', line 106

def set_custom_param(key, val)
  @custom_params[key] = val
end

#set_ext_param(key, val) ⇒ Object



122
123
124
# File 'lib/ims/lti/launch_params.rb', line 122

def set_ext_param(key, val)
  @ext_params[key] = val
end

#set_non_spec_param(key, val) ⇒ Object



114
115
116
# File 'lib/ims/lti/launch_params.rb', line 114

def set_non_spec_param(key, val)
  @non_spec_params[key] = val
end

#to_paramsObject

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



133
134
135
136
137
# 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