senkyoshi 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 734aa6a4182cbe1cc084141e348a86de31e79e8f
4
- data.tar.gz: da8a96c3f60cd2b8afd6bde2633336db2838facf
3
+ metadata.gz: 6380890b182d57c03008d4c6893a0e7e319b4ad5
4
+ data.tar.gz: 1b9ed95c67cfd8f5f1e6ded91ad0c3af0ee98680
5
5
  SHA512:
6
- metadata.gz: 9c53c165560b8b087b256eadecb60b0f0106c3987532ba845155b1fcd905ef0db32f6fd0bd93e9e6bf869867f40d7961916f501047aa182db93372e3716175ed
7
- data.tar.gz: 90efec004135f970851a3a9c3e8c8d893bcf6930b3111811500302ec22f7be2706ddbfd54b616d45e97a349e1710948bef12097350fe7fb49bc6951ec7d6e7e5
6
+ metadata.gz: 9b2a316951726bd6ddfd757b2152990505ca298c96ed34a42f73f78276deca27fb83ea9b345d4e174caa67208e3d69f59b88a695c7247c6b2ce7f847e967c59f
7
+ data.tar.gz: cbe0c05994c6ed39aee696488d3fd868ef5f6af9d474ca908e645ba073ed74c98bca0fa402a5e945f941afe32a12a7eeb431439950d6840c6398470280181400
data/README.md CHANGED
@@ -71,9 +71,11 @@ Create a `senkyoshi.yml` and add credentials:
71
71
  # Adhesion, it would just be `scorm`.
72
72
  :scorm_oauth_consumer_key: <scorm oauth consumer key>
73
73
 
74
- # This is the secret to authenticate requests to the SCORM manager. In the case
75
- # of Adhesion, you can generate a shared secret by logging into the server and
76
- # running rake shared_auth, which will generate and save a token
74
+ # This is the shared id for the jwt aud. In the case of Adhesion it
75
+ # will be `adhesion`.
76
+ :scorm_shared_id: <scorm shared id>
77
+
78
+ # This is the secret used to create a jwt to communicate with the SCORM manager.
77
79
  :scorm_shared_auth: <scorm manager token>
78
80
 
79
81
  # The number of seconds before uploads timeout. Defaults to 1800 (30 minutes)
data/lib/auth_token.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "jwt"
2
+
3
+ module AuthToken
4
+
5
+ # More information on jwt available at
6
+ # http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#rfc.section.4.1.6
7
+ def self.issue_token(
8
+ payload = {},
9
+ exp = (Time.now + 86400),
10
+ secret = nil,
11
+ aud = nil
12
+ )
13
+ config = Senkyoshi.configuration
14
+ payload["iat"] = Time.now.to_i # issued at claim
15
+ payload["exp"] = exp.to_i # Default expiration set to 24 hours.
16
+ payload["aud"] = aud || config.scorm_shared_id
17
+ JWT.encode(
18
+ payload,
19
+ secret || config.scorm_shared_auth,
20
+ "HS512",
21
+ )
22
+ end
23
+
24
+ def self.valid?(token, secret = nil)
25
+ config = Senkyoshi.configuration
26
+ JWT.decode(token, secret || config.scorm_shared_auth)
27
+ end
28
+ end
@@ -16,6 +16,7 @@
16
16
  require "pandarus"
17
17
  require "senkyoshi/models/scorm_package"
18
18
  require "rest-client"
19
+ require "auth_token"
19
20
 
20
21
  module Senkyoshi
21
22
  ##
@@ -134,11 +135,39 @@ module Senkyoshi
134
135
  assignment__points_possible__: scorm_package["points_possible"],
135
136
  }
136
137
 
