ims-lti 1.1.4 → 1.1.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f08cf8db456b71aa74d6c55cecb8e76dc5ae4ad7
4
+ data.tar.gz: 5f1a47d7a25c957228b9f2bc3038ee5d64bc5b30
5
+ SHA512:
6
+ metadata.gz: c79e28940abe36bec574f89263f3650948f8e60010061f9799f9c013129d97c13d388ed1eb708f1328a171578db374ccc435e49148849f6e08c6700c9d302728
7
+ data.tar.gz: 1ed5c8d404daaea3e46177bf5761812a5ae59becc7de4d8e44a736358ee4d991fd71259bfff6c739d05155bd6c8e930bbad104d0719a08a3a6a6a2b1698c9298
data/README.md CHANGED
@@ -24,7 +24,7 @@ proxy for your application. For example:
24
24
  # For a Rails 2.3 app:
25
25
  require 'oauth/request_proxy/action_controller_request'
26
26
 
27
- For further information see the [oauth-ruby](https://github.com/oauth/oauth-ruby) project.
27
+ For further information see the [oauth-ruby](https://github.com/oauth-xx/oauth-ruby) project.
28
28
 
29
29
  ## Usage
30
30
  This readme won't cover the LTI standard, just how to use the library. It will be
@@ -33,6 +33,19 @@ module IMS # :nodoc:
33
33
  class InvalidLTIConfigError < StandardError
34
34
  end
35
35
 
36
+ # POST a signed oauth request with the given key/secret/data
37
+ def self.post_service_request(key, secret, url, content_type, body)
38
+ raise IMS::LTI::InvalidLTIConfigError, "" unless key && secret
39
+
40
+ consumer = OAuth::Consumer.new(key, secret)
41
+ token = OAuth::AccessToken.new(consumer)
42
+ token.post(
43
+ url,
44
+ body,
45
+ 'Content-Type' => content_type
46
+ )
47
+ end
48
+
36
49
  # Generates a unique identifier
37
50
  def self.generate_identifier
38
51
  UUID.new
@@ -43,6 +56,7 @@ end
43
56
  require 'ims/lti/extensions'
44
57
  require 'ims/lti/launch_params'
45
58
  require 'ims/lti/request_validator'
59
+ require 'ims/lti/tool_base'
46
60
  require 'ims/lti/tool_provider'
47
61
  require 'ims/lti/tool_consumer'
48
62
  require 'ims/lti/outcome_request'
@@ -28,34 +28,45 @@ module IMS::LTI
28
28
 
29
29
  # Canvas extension defaults
30
30
  # These properties will cascade down to any options that are configured
31
+ def set_canvas_ext_param(key, value)
32
+ set_ext_param(PLATFORM, key, value)
33
+ end
34
+
35
+ def get_canvas_param(param_key)
36
+ get_ext_param PLATFORM, param_key
37
+ end
31
38
 
32
39
  def canvas_privacy_public!()
33
- set_ext_param(PLATFORM, :privacy_level, 'public')
40
+ set_canvas_ext_param(:privacy_level, 'public')
34
41
  end
35
42
 
36
43
  def canvas_privacy_name_only!()
37
- set_ext_param(PLATFORM, :privacy_level, 'name_only')
44
+ set_canvas_ext_param(:privacy_level, 'name_only')
38
45
  end
39
46
 
40
47
  def canvas_privacy_anonymous!()
41
- set_ext_param(PLATFORM, :privacy_level, 'anonymous')
48
+ set_canvas_ext_param(:privacy_level, 'anonymous')
42
49
  end
43
50
 
44
51
  def canvas_domain!(domain)
45
- set_ext_param(PLATFORM, :domain, domain)
52
+ set_canvas_ext_param(:domain, domain)
46
53
  end
47
54
 
48
55
  def canvas_text!(text)
49
- set_ext_param(PLATFORM, :text, text)
56
+ set_canvas_ext_param(:text, text)
50
57
  end
51
58
 
52
59
  def canvas_icon_url!(icon_url)
53
- set_ext_param(PLATFORM, :icon_url, icon_url)
60
+ set_canvas_ext_param(:icon_url, icon_url)
61
+ end
62
+
63
+ def canvas_tool_id!(tool_id)
64
+ set_canvas_ext_param(:tool_id, tool_id)
54
65
  end
55
66
 
56
67
  def canvas_selector_dimensions!(width, height)
57
- set_ext_param(PLATFORM, :selection_width, width)
58
- set_ext_param(PLATFORM, :selection_height, height)
68
+ set_canvas_ext_param(:selection_width, width)
69
+ set_canvas_ext_param(:selection_height, height)
59
70
  end
60
71
 
61
72
  # Canvas options
@@ -65,25 +76,25 @@ module IMS::LTI
65
76
  # Enables homework submissions via the tool
66
77
  # Valid properties are url, text, selection_width, selection_height, enabled
67
78
  def canvas_homework_submission!(params = {})
68
- set_ext_param(PLATFORM, :homework_submission, params)
79
+ set_canvas_ext_param(:homework_submission, params)
69
80
  end
70
81
 
71
82
  # Adds the tool to canvas' rich text editor
72
83
  # Valid properties are url, icon_url, text, selection_width, selection_height, enabled
73
84
  def canvas_editor_button!(params = {})
74
- set_ext_param(PLATFORM, :editor_button, params)
85
+ set_canvas_ext_param(:editor_button, params)
75
86
  end
76
87
 
77
- # Adds the tool to canvas' rich text editor
78
- # Valid properties are url, icon_url, text, selection_width, selection_height, enabled
88
+ # Adds the tool to canvas' resource selector
89
+ # Valid properties are url, text, selection_width, selection_height, enabled
79
90
  def canvas_resource_selection!(params = {})
80
- set_ext_param(PLATFORM, :resource_selection, params)
91
+ set_canvas_ext_param(:resource_selection, params)
81
92
  end
82
93
 
83
94
  # Adds the tool to account level navigation in canvas
84
95
  # Valid properties are url, text, enabled
85
96
  def canvas_account_navigation!(params = {})
86
- set_ext_param(PLATFORM, :account_navigation, params)
97
+ set_canvas_ext_param(:account_navigation, params)
87
98
  end
88
99
 
89
100
  # Adds the tool to course level navigation in canvas
@@ -91,17 +102,19 @@ module IMS::LTI
91
102
  # Visibility describes who will see the navigation element. Possible values are "admins", "members", and nil
92
103
  # Default determines if it is on or off by default. Possible values are "admins", "members", and nil
93
104
  def canvas_course_navigation!(params = {})
94
- set_ext_param(PLATFORM, :course_navigation, params)
105
+ set_canvas_ext_param(:course_navigation, params)
95
106
  end
96
107
 
97
108
  # Adds the tool to user level navigation in canvas
98
109
  # Valid properties are url, text, enabled
99
110
  def canvas_user_navigation!(params = {})
100
- set_ext_param(PLATFORM, :user_navigation, params)
111
+ set_canvas_ext_param(:user_navigation, params)
101
112
  end
102
113
 
103
- def get_canvas_param(param_key)
104
- get_ext_param PLATFORM, param_key
114
+ # Adds canvas environment configurations options
115
+ # Valid properties are launch_url, domain, test_launch_url, test_domain, beta_launch_url, beta_domain
116
+ def canvas_environments!(params = {})
117
+ set_canvas_ext_param(:environments, params)
105
118
  end
106
119
  end
107
120
  end
@@ -70,12 +70,14 @@ module IMS::LTI
70
70
  # POSTs the given score to the Tool Consumer with a replaceResult and
71
71
  # adds the specified data. The data hash can have the keys "text", "cdata_text", or "url"
72
72
  #
73
- # If both cdata_text and text are sent, cdata_text will be used
73
+ # If both cdata_text and text are sent, cdata_text will be used
74
+ #
75
+ # If score is nil, the replace result XML will not contain a resultScore node
74
76
  #
75
77
  # Creates a new OutcomeRequest object and stores it in @outcome_requests
76
78
  #
77
79
  # @return [OutcomeResponse] the response from the Tool Consumer
78
- def post_replace_result_with_data!(score, data={})
80
+ def post_replace_result_with_data!(score = nil, data={})
79
81
  req = new_request
80
82
  if data["cdata_text"]
81
83
  req.outcome_cdata_text = data["cdata_text"]
@@ -85,7 +87,6 @@ module IMS::LTI
85
87
  req.outcome_url = data["url"] if data["url"]
86
88
  req.post_replace_result!(score)
87
89
  end
88
-
89
90
  end
90
91
 
91
92
  module ToolConsumer
@@ -137,9 +137,9 @@ module IMS::LTI
137
137
  params.each_pair do |key, val|
138
138
  if LAUNCH_DATA_PARAMETERS.member?(key)
139
139
  self.send("#{key}=", val)
140
- elsif key =~ /custom_(.*)/
140
+ elsif key =~ /\Acustom_(.+)\Z/
141
141
  @custom_params[$1] = val
142
- elsif key =~ /ext_(.*)/
142
+ elsif key =~ /\Aext_(.+)\Z/
143
143
  @ext_params[$1] = val
144
144
  end
145
145
  end
@@ -32,7 +32,7 @@ module IMS::LTI
32
32
  # else
33
33
  # # return an unsupported OutcomeResponse
34
34
  # end
35
- class OutcomeRequest
35
+ class OutcomeRequest < ToolBase
36
36
  include IMS::LTI::Extensions::Base
37
37
 
38
38
  REPLACE_REQUEST = 'replaceResult'
@@ -123,13 +123,10 @@ module IMS::LTI
123
123
  def post_outcome_request
124
124
  raise IMS::LTI::InvalidLTIConfigError, "" unless has_required_attributes?
125
125
 
126
- consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret)
127
- token = OAuth::AccessToken.new(consumer)
128
- res = token.post(
129
- @lis_outcome_service_url,
130
- generate_request_xml,
131
- 'Content-Type' => 'application/xml'
132
- )
126
+ res = post_service_request(@lis_outcome_service_url,
127
+ 'application/xml',
128
+ generate_request_xml)
129
+
133
130
  @outcome_response = extend_outcome_response(OutcomeResponse.new)
134
131
  @outcome_response.process_post_response(res)
135
132
  end
@@ -0,0 +1,22 @@
1
+ module IMS::LTI
2
+ class ToolBase
3
+
4
+ # OAuth credentials
5
+ attr_accessor :consumer_key, :consumer_secret
6
+
7
+ def initialize(consumer_key, consumer_secret)
8
+ @consumer_key = consumer_key
9
+ @consumer_secret = consumer_secret
10
+ end
11
+
12
+ # Convenience method for doing oauth signed requests to services that
13
+ # aren't supported by this library
14
+ def post_service_request(url, content_type, body)
15
+ IMS::LTI::post_service_request(@consumer_key,
16
+ @consumer_secret,
17
+ url,
18
+ content_type,
19
+ body)
20
+ end
21
+ end
22
+ end
@@ -142,7 +142,7 @@ module IMS::LTI
142
142
  "xsi:schemaLocation" => "http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd"
143
143
  ) do |blti_node|
