ims-lti 1.2.4 → 2.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Changelog.txt +0 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -103
- data/lib/ims.rb +3 -1
- data/lib/ims/lti.rb +6 -64
- data/lib/ims/lti/converters.rb +5 -0
- data/lib/ims/lti/converters/time_json_converter.rb +13 -0
- data/lib/ims/lti/models.rb +29 -0
- data/lib/ims/lti/models/base_url_choice.rb +15 -0
- data/lib/ims/lti/models/base_url_selector.rb +5 -0
- data/lib/ims/lti/models/contact.rb +5 -0
- data/lib/ims/lti/models/icon_endpoint.rb +5 -0
- data/lib/ims/lti/models/icon_info.rb +6 -0
- data/lib/ims/lti/models/localized_name.rb +11 -0
- data/lib/ims/lti/models/localized_text.rb +11 -0
- data/lib/ims/lti/models/lti_model.rb +169 -0
- data/lib/ims/lti/models/message_handler.rb +6 -0
- data/lib/ims/lti/models/messages.rb +6 -0
- data/lib/ims/lti/models/messages/basic_lti_launch_request.rb +8 -0
- data/lib/ims/lti/models/messages/message.rb +43 -0
- data/lib/ims/lti/models/messages/registration_request.rb +17 -0
- data/lib/ims/lti/models/parameter.rb +5 -0
- data/lib/ims/lti/models/product_family.rb +8 -0
- data/lib/ims/lti/models/product_info.rb +19 -0
- data/lib/ims/lti/models/product_instance.rb +10 -0
- data/lib/ims/lti/models/resource_handler.rb +18 -0
- data/lib/ims/lti/models/resource_type.rb +6 -0
- data/lib/ims/lti/models/rest_service.rb +14 -0
- data/lib/ims/lti/models/rest_service_profile.rb +7 -0
- data/lib/ims/lti/models/security_contract.rb +9 -0
- data/lib/ims/lti/models/service_owner.rb +8 -0
- data/lib/ims/lti/models/service_provider.rb +11 -0
- data/lib/ims/lti/models/tool_consumer_profile.rb +20 -0
- data/lib/ims/lti/models/tool_profile.rb +22 -0
- data/lib/ims/lti/models/tool_proxy.rb +11 -0
- data/lib/ims/lti/models/vendor.rb +28 -0
- data/lib/ims/lti/services.rb +5 -0
- data/lib/ims/lti/services/message_service.rb +40 -0
- data/lib/ims/lti/version.rb +5 -0
- metadata +68 -52
- data/Changelog +0 -54
- data/LICENSE +0 -18
- data/lib/ims/lti/deprecated_role_checks.rb +0 -52
- data/lib/ims/lti/extensions.rb +0 -45
- data/lib/ims/lti/extensions/canvas.rb +0 -122
- data/lib/ims/lti/extensions/content.rb +0 -209
- data/lib/ims/lti/extensions/outcome_data.rb +0 -216
- data/lib/ims/lti/launch_params.rb +0 -166
- data/lib/ims/lti/outcome_request.rb +0 -225
- data/lib/ims/lti/outcome_response.rb +0 -166
- data/lib/ims/lti/request_validator.rb +0 -56
- data/lib/ims/lti/role_checks.rb +0 -101
- data/lib/ims/lti/tool_base.rb +0 -29
- data/lib/ims/lti/tool_config.rb +0 -231
- data/lib/ims/lti/tool_consumer.rb +0 -86
- data/lib/ims/lti/tool_provider.rb +0 -143
@@ -1,86 +0,0 @@
|
|
1
|
-
module IMS::LTI
|
2
|
-
# Class for implementing an LTI Tool Consumer
|
3
|
-
class ToolConsumer < ToolBase
|
4
|
-
attr_accessor :launch_url, :timestamp, :nonce
|
5
|
-
|
6
|
-
# Create a new ToolConsumer
|
7
|
-
#
|
8
|
-
# @param consumer_key [String] The OAuth consumer key
|
9
|
-
# @param consumer_secret [String] The OAuth consumer secret
|
10
|
-
# @param params [Hash] Set the launch parameters as described in LaunchParams
|
11
|
-
def initialize(consumer_key, consumer_secret, params={})
|
12
|
-
super(consumer_key, consumer_secret, params)
|
13
|
-
@launch_url = params['launch_url']
|
14
|
-
end
|
15
|
-
|
16
|
-
def process_post_request(post_request)
|
17
|
-
request = extend_outcome_request(OutcomeRequest.new)
|
18
|
-
request.process_post_request(post_request)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Set launch data from a ToolConfig
|
22
|
-
#
|
23
|
-
# @param config [ToolConfig]
|
24
|
-
def set_config(config)
|
25
|
-
@launch_url ||= config.secure_launch_url
|
26
|
-
@launch_url ||= config.launch_url
|
27
|
-
# any parameters already set will take priority
|
28
|
-
@custom_params = config.custom_params.merge(@custom_params)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Check if the required parameters for a tool launch are set
|
32
|
-
def has_required_params?
|
33
|
-
@consumer_key && @consumer_secret && @resource_link_id && @launch_url
|
34
|
-
end
|
35
|
-
|
36
|
-
# Generate the launch data including the necessary OAuth information
|
37
|
-
#
|
38
|
-
#
|
39
|
-
def generate_launch_data
|
40
|
-
raise IMS::LTI::InvalidLTIConfigError, "Not all required params set for tool launch" unless has_required_params?
|
41
|
-
|
42
|
-
params = self.to_params
|
43
|
-
params['lti_version'] ||= 'LTI-1p0'
|
44
|
-
params['lti_message_type'] ||= 'basic-lti-launch-request'
|
45
|
-
uri = URI.parse(@launch_url)
|
46
|
-
|
47
|
-
if uri.port == uri.default_port
|
48
|
-
host = uri.host
|
49
|
-
else
|
50
|
-
host = "#{uri.host}:#{uri.port}"
|
51
|
-
end
|
52
|
-
|
53
|
-
consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {
|
54
|
-
:site => "#{uri.scheme}://#{host}",
|
55
|
-
:signature_method => "HMAC-SHA1"
|
56
|
-
})
|
57
|
-
|
58
|
-
path = uri.path
|
59
|
-
path = '/' if path.empty?
|
60
|
-
if uri.query && uri.query != ''
|
61
|
-
CGI.parse(uri.query).each do |query_key, query_values|
|
62
|
-
unless params[query_key]
|
63
|
-
params[query_key] = query_values.first
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
options = {
|
68
|
-
:scheme => 'body',
|
69
|
-
:timestamp => @timestamp,
|
70
|
-
:nonce => @nonce
|
71
|
-
}
|
72
|
-
request = consumer.create_signed_request(:post, path, nil, options, params)
|
73
|
-
|
74
|
-
# the request is made by a html form in the user's browser, so we
|
75
|
-
# want to revert the escapage and return the hash of post parameters ready
|
76
|
-
# for embedding in a html view
|
77
|
-
hash = {}
|
78
|
-
request.body.split(/&/).each do |param|
|
79
|
-
key, val = param.split(/=/).map { |v| CGI.unescape(v) }
|
80
|
-
hash[key] = val
|
81
|
-
end
|
82
|
-
hash
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
module IMS::LTI
|
2
|
-
|
3
|
-
# Class for implementing an LTI Tool Provider
|
4
|
-
#
|
5
|
-
# # Initialize TP object with OAuth creds and post parameters
|
6
|
-
# provider = IMS::LTI::ToolProvider.new(consumer_key, consumer_secret, params)
|
7
|
-
#
|
8
|
-
# # Verify OAuth signature by passing the request object
|
9
|
-
# if provider.valid_request?(request)
|
10
|
-
# # success
|
11
|
-
# else
|
12
|
-
# # handle invalid OAuth
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# if provider.outcome_service?
|
16
|
-
# # ready for grade write-back
|
17
|
-
# else
|
18
|
-
# # normal tool launch without grade write-back
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# If the tool was launch as an outcome service you can POST a score to the TC.
|
22
|
-
# The POST calls all return an OutcomeResponse object which can be used to
|
23
|
-
# handle the response appropriately.
|
24
|
-
#
|
25
|
-
# # post the score to the TC, score should be a float >= 0.0 and <= 1.0
|
26
|
-
# # this returns an OutcomeResponse object
|
27
|
-
# response = provider.post_replace_result!(score)
|
28
|
-
# if response.success?
|
29
|
-
# # grade write worked
|
30
|
-
# elsif response.processing?
|
31
|
-
# elsif response.unsupported?
|
32
|
-
# else
|
33
|
-
# # failed
|
34
|
-
# end
|
35
|
-
|
36
|
-
class ToolProvider < ToolBase
|
37
|
-
# List of outcome requests made through this instance
|
38
|
-
|
39
|
-
include DeprecatedRoleChecks
|
40
|
-
include RoleChecks
|
41
|
-
attr_accessor :outcome_requests
|
42
|
-
# Message to be sent back to the ToolConsumer when the user returns
|
43
|
-
attr_accessor :lti_errormsg, :lti_errorlog, :lti_msg, :lti_log
|
44
|
-
|
45
|
-
# Create a new ToolProvider
|
46
|
-
#
|
47
|
-
# @param consumer_key [String] The OAuth consumer key
|
48
|
-
# @param consumer_secret [String] The OAuth consumer secret
|
49
|
-
# @param params [Hash] Set the launch parameters as described in LaunchParams
|
50
|
-
def initialize(consumer_key, consumer_secret, params={})
|
51
|
-
super(consumer_key, consumer_secret, params)
|
52
|
-
@outcome_requests = []
|
53
|
-
end
|
54
|
-
|
55
|
-
# Check if the request was an LTI Launch Request
|
56
|
-
def launch_request?
|
57
|
-
lti_message_type == 'basic-lti-launch-request'
|
58
|
-
end
|
59
|
-
|
60
|
-
# Check if the Tool Launch expects an Outcome Result
|
61
|
-
def outcome_service?
|
62
|
-
!!(lis_outcome_service_url && lis_result_sourcedid)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return the full, given, or family name if set
|
66
|
-
def username(default=nil)
|
67
|
-
lis_person_name_given || lis_person_name_family || lis_person_name_full || default
|
68
|
-
end
|
69
|
-
|
70
|
-
# POSTs the given score to the Tool Consumer with a replaceResult
|
71
|
-
#
|
72
|
-
# Creates a new OutcomeRequest object and stores it in @outcome_requests
|
73
|
-
#
|
74
|
-
# @return [OutcomeResponse] the response from the Tool Consumer
|
75
|
-
def post_replace_result!(score)
|
76
|
-
new_request.post_replace_result!(score)
|
77
|
-
end
|
78
|
-
|
79
|
-
# POSTs a delete request to the Tool Consumer
|
80
|
-
#
|
81
|
-
# Creates a new OutcomeRequest object and stores it in @outcome_requests
|
82
|
-
#
|
83
|
-
# @return [OutcomeResponse] the response from the Tool Consumer
|
84
|
-
def post_delete_result!
|
85
|
-
new_request.post_delete_result!
|
86
|
-
end
|
87
|
-
|
88
|
-
# POSTs the given score to the Tool Consumer with a replaceResult, the
|
89
|
-
# returned OutcomeResponse will have the score
|
90
|
-
#
|
91
|
-
# Creates a new OutcomeRequest object and stores it in @outcome_requests
|
92
|
-
#
|
93
|
-
# @return [OutcomeResponse] the response from the Tool Consumer
|
94
|
-
def post_read_result!
|
95
|
-
new_request.post_read_result!
|
96
|
-
end
|
97
|
-
|
98
|
-
# Returns the most recent OutcomeRequest
|
99
|
-
def last_outcome_request
|
100
|
-
@outcome_requests.last
|
101
|
-
end
|
102
|
-
|
103
|
-
# Convenience method for whether the last OutcomeRequest was successful
|
104
|
-
def last_outcome_success?
|
105
|
-
last_outcome_request && last_outcome_request.outcome_post_successful?
|
106
|
-
end
|
107
|
-
|
108
|
-
# If the Tool Consumer sent a URL for the user to return to this will add
|
109
|
-
# any set messages to the URL.
|
110
|
-
#
|
111
|
-
# Example:
|
112
|
-
#
|
113
|
-
# tc = IMS::LTI::tc.new
|
114
|
-
# tc.launch_presentation_return_url = "http://example.com/return"
|
115
|
-
# tc.lti_msg = "hi there"
|
116
|
-
# tc.lti_errorlog = "error happens"
|
117
|
-
#
|
118
|
-
# tc.build_return_url # => "http://example.com/return?lti_msg=hi%20there<i_errorlog=error%20happens"
|
119
|
-
def build_return_url
|
120
|
-
return nil unless launch_presentation_return_url
|
121
|
-
messages = []
|
122
|
-
%w{lti_errormsg lti_errorlog lti_msg lti_log}.each do |m|
|
123
|
-
if message = self.send(m)
|
124
|
-
messages << "#{m}=#{URI.escape(message)}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
q_string = messages.any? ? ("?" + messages.join("&")) : ''
|
128
|
-
launch_presentation_return_url + q_string
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def new_request
|
134
|
-
@outcome_requests << OutcomeRequest.new(:consumer_key => @consumer_key,
|
135
|
-
:consumer_secret => @consumer_secret,
|
136
|
-
:lis_outcome_service_url => lis_outcome_service_url,
|
137
|
-
:lis_result_sourcedid =>lis_result_sourcedid)
|
138
|
-
|
139
|
-
extend_outcome_request(@outcome_requests.last)
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|