ims-lti 2.0.0.beta.1 → 2.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ims/lti.rb +3 -0
- data/lib/ims/lti/models/lti_model.rb +5 -1
- data/lib/ims/lti/models/messages/message.rb +20 -3
- data/lib/ims/lti/models/resource_handler.rb +4 -0
- data/lib/ims/lti/models/rest_service.rb +17 -1
- data/lib/ims/lti/models/rest_service_profile.rb +8 -0
- data/lib/ims/lti/models/tool_consumer_profile.rb +6 -1
- data/lib/ims/lti/models/tool_profile.rb +8 -0
- data/lib/ims/lti/models/tool_proxy.rb +6 -0
- data/lib/ims/lti/services.rb +1 -0
- data/lib/ims/lti/services/message_service.rb +31 -23
- data/lib/ims/lti/services/tool_proxy_registration_service.rb +39 -0
- metadata +52 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f070c1a552e6a85696dbf87fc187b14f7a252d
|
4
|
+
data.tar.gz: 56a2303e4793715a1c2e301f62488fc4091219da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c55c3788464a299201d8d513d89981917b37b7c752a55c8563c838f61b78d86b6214695e043898f4b97280efc034b82d79ed613a1cfce2ddb1e67769f94999d3
|
7
|
+
data.tar.gz: 42b4177176b634b61164ff40719d6867d1f64ff7adffe2016104d6031c55692b292081b2c00c1a98b2aa64c890b0a7a499799697f70da97f03cca5d768d1817b
|
data/lib/ims/lti.rb
CHANGED
@@ -42,7 +42,11 @@ module IMS::LTI::Models
|
|
42
42
|
|
43
43
|
def attributes=(attrs)
|
44
44
|
attrs.each do |k, v|
|
45
|
-
|
45
|
+
if self.class.attributes.include?(k.to_sym)
|
46
|
+
instance_variable_set("@#{k.to_s}", v)
|
47
|
+
else
|
48
|
+
warn("Unknown attribute '#{k}'")
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -3,14 +3,30 @@ module IMS::LTI::Models::Messages
|
|
3
3
|
LAUNCH_TARGET_IFRAME = 'iframe'
|
4
4
|
LAUNCH_TARGET_WINDOW = 'window'
|
5
5
|
|
6
|
+
EXTENSION_PREFIX = 'ext_'
|
7
|
+
CUSTOM_PREFIX = 'custom_'
|
8
|
+
|
6
9
|
add_attributes :lti_message_type, :lti_version, :user_id, :roles, :launch_presentation_local,
|
7
10
|
:launch_presentation_document_target, :launch_presentation_css_url, :launch_presentation_width,
|
8
11
|
:launch_presentation_height
|
9
12
|
|
10
13
|
def initialize(attrs = {})
|
11
|
-
super(attrs)
|
12
14
|
@custom_params = {}
|
13
15
|
@ext_params = {}
|
16
|
+
attributes = {}
|
17
|
+
|
18
|
+
attrs.each do |k,v|
|
19
|
+
str_key = k.to_s
|
20
|
+
if str_key.start_with?(EXTENSION_PREFIX)
|
21
|
+
@ext_params[str_key.sub(EXTENSION_PREFIX, '')] = v
|
22
|
+
elsif str_key.start_with?(CUSTOM_PREFIX)
|
23
|
+
@custom_params[str_key.sub(CUSTOM_PREFIX, '')] = v
|
24
|
+
else
|
25
|
+
attributes[k] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
super(attributes)
|
14
30
|
end
|
15
31
|
|
16
32
|
def post_params
|
@@ -19,13 +35,13 @@ module IMS::LTI::Models::Messages
|
|
19
35
|
|
20
36
|
def get_ext_params
|
21
37
|
params = {}
|
22
|
-
@ext_params.each { |k, v| params["
|
38
|
+
@ext_params.each { |k, v| params["#{EXTENSION_PREFIX}#{k}"] = v }
|
23
39
|
params
|
24
40
|
end
|
25
41
|
|
26
42
|
def get_custom_params
|
27
43
|
params = {}
|
28
|
-
@custom_params.each { |k, v| params["
|
44
|
+
@custom_params.each { |k, v| params["#{CUSTOM_PREFIX}#{k}"] = v }
|
29
45
|
params
|
30
46
|
end
|
31
47
|
|
@@ -39,5 +55,6 @@ module IMS::LTI::Models::Messages
|
|
39
55
|
end
|
40
56
|
end
|
41
57
|
|
58
|
+
private
|
42
59
|
end
|
43
60
|
end
|
@@ -6,8 +6,24 @@ module IMS::LTI::Models
|
|
6
6
|
add_attribute :id, json_key:'@id'
|
7
7
|
add_attribute :type, json_key: '@type'
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(attributes = {})
|
10
10
|
@type = TYPE
|
11
|
+
super(attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
def profile
|
15
|
+
RestServiceProfile.new(
|
16
|
+
service: endpoint,
|
17
|
+
action: action
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def actions
|
22
|
+
[*action]
|
23
|
+
end
|
24
|
+
|
25
|
+
def formats
|
26
|
+
[*format]
|
11
27
|
end
|
12
28
|
|
13
29
|
end
|
@@ -11,9 +11,14 @@ module IMS::LTI::Models
|
|
11
11
|
add_attribute :product_instance, relation:'IMS::LTI::Models::ProductInstance'
|
12
12
|
add_attribute :service_offered, relation: 'IMS::LTI::Models::RestService'
|
13
13
|
|
14
|
-
def initialize
|
14
|
+
def initialize(attr = {})
|
15
15
|
@context = [CONTEXT]
|
16
16
|
@type = TYPE
|
17
|
+
super(attr)
|
18
|
+
end
|
19
|
+
|
20
|
+
def services_offered
|
21
|
+
[*@service_offered]
|
17
22
|
end
|
18
23
|
|
19
24
|
end
|
@@ -7,5 +7,11 @@ module IMS::LTI::Models
|
|
7
7
|
add_attribute :tool_consumer_profile
|
8
8
|
add_attribute :tool_profile, relation:'IMS::LTI::Models::ToolProfile'
|
9
9
|
add_attribute :security_contract, relation:'IMS::LTI::Models::SecurityContract'
|
10
|
+
|
11
|
+
def initialize(attr = {})
|
12
|
+
@context = ['http://purl.imsglobal.org/ctx/lti/v2/ToolProxy']
|
13
|
+
super(attr)
|
14
|
+
@type = 'ToolProxy'
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
data/lib/ims/lti/services.rb
CHANGED
@@ -2,39 +2,47 @@ module IMS::LTI::Services
|
|
2
2
|
class MessageService
|
3
3
|
|
4
4
|
def initialize(key, secret)
|
5
|
-
@
|
6
|
-
@secret = secret
|
5
|
+
@credentials = {consumer_key: key, consumer_secret: secret}
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
request = oauth_consumer.create_signed_request(:post, uri.request_uri, nil, {}, message.post_params)
|
8
|
+
def signed_params(url, message)
|
9
|
+
params = message.post_params
|
10
|
+
header = SimpleOAuth::Header.new(:post, url, params, @credentials)
|
11
|
+
params = header.signed_attributes.merge(params)
|
12
|
+
params
|
13
|
+
end
|
16
14
|
|
17
|
-
|
15
|
+
def valid_signature?(url, params)
|
16
|
+
options, parsed_params = parse_params(params)
|
17
|
+
signature = parsed_params.delete(:oauth_signature)
|
18
|
+
header = SimpleOAuth::Header.new(:post, url, parsed_params, options.merge(@credentials))
|
19
|
+
header.valid?(signature: signature)
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
signed_request = signed_request(url, message)
|
22
|
+
private
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def parse_params(params)
|
25
|
+
params.inject([{}, {}]) do |array, (k, v)|
|
26
|
+
attr = k.to_s.sub('oauth_', '').to_sym
|
27
|
+
if SimpleOAuth::Header::ATTRIBUTE_KEYS.include?(attr)
|
28
|
+
array[0][attr] = v
|
29
|
+
else
|
30
|
+
array[1][k] = v
|
31
|
+
end
|
32
|
+
array
|
26
33
|
end
|
27
|
-
params
|
28
34
|
end
|
29
35
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
+
def signed_request(url, message)
|
37
|
+
uri = URI.parse(url)
|
38
|
+
oauth_consumer = OAuth::Consumer.new(@key, @secret, {
|
39
|
+
:site => "#{uri.scheme}://#{uri.host}",
|
40
|
+
:scheme => :body
|
41
|
+
})
|
42
|
+
request = oauth_consumer.create_signed_request(:post, uri.request_uri, nil, {}, message.post_params)
|
36
43
|
|
37
|
-
|
44
|
+
request
|
38
45
|
end
|
46
|
+
|
39
47
|
end
|
40
48
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module IMS::LTI::Services
|
2
|
+
class ToolProxyRegistrationService
|
3
|
+
def initialize(registration_request)
|
4
|
+
@registration_request = registration_request
|
5
|
+
end
|
6
|
+
|
7
|
+
def tool_consumer_profile
|
8
|
+
return @tool_consumer_profile if @tool_consumer_profile
|
9
|
+
|
10
|
+
connection = Faraday.new
|
11
|
+
response = connection.get(@registration_request.tc_profile_url)
|
12
|
+
@tool_consumer_profile = IMS::LTI::Models::ToolConsumerProfile.new.from_json(response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def service_profiles
|
16
|
+
tool_consumer_profile.services_offered.map(&:profile)
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_tool_proxy(tool_proxy)
|
20
|
+
service = tool_consumer_profile.services_offered.find{|s| s.formats.include?('application/vnd.ims.lti.v2.toolproxy+json') && s.actions.include?('POST')}
|
21
|
+
|
22
|
+
conn = Faraday.new do |conn|
|
23
|
+
conn.request :oauth, {:consumer_key => @registration_request.reg_key, :consumer_secret => @registration_request.reg_password}
|
24
|
+
conn.adapter :net_http
|
25
|
+
end
|
26
|
+
|
27
|
+
response = conn.post do |req|
|
28
|
+
req.url service.endpoint
|
29
|
+
req.headers['Content-Type'] = 'application/json'
|
30
|
+
req.body = tool_proxy.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
if response.status == 201
|
34
|
+
IMS::LTI::Models::ToolProxy.new.from_json(tool_proxy.to_json).from_json(response.body)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ims-lti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.beta.
|
4
|
+
version: 2.0.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Instructure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: oauth
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: simple_oauth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday_middleware
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,20 @@ dependencies:
|
|
66
94
|
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
description:
|
70
112
|
email:
|
71
113
|
executables: []
|
@@ -110,6 +152,7 @@ files:
|
|
110
152
|
- lib/ims/lti/models/vendor.rb
|
111
153
|
- lib/ims/lti/services.rb
|
112
154
|
- lib/ims/lti/services/message_service.rb
|
155
|
+
- lib/ims/lti/services/tool_proxy_registration_service.rb
|
113
156
|
- lib/ims/lti/version.rb
|
114
157
|
homepage: http://github.com/instructure/ims-lti
|
115
158
|
licenses:
|
@@ -136,3 +179,4 @@ signing_key:
|
|
136
179
|
specification_version: 4
|
137
180
|
summary: Ruby library for creating IMS LTI tool providers and consumers
|
138
181
|
test_files: []
|
182
|
+
has_rdoc:
|