144
144
 
145
- %w{title description launch_url secure_launch_url}.each do |key|
145
+ %w{title description launch_url secure_launch_url icon secure_icon}.each do |key|
146
146
  blti_node.blti key.to_sym, self.send(key) if self.send(key)
147
147
  end
148
148
 
@@ -1,11 +1,11 @@
1
1
  module IMS::LTI
2
2
  # Class for implementing an LTI Tool Consumer
3
- class ToolConsumer
3
+ class ToolConsumer < ToolBase
4
4
  include IMS::LTI::Extensions::Base
5
5
  include IMS::LTI::LaunchParams
6
6
  include IMS::LTI::RequestValidator
7
7
 
8
- attr_accessor :consumer_key, :consumer_secret, :launch_url, :timestamp, :nonce
8
+ attr_accessor :launch_url, :timestamp, :nonce
9
9
 
10
10
  # Create a new ToolConsumer
11
11
  #
@@ -13,8 +13,7 @@ module IMS::LTI
13
13
  # @param consumer_secret [String] The OAuth consumer secret
14
14
  # @param params [Hash] Set the launch parameters as described in LaunchParams
15
15
  def initialize(consumer_key, consumer_secret, params={})
16
- @consumer_key = consumer_key
17
- @consumer_secret = consumer_secret
16
+ super(consumer_key, consumer_secret)
18
17
  @custom_params = {}