137
- CanvasCourse.client.create_assignment(
138
+ lms_assignment = CanvasCourse.client.create_assignment(
138
139
  course_id,
139
140
  scorm_package["title"],
140
141
  payload,
141
142
  )
143
+
144
+ lms_assignment_id = lms_assignment["id"]
145
+ points_possible = lms_assignment["points_possible"]
146
+ update_scorm_package(
147
+ scorm_package["package_id"],
148
+ lms_assignment_id,
149
+ points_possible,
150
+ )
151
+ end
152
+
153
+ ##
154
+ # Updates scorm manager with lms data for scorm course
155
+ ##
156
+ def update_scorm_package(package_id, lms_assignment_id, points_possible)
157
+ config = Senkyoshi.configuration
158
+ url = "#{config.scorm_url}/api/scorm_courses/#{package_id}"
159
+ RestClient.put(
160
+ url,
161
+ {
162
+ oauth_consumer_key: config.scorm_oauth_consumer_key,
163
+ shared_auth: true,
164
+ scorm_course: {
165
+ lms_assignment_id: lms_assignment_id,
166
+ points_possible: points_possible,
167
+ },
168
+ },
169
+ Authorization: "Bearer #{AuthToken.issue_token}",
170
+ )
142
171
  end
143
172
 
144
173
  ##
@@ -148,19 +177,23 @@ module Senkyoshi
148
177
  def upload_scorm_package(scorm_package, course_id, tmp_name)
149
178
  zip = scorm_package.write_zip tmp_name
150
179
  config = Senkyoshi.configuration
180
+ url = "#{config.scorm_url}/api/scorm_courses"
151
181
  File.open(zip, "rb") do |file|
152
182
  RestClient.post(
153
- "#{Senkyoshi.configuration.scorm_url}/api/scorm_courses",
183
+ url,
154
184
  {
155
185
  oauth_consumer_key: config.scorm_oauth_consumer_key,
156
186
  lms_course_id: course_id,
157
187
  file: file,
188
+ shared_auth: true,
158
189
  },
159
- SharedAuthorization: config.scorm_shared_auth,
190
+ Authorization: "Bearer #{AuthToken.issue_token}",
160
191
  ) do |resp|
161
- result = JSON.parse(resp.body)["response"]
162
- result["points_possible"] = scorm_package.points_possible
163
- result
192
+ result = JSON.parse(resp.body)
193
+ response = result["response"]
194
+ response["points_possible"] = scorm_package.points_possible
195
+ response["package_id"] = result["package_id"]
196
+ response
164
197
  end
165
198
  end
166
199
  end
@@ -22,7 +22,9 @@ module Senkyoshi
22
22
  attr_accessor :account_id
23
23
  attr_accessor :scorm_url
24
24
  attr_accessor :scorm_launch_url
25
+ attr_accessor :scorm_shared_id
25
26
  attr_accessor :scorm_shared_auth
27
+ attr_accessor :scorm_oauth_consumer_key
26
28
  attr_accessor :request_timeout
27
29
 
28
30
  DEFAULT_TIMEOUT = 1_800 # 30 minutes
@@ -33,7 +35,10 @@ module Senkyoshi
33
35
  @account_id = Configuration._config[:account_id] || :self
34
36
  @scorm_url = Configuration._config[:scorm_url]
35
37
  @scorm_launch_url = Configuration._config[:scorm_launch_url]
38
+ @scorm_shared_id = Configuration._config[:scorm_shared_id]
36
39
  @scorm_shared_auth = Configuration._config[:scorm_shared_auth]
40
+ @scorm_oauth_consumer_key =
41
+ Configuration._config[:scorm_oauth_consumer_key]
37
42
  @request_timeout =
38
43
  Configuration._config[:request_timeout] || DEFAULT_TIMEOUT
39
44
  end
@@ -14,5 +14,5 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  module Senkyoshi
17
- VERSION = "1.0.10".freeze
17
+ VERSION = "1.0.11".freeze
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senkyoshi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atomic Jolt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.6'
89
+ version: '1.8'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.6'
96
+ version: '1.8'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pandarus
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jwt
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.1'
139
153
  description: Commandline tool for converting blackboard to canvas
140
154
  email:
141
155
  executables:
@@ -149,6 +163,7 @@ files:
149
163
  - README.md
150
164
  - bin/console
151
165
  - bin/import_blackboard
166
+ - lib/auth_token.rb
152
167
  - lib/senkyoshi.rb
153
168
  - lib/senkyoshi/canvas_course.rb
154
169
  - lib/senkyoshi/collection.rb
@@ -225,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
240
  requirements:
226
241
  - - ">="
227
242
  - !ruby/object:Gem::Version
228
- version: '2.0'
243
+ version: '2.1'
229
244
  required_rubygems_version: !ruby/object:Gem::Requirement
230
245
  requirements:
231
246
  - - ">="
@@ -233,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
248
  version: '0'
234
249
  requirements: []
235
250
  rubyforge_project:
236
- rubygems_version: 2.6.13
251
+ rubygems_version: 2.6.11
237
252
  signing_key:
238
253
  specification_version: 4
239
254
  summary: Converts Blackboard zip file to Canvas Common Cartridge