Class: IMS::LTI::ToolProvider

Inherits:
ToolBase
  • Object
show all
Includes:
DeprecatedRoleChecks, RoleChecks
Defined in:
lib/ims/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

Attributes inherited from ToolBase

#consumer_key, #consumer_secret

Attributes included from RequestValidator

#oauth_signature_validator

Attributes included from LaunchParams

#custom_params, #ext_params, #non_spec_params

Instance Method Summary collapse

Methods included from RoleChecks

#context_admin?, #context_content_developer?, #context_instructor?, #context_mentor?, #context_student?, #context_ta?, #has_base_role?, #has_exact_role?, #institution_admin?, #institution_instructor?, #institution_student?, #system_administrator?

Methods included from DeprecatedRoleChecks

#admin?, #content_developer?, #has_role?, #instructor?, #manager?, #member?, #mentor?, #student?, #ta?

Methods inherited from ToolBase

#post_service_request

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

Parameters:

  • consumer_key (String)

    The OAuth consumer key

  • consumer_secret (String)

    The OAuth consumer secret

  • params (Hash) (defaults to: {})

    Set the launch parameters as described in LaunchParams



50
51
52
53
# File 'lib/ims/lti/tool_provider.rb', line 50

def initialize(consumer_key, consumer_secret, params={})
  super(consumer_key, consumer_secret, params)
  @outcome_requests = []
end

Instance Attribute Details

#lti_errorlogObject

Message to be sent back to the ToolConsumer when the user returns



43
44
45
# File 'lib/ims/lti/tool_provider.rb', line 43

def lti_errorlog
  @lti_errorlog
end

#lti_errormsgObject

Message to be sent back to the ToolConsumer when the user returns



43
44
45
# File 'lib/ims/lti/tool_provider.rb', line 43

def lti_errormsg
  @lti_errormsg
end

#lti_logObject

Message to be sent back to the ToolConsumer when the user returns



43
44
45
# File 'lib/ims/lti/tool_provider.rb', line 43

def lti_log
  @lti_log
end

#lti_msgObject

Message to be sent back to the ToolConsumer when the user returns



43
44
45
# File 'lib/ims/lti/tool_provider.rb', line 43

def lti_msg
  @lti_msg
end

#outcome_requestsObject

Returns the value of attribute outcome_requests.



41
42
43
# File 'lib/ims/lti/tool_provider.rb', line 41

def outcome_requests
  @outcome_requests
end

Instance Method Details

#build_return_urlObject

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%20there&lti_errorlog=error%20happens"


119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ims/lti/tool_provider.rb', line 119

def build_return_url
  return nil unless launch_presentation_return_url
  messages = []
  %w{lti_errormsg lti_errorlog lti_msg lti_log}.each do |m|
    if message = self.send(m)
      messages << "#{m}=#{URI.escape(message)}"
    end
  end
  q_string = messages.any? ? ("?" + messages.join("&")) : ''
  launch_presentation_return_url + q_string
end

#last_outcome_requestObject

Returns the most recent OutcomeRequest



99
100
101
# File 'lib/ims/lti/tool_provider.rb', line 99

def last_outcome_request
  @outcome_requests.last
end

#last_outcome_success?Boolean

Convenience method for whether the last OutcomeRequest was successful

Returns:

  • (Boolean)


104
105
106
# File 'lib/ims/lti/tool_provider.rb', line 104

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/ims/lti/tool_provider.rb', line 56

def launch_request?
  lti_message_type == 'basic-lti-launch-request'
end

#outcome_service?Boolean

Check if the Tool Launch expects an Outcome Result

Returns:

  • (Boolean)


61
62
63
# File 'lib/ims/lti/tool_provider.rb', line 61

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

Returns:



84
85
86
# File 'lib/ims/lti/tool_provider.rb', line 84

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

Returns:



94
95
96
# File 'lib/ims/lti/tool_provider.rb', line 94

def post_read_result!
  new_request.post_read_result!
end

#post_replace_result!(score) ⇒ OutcomeResponse

POSTs the given score to the Tool Consumer with a replaceResult

Creates a new OutcomeRequest object and stores it in @outcome_requests

Returns:



75
76
77
# File 'lib/ims/lti/tool_provider.rb', line 75

def post_replace_result!(score)
  new_request.post_replace_result!(score)
end

#username(default = nil) ⇒ Object

Return the full, given, or family name if set



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

def username(default=nil)
  lis_person_name_given || lis_person_name_family || lis_person_name_full || default
end