19
18
  @ext_params = {}
20
19
  @non_spec_params = {}
@@ -33,13 +33,11 @@ module IMS::LTI
33
33
  # # failed
34
34
  # end
35
35
 
36
- class ToolProvider
36
+ class ToolProvider < ToolBase
37
37
  include IMS::LTI::Extensions::Base
38
38
  include IMS::LTI::LaunchParams
39
39
  include IMS::LTI::RequestValidator
40
40
 
41
- # OAuth credentials
42
- attr_accessor :consumer_key, :consumer_secret
43
41
  # List of outcome requests made through this instance
44
42
  attr_accessor :outcome_requests
45
43
  # Message to be sent back to the ToolConsumer when the user returns
@@ -51,8 +49,7 @@ module IMS::LTI
51
49
  # @param consumer_secret [String] The OAuth consumer secret
52
50
  # @param params [Hash] Set the launch parameters as described in LaunchParams
53
51
  def initialize(consumer_key, consumer_secret, params={})
54
- @consumer_key = consumer_key
55
- @consumer_secret = consumer_secret
52
+ super(consumer_key, consumer_secret)
56
53
  @custom_params = {}
57
54
  @ext_params = {}
58
55
  @non_spec_params = {}
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ims-lti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
5
- prerelease:
4
+ version: 1.1.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Instructure
@@ -14,23 +13,20 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: builder
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: oauth
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,49 +41,43 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: uuid
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: ruby-debug
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description:
@@ -106,6 +95,7 @@ files:
106
95
  - lib/ims/lti/outcome_request.rb
