Class: IMS::LTI::OutcomeRequest
- Includes:
- Extensions::Base
- Defined in:
- lib/ims/lti/outcome_request.rb
Overview
Class for consuming/generating LTI Outcome Requests
Outcome Request documentation: www.imsglobal.org/lti/v1p1pd/ltiIMGv1p1pd.html#_Toc309649691
This class can be used by both Tool Providers and Tool Consumers. Each will use it a bit differently. The Tool Provider will use it to POST an OAuth-signed request to a TC. A Tool Consumer will use it to parse such a request from a TP.
Tool Provider Usage
An OutcomeRequest will generally be created through a configured ToolProvider object. See the ToolProvider documentation.
Tool Consumer Usage
When an outcome request is sent from a TP the body of the request is XML. This class parses that XML and provides a simple interface for accessing the information in the request. Typical usage would be:
# create an OutcomeRequest from the request object
req = IMS::LTI::OutcomeRequest.from_post_request(request)
# access the source id to identify the user who's grade you'd like to access
req.lis_result_sourcedid
# process the request
if req.replace_request?
# set a new score for the user
elsif req.read_request?
# return the score for the user
elsif req.delete_request?
# clear the score for the user
else
# return an unsupported OutcomeResponse
end
Constant Summary collapse
- REPLACE_REQUEST =
'replaceResult'
- DELETE_REQUEST =
'deleteResult'
- READ_REQUEST =
'readResult'
Constants included from LaunchParams
LaunchParams::LAUNCH_DATA_PARAMETERS
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#lis_outcome_service_url ⇒ Object
Returns the value of attribute lis_outcome_service_url.
-
#lis_result_sourcedid ⇒ Object
Returns the value of attribute lis_result_sourcedid.
-
#message_identifier ⇒ Object
Returns the value of attribute message_identifier.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#outcome_response ⇒ Object
Returns the value of attribute outcome_response.
-
#post_request ⇒ Object
Returns the value of attribute post_request.
-
#score ⇒ Object
Returns the value of attribute score.
Attributes included from RequestValidator
Attributes included from LaunchParams
#custom_params, #ext_params, #non_spec_params
Class Method Summary collapse
-
.from_post_request(post_request) ⇒ Object
Convenience method for creating a new OutcomeRequest from a request object.
Instance Method Summary collapse
-
#delete_request? ⇒ Boolean
Check whether this request is a deleteResult request.
-
#initialize(opts = {}) ⇒ OutcomeRequest
constructor
Create a new OutcomeRequest.
-
#outcome_post_successful? ⇒ Boolean
Check whether the last outcome POST was successful.
-
#post_delete_result! ⇒ OutcomeResponse
POSTs a deleteResult to the Tool Consumer.
-
#post_outcome_request ⇒ OutcomeResponse
POST an OAuth signed request to the Tool Consumer.
-
#post_read_result! ⇒ OutcomeResponse
POSTs a readResult to the Tool Consumer.
-
#post_replace_result!(score) ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult.
- #process_post_request(post_request) ⇒ Object
-
#process_xml(xml) ⇒ Object
Parse Outcome Request data from XML.
-
#read_request? ⇒ Boolean
Check whether this request is a readResult request.
-
#replace_request? ⇒ Boolean
Check whether this request is a replaceResult request.
Methods included from Extensions::Base
#extend_outcome_request, #extend_outcome_response, #outcome_request_extensions, #outcome_response_extensions
Methods inherited from ToolBase
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
Constructor Details
#initialize(opts = {}) ⇒ OutcomeRequest
Create a new OutcomeRequest
49 50 51 52 53 |
# File 'lib/ims/lti/outcome_request.rb', line 49 def initialize(opts={}) opts.each_pair do |key, val| self.send("#{key}=", val) if self.respond_to?("#{key}=") end end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def consumer_secret @consumer_secret end |
#lis_outcome_service_url ⇒ Object
Returns the value of attribute lis_outcome_service_url.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def lis_outcome_service_url @lis_outcome_service_url end |
#lis_result_sourcedid ⇒ Object
Returns the value of attribute lis_result_sourcedid.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def lis_result_sourcedid @lis_result_sourcedid end |
#message_identifier ⇒ Object
Returns the value of attribute message_identifier.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def @message_identifier end |
#operation ⇒ Object
Returns the value of attribute operation.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def operation @operation end |
#outcome_response ⇒ Object
Returns the value of attribute outcome_response.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def outcome_response @outcome_response end |
#post_request ⇒ Object
Returns the value of attribute post_request.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def post_request @post_request end |
#score ⇒ Object
Returns the value of attribute score.
42 43 44 |
# File 'lib/ims/lti/outcome_request.rb', line 42 def score @score end |
Class Method Details
.from_post_request(post_request) ⇒ Object
Convenience method for creating a new OutcomeRequest from a request object
req = IMS::LTI::OutcomeRequest.from_post_request(request)
58 59 60 61 |
# File 'lib/ims/lti/outcome_request.rb', line 58 def self.from_post_request(post_request) request = OutcomeRequest.new request.process_post_request(post_request) end |
Instance Method Details
#delete_request? ⇒ Boolean
Check whether this request is a deleteResult request
106 107 108 |
# File 'lib/ims/lti/outcome_request.rb', line 106 def delete_request? @operation == DELETE_REQUEST end |
#outcome_post_successful? ⇒ Boolean
Check whether the last outcome POST was successful
116 117 118 |
# File 'lib/ims/lti/outcome_request.rb', line 116 def outcome_post_successful? @outcome_response && @outcome_response.success? end |
#post_delete_result! ⇒ OutcomeResponse
POSTs a deleteResult to the Tool Consumer
87 88 89 90 |
# File 'lib/ims/lti/outcome_request.rb', line 87 def post_delete_result! @operation = DELETE_REQUEST post_outcome_request end |
#post_outcome_request ⇒ OutcomeResponse
POST an OAuth signed request to the Tool Consumer
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ims/lti/outcome_request.rb', line 123 def post_outcome_request raise IMS::LTI::InvalidLTIConfigError, "" unless has_required_attributes? res = post_service_request(@lis_outcome_service_url, 'application/xml', generate_request_xml) @outcome_response = extend_outcome_response(OutcomeResponse.new) @outcome_response.process_post_response(res) end |
#post_read_result! ⇒ OutcomeResponse
POSTs a readResult to the Tool Consumer
95 96 97 98 |
# File 'lib/ims/lti/outcome_request.rb', line 95 def post_read_result! @operation = READ_REQUEST post_outcome_request end |
#post_replace_result!(score) ⇒ OutcomeResponse
POSTs the given score to the Tool Consumer with a replaceResult
78 79 80 81 82 |
# File 'lib/ims/lti/outcome_request.rb', line 78 def post_replace_result!(score) @operation = REPLACE_REQUEST @score = score post_outcome_request end |
#process_post_request(post_request) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ims/lti/outcome_request.rb', line 63 def process_post_request(post_request) self.post_request = post_request if post_request.body.respond_to?(:read) xml = post_request.body.read post_request.body.rewind else xml = post_request.body end self.process_xml(xml) self end |
#process_xml(xml) ⇒ Object
Parse Outcome Request data from XML
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ims/lti/outcome_request.rb', line 135 def process_xml(xml) doc = REXML::Document.new xml @message_identifier = doc.text("//imsx_POXRequestHeaderInfo/imsx_messageIdentifier") @lis_result_sourcedid = doc.text("//resultRecord/sourcedGUID/sourcedId") if REXML::XPath.first(doc, "//deleteResultRequest") @operation = DELETE_REQUEST elsif REXML::XPath.first(doc, "//readResultRequest") @operation = READ_REQUEST elsif REXML::XPath.first(doc, "//replaceResultRequest") @operation = REPLACE_REQUEST @score = doc.get_text("//resultRecord/result/resultScore/textString") end extention_process_xml(doc) end |
#read_request? ⇒ Boolean
Check whether this request is a readResult request
111 112 113 |
# File 'lib/ims/lti/outcome_request.rb', line 111 def read_request? @operation == READ_REQUEST end |
#replace_request? ⇒ Boolean
Check whether this request is a replaceResult request
101 102 103 |
# File 'lib/ims/lti/outcome_request.rb', line 101 def replace_request? @operation == REPLACE_REQUEST end |