Class: AJIMS::LTI::ToolProvider
- Inherits:
-
Object
- Object
- AJIMS::LTI::ToolProvider
- Includes:
- Extensions::Base, LaunchParams, RequestValidator
- Defined in:
- lib/ajims/lti/tool_provider.rb
Overview
Class for implementing an LTI Tool Provider
# Initialize TP object with OAuth creds and post parameters
provider = IMS::LTI::ToolProvider.new(consumer_key, consumer_secret, params)
# Verify OAuth signature by passing the request object
if provider.valid_request?(request)
# success
else
# handle invalid OAuth
end
if provider.outcome_service?
# ready for grade write-back
else
# normal tool launch without grade write-back
end
If the tool was launch as an outcome service you can POST a score to the TC. The POST calls all return an OutcomeResponse object which can be used to handle the response appropriately.
# post the score to the TC, score should be a float >= 0.0 and <= 1.0
# this returns an OutcomeResponse object
response = provider.post_replace_result!(score)
if response.success?
# grade write worked
elsif response.processing?
elsif response.unsupported?
else
# failed
end
Constant Summary
Constants included from LaunchParams
LaunchParams::LAUNCH_DATA_PARAMETERS
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
OAuth credentials.
-
#consumer_secret ⇒ Object
OAuth credentials.
-
#lti_errorlog ⇒ Object
Message to be sent back to the ToolConsumer when the user returns.
-
#lti_errormsg ⇒ Object
Message to be sent back to the ToolConsumer when the user returns.
-
#lti_log ⇒ Object
Message to be sent back to the ToolConsumer when the user returns.
-
#lti_msg ⇒ Object
Message to be sent back to the ToolConsumer when the user returns.
-
#outcome_requests ⇒ Object
List of outcome requests made through this instance.
Attributes included from RequestValidator
Attributes included from LaunchParams
#custom_params, #ext_params, #non_spec_params
Instance Method Summary collapse
-
#admin? ⇒ Boolean
Convenience method for checking if the user has ‘administrator’ role.
-
#build_return_url ⇒ Object
If the Tool Consumer sent a URL for the user to return to this will add any set messages to the URL.
-
#content_developer? ⇒ Boolean
Convenience method for checking if the user has ‘contentdeveloper’ role.
-
#has_role?(role) ⇒ Boolean
Check whether the Launch Parameters have a role.
-
#initialize(consumer_key, consumer_secret, params = {}) ⇒ ToolProvider
constructor
Create a new ToolProvider.
-
#instructor? ⇒ Boolean
Convenience method for checking if the user has ‘instructor’ or ‘faculty’ or ‘staff’ role.
-
#last_outcome_request ⇒ Object
Returns the most recent OutcomeRequest.
-
#last_outcome_success? ⇒ Boolean
Convenience method for whether the last OutcomeRequest was successful.
-
#launch_request? ⇒ Boolean
Check if the request was an LTI Launch Request.
-
#manager? ⇒ Boolean
Convenience method for checking if the user has ‘Manager’ role.
-
#member? ⇒ Boolean
Convenience method for checking if the user has ‘Member’ role.
-
#mentor? ⇒ Boolean
Convenience method for checking if the user has ‘Mentor’ role.
-
#outcome_service? ⇒ Boolean
Check if the Tool Launch expects an Outcome Result.
-
#post_delete_result! ⇒ OutcomeResponse
POSTs a delete request to the Tool Consumer.
-
#post_read_result! ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult, the returned OutcomeResponse will have the score.
-
#post_replace_result!(score, submitted_at: nil) ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult.
-
#student? ⇒ Boolean
Convenience method for checking if the user has ‘learner’ or ‘student’ role.
-
#ta? ⇒ Boolean
Convenience method for checking if the user has ‘TeachingAssistant’ role.
-
#username(default = nil) ⇒ Object
Return the full, given, or family name if set.
Methods included from RequestValidator
#request_oauth_nonce, #request_oauth_timestamp, #valid_request!, #valid_request?
Methods included from LaunchParams
#get_custom_param, #get_ext_param, #get_non_spec_param, #process_params, #roles=, #set_custom_param, #set_ext_param, #set_non_spec_param, #to_params
Methods included from Extensions::Base
#extend_outcome_request, #extend_outcome_response, #outcome_request_extensions, #outcome_response_extensions
Constructor Details
#initialize(consumer_key, consumer_secret, params = {}) ⇒ ToolProvider
Create a new ToolProvider
53 54 55 56 57 58 59 60 61 |
# File 'lib/ajims/lti/tool_provider.rb', line 53 def initialize(consumer_key, consumer_secret, params={}) @consumer_key = consumer_key @consumer_secret = consumer_secret @custom_params = {} @ext_params = {} @non_spec_params = {} @outcome_requests = [] process_params(params) end |
Instance Attribute Details
#consumer_key ⇒ Object
OAuth credentials
42 43 44 |
# File 'lib/ajims/lti/tool_provider.rb', line 42 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
OAuth credentials
42 43 44 |
# File 'lib/ajims/lti/tool_provider.rb', line 42 def consumer_secret @consumer_secret end |
#lti_errorlog ⇒ Object
Message to be sent back to the ToolConsumer when the user returns
46 47 48 |
# File 'lib/ajims/lti/tool_provider.rb', line 46 def lti_errorlog @lti_errorlog end |
#lti_errormsg ⇒ Object
Message to be sent back to the ToolConsumer when the user returns
46 47 48 |
# File 'lib/ajims/lti/tool_provider.rb', line 46 def lti_errormsg @lti_errormsg end |
#lti_log ⇒ Object
Message to be sent back to the ToolConsumer when the user returns
46 47 48 |
# File 'lib/ajims/lti/tool_provider.rb', line 46 def lti_log @lti_log end |
#lti_msg ⇒ Object
Message to be sent back to the ToolConsumer when the user returns
46 47 48 |
# File 'lib/ajims/lti/tool_provider.rb', line 46 def lti_msg @lti_msg end |
#outcome_requests ⇒ Object
List of outcome requests made through this instance
44 45 46 |
# File 'lib/ajims/lti/tool_provider.rb', line 44 def outcome_requests @outcome_requests end |
Instance Method Details
#admin? ⇒ Boolean
Convenience method for checking if the user has ‘administrator’ role
100 101 102 |
# File 'lib/ajims/lti/tool_provider.rb', line 100 def admin? has_role?('administrator') end |
#build_return_url ⇒ Object
If the Tool Consumer sent a URL for the user to return to this will add any set messages to the URL.
Example:
tc = IMS::LTI::tc.new
tc.launch_presentation_return_url = "http://example.com/return"
tc.lti_msg = "hi there"
tc.lti_errorlog = "error happens"
tc.build_return_url # => "http://example.com/return?lti_msg=hi+there<i_errorlog=error+happens"
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/ajims/lti/tool_provider.rb', line 173 def build_return_url return nil unless launch_presentation_return_url = [] %w{lti_errormsg lti_errorlog lti_msg lti_log}.each do |m| if = self.send(m) << "#{m}=#{URI.encode_www_form_component()}" end end q_string = .any? ? ("?" + .join("&")) : '' launch_presentation_return_url + q_string end |
#content_developer? ⇒ Boolean
Convenience method for checking if the user has ‘contentdeveloper’ role
80 81 82 |
# File 'lib/ajims/lti/tool_provider.rb', line 80 def content_developer? has_role?('ContentDeveloper') end |
#has_role?(role) ⇒ Boolean
Check whether the Launch Parameters have a role
64 65 66 67 |
# File 'lib/ajims/lti/tool_provider.rb', line 64 def has_role?(role) role = role.downcase @roles && @roles.any?{|r| r.index(role)} end |
#instructor? ⇒ Boolean
Convenience method for checking if the user has ‘instructor’ or ‘faculty’ or ‘staff’ role
75 76 77 |
# File 'lib/ajims/lti/tool_provider.rb', line 75 def instructor? has_role?('instructor') || has_role?('faculty') || has_role?('staff') end |
#last_outcome_request ⇒ Object
Returns the most recent OutcomeRequest
153 154 155 |
# File 'lib/ajims/lti/tool_provider.rb', line 153 def last_outcome_request @outcome_requests.last end |
#last_outcome_success? ⇒ Boolean
Convenience method for whether the last OutcomeRequest was successful
158 159 160 |
# File 'lib/ajims/lti/tool_provider.rb', line 158 def last_outcome_success? last_outcome_request && last_outcome_request.outcome_post_successful? end |
#launch_request? ⇒ Boolean
Check if the request was an LTI Launch Request
110 111 112 |
# File 'lib/ajims/lti/tool_provider.rb', line 110 def launch_request? == 'basic-lti-launch-request' end |
#manager? ⇒ Boolean
Convenience method for checking if the user has ‘Manager’ role
90 91 92 |
# File 'lib/ajims/lti/tool_provider.rb', line 90 def manager? has_role?('Manager') end |
#member? ⇒ Boolean
Convenience method for checking if the user has ‘Member’ role
85 86 87 |
# File 'lib/ajims/lti/tool_provider.rb', line 85 def member? has_role?('Member') end |
#mentor? ⇒ Boolean
Convenience method for checking if the user has ‘Mentor’ role
95 96 97 |
# File 'lib/ajims/lti/tool_provider.rb', line 95 def mentor? has_role?('Mentor') end |
#outcome_service? ⇒ Boolean
Check if the Tool Launch expects an Outcome Result
115 116 117 |
# File 'lib/ajims/lti/tool_provider.rb', line 115 def outcome_service? !!(lis_outcome_service_url && lis_result_sourcedid) end |
#post_delete_result! ⇒ OutcomeResponse
POSTs a delete request to the Tool Consumer
Creates a new OutcomeRequest object and stores it in @outcome_requests
138 139 140 |
# File 'lib/ajims/lti/tool_provider.rb', line 138 def post_delete_result! new_request.post_delete_result! end |
#post_read_result! ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult, the returned OutcomeResponse will have the score
Creates a new OutcomeRequest object and stores it in @outcome_requests
148 149 150 |
# File 'lib/ajims/lti/tool_provider.rb', line 148 def post_read_result! new_request.post_read_result! end |
#post_replace_result!(score, submitted_at: nil) ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult
Creates a new OutcomeRequest object and stores it in @outcome_requests
129 130 131 |
# File 'lib/ajims/lti/tool_provider.rb', line 129 def post_replace_result!(score, submitted_at: nil) new_request.post_replace_result!(score, submitted_at: submitted_at) end |
#student? ⇒ Boolean
Convenience method for checking if the user has ‘learner’ or ‘student’ role
70 71 72 |
# File 'lib/ajims/lti/tool_provider.rb', line 70 def student? has_role?('learner') || has_role?('student') end |
#ta? ⇒ Boolean
Convenience method for checking if the user has ‘TeachingAssistant’ role
105 106 107 |
# File 'lib/ajims/lti/tool_provider.rb', line 105 def ta? has_role?('TeachingAssistant') end |
#username(default = nil) ⇒ Object
Return the full, given, or family name if set
120 121 122 |
# File 'lib/ajims/lti/tool_provider.rb', line 120 def username(default=nil) lis_person_name_given || lis_person_name_family || lis_person_name_full || default end |