107
96
  - lib/ims/lti/outcome_response.rb
108
97
  - lib/ims/lti/request_validator.rb
98
+ - lib/ims/lti/tool_base.rb
109
99
  - lib/ims/lti/tool_config.rb
110
100
  - lib/ims/lti/tool_consumer.rb
111
101
  - lib/ims/lti/tool_provider.rb
@@ -117,26 +107,25 @@ files:
117
107
  homepage: http://github.com/instructure/ims-lti
118
108
  licenses:
119
109
  - MIT
110
+ metadata: {}
120
111
  post_install_message:
121
112
  rdoc_options: []
122
113
  require_paths:
123
114
  - lib
124
115
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
116
  requirements:
127
- - - ! '>='
117
+ - - '>='
128
118
  - !ruby/object:Gem::Version
129
119
  version: '0'
130
120
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
121
  requirements:
133
- - - ! '>='
122
+ - - '>='
134
123
  - !ruby/object:Gem::Version
135
124
  version: '0'
136
125
  requirements: []
137
126
  rubyforge_project:
138
- rubygems_version: 1.8.23
127
+ rubygems_version: 2.0.14
139
128
  signing_key:
140
- specification_version: 3
129
+ specification_version: 4
141
130
  summary: Ruby library for creating IMS LTI tool providers and consumers
142
131
  test_files: []