qalam_oauth_engine 3.0.4 → 3.0.8

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
  SHA256:
3
- metadata.gz: e153aaa7541aee767fe47cb0824831482a12f392f1bd87803ee4ad4703e7d30f
4
- data.tar.gz: '0494829ca2a3a9d94c7ddee7ca5b853de2df985e74e1d3f142f1d805578826ad'
3
+ metadata.gz: a94aa9f960fad372ccd1ce843c502f7f1f8011f010e29dd095224a0d9a5c701f
4
+ data.tar.gz: a1f11ff92ae13c52c42271180623616cbf47cd42780e34e3f029a30c6143fe44
5
5
  SHA512:
6
- metadata.gz: 2bca130d4a82b30db36ebb3fb1a6208db2b7cc6350cd97e8c1a9e9ada3498e0d3f431f2c4f626db35bfeb03e540e27a1b9e5543487380da2b9b73783b4b6d0cc
7
- data.tar.gz: 91a7d377612aa1e3d5036e730348224c7c0d0f60f0aa1635d4c4f1f6f6d7d847f6c9f40430bb3538d4e6cb8638893d2b6ccf0f631aebdcd6768953cb1ab293df
6
+ metadata.gz: 8540835b1a123aae6f271195d80443a7627649dc2156c1ec2a6f0e6be6295d99f0669815b5e11250b7b0c7f70c7811d901158107ed1e2424934a0de3ba2c3d7b
7
+ data.tar.gz: f01b816cc088416ffa80ddfd5908ae40bded8ac8e11f8c784ead5317fd82a3d4039b424aa29cfff82aad4756c5776bbcdc291ec8116ebec48776dd2cb0a3b5a1
@@ -23,13 +23,13 @@ module CanvasOauth
23
23
  def verify_oauth2_state(callback_state)
24
24
  callback_state.present? && callback_state == session.delete(:oauth2_state)
25
25
  end
26
- end
27
26
 
28
- def set_root_account
29
- if current_account_id
30
- @root_account_id = canvas.root_account_id(current_account_id)
31
- elsif current_course_id
32
- @root_account_id = canvas.course_root_account_id(current_course_id)
27
+ def set_root_account
28
+ if session[:account_id]
29
+ @root_account_id = canvas.root_account_id(session[:account_id])
30
+ elsif session[:course_id]
31
+ @root_account_id = canvas.course_root_account_id(session[:course_id])
32
+ end
33
33
  end
34
34
  end
35
35
  end
@@ -4,7 +4,7 @@ module CanvasOauth
4
4
  PER_PAGE = 50
5
5
 
6
6
  attr_accessor :token, :refresh_token, :key, :secret
7
- attr_reader :canvas_url, :canvas_user_id
7
+ attr_reader :canvas_url, :canvas_user_id, :canvas_root_account_id
8
8
 
9
9
  def initialize(canvas_url, canvas_user_id, canvas_root_account_id, token, refresh_token, key, secret)
10
10
  unless [key, secret].all?(&:present?)
@@ -104,18 +104,23 @@ module CanvasOauth
104
104
  authenticated_request(:put, *params)
105
105
  end
106
106
 
107
- def paginated_get(url, params = {})
107
+ def paginated_get(url, params={})
108
108
  params[:query] ||= {}
109
- params[:query][:per_page] = PER_PAGE
110
-
109
+ params[:query][:per_page] ||= PER_PAGE
110
+ params[:query][:page] ||= 1
111
111
  all_pages = []
112
112
 
113
- while url && current_page = authenticated_get(url, params) do
113
+ if params[:current_page]
114
+ current_page = authenticated_get(url, params)
114
115
  all_pages.concat(current_page) if valid_page?(current_page)
116
+ else
117
+ while url && current_page = authenticated_get(url, params) do
118
+ all_pages.concat(current_page) if valid_page?(current_page)
115
119
 
116
- links = LinkHeader.parse(current_page.headers['link'])
117
- url = links.find_link(["rel", "next"]).try(:href)
118
- params[:query] = nil if params[:query]
120
+ links = LinkHeader.parse(current_page.headers['link'])
121
+ url = links.find_link(["rel", "next"]).try(:href)
122
+ params[:query] = nil if params[:query]
123
+ end
119
124
  end
120
125
 
121
126
  all_pages
@@ -195,7 +200,7 @@ module CanvasOauth
195
200
  # root_account_id
196
201
  # course_root_account_id
197
202
 
198
- def get_report(account_id, report_type, params)
203
+ def get_report(account_id, report_type, params={})
199
204
  report = authenticated_post("/api/v1/accounts/#{account_id}/reports/#{report_type}", { body: params })
200
205
  report = authenticated_get "/api/v1/accounts/#{account_id}/reports/#{report_type}/#{report['id']}"
201
206
  while (report['status'] == 'created' || report['status'] == 'running')
@@ -212,108 +217,108 @@ module CanvasOauth
212
217
  end
213
218
  end
214
219
 
215
- def get_file(file_id)
220
+ def get_file(file_id, params={})
216
221
  authenticated_get "/api/v1/files/#{file_id}"
217
222
  end
218
223
 
219
- def get_accounts_provisioning_report(account_id)
224
+ def get_accounts_provisioning_report(account_id, params={})
220
225
  get_report(account_id, :provisioning_csv, 'parameters[accounts]' => true)
221
226
  end
222
227
 
223
- def get_courses
228
+ def get_courses(params={})
224
229
  paginated_get "/api/v1/courses"
225
230
  end
226
231
 
227
- def get_account(account_id)
232
+ def get_account(account_id, params={})
228
233
  authenticated_get "/api/v1/accounts/#{account_id}"
229
234
  end
230
235
 
231
- def get_account_sub_accounts(account_id)
236
+ def get_account_sub_accounts(account_id, params={})
232
237
  paginated_get "/api/v1/accounts/#{account_id}/sub_accounts", { query: { :recursive => true } }
233
238
  end
234
239
 
235
- def get_account_courses(account_id)
240
+ def get_account_courses(account_id, params={})
236
241
  paginated_get "/api/v1/accounts/#{account_id}/courses"
237
242
  end
238
243
 
239
- def get_account_users(account_id)
244
+ def get_account_users(account_id, params={})
240
245
  paginated_get "/api/v1/accounts/#{account_id}/users"
241
246
  end
242
247
 
243
- def get_course(course_id)
248
+ def get_course(course_id, params={})
244
249
  authenticated_get "/api/v1/courses/#{course_id}"
245
250
  end
246
251
 
247
- def get_section_enrollments(section_id)
252
+ def get_section_enrollments(section_id, params={})
248
253
  paginated_get "/api/v1/sections/#{section_id}/enrollments"
249
254
  end
250
255
 
251
- def get_user_enrollments(user_id)
256
+ def get_user_enrollments(user_id, params={})
252
257
  paginated_get "/api/v1/users/#{user_id}/enrollments"
253
258
  end
254
259
 
255
- def get_course_users(course_id)
260
+ def get_course_users(course_id, params={})
256
261
  paginated_get "/api/v1/courses/#{course_id}/users"
257
262
  end
258
263
 
259
- def get_all_course_users(course_id)
264
+ def get_all_course_users(course_id, params={})
260
265
  paginated_get "/api/v1/courses/#{course_id}/users", { query: {enrollment_state: ["active","invited","rejected","completed","inactive"] } }
261
266
  end
262
267
 
263
- def get_course_teachers_and_tas(course_id)
268
+ def get_course_teachers_and_tas(course_id, params={})
264
269
  paginated_get "/api/v1/courses/#{course_id}/users", { query: { enrollment_type: ['teacher', 'ta'] } }
265
270
  end
266
271
 
267
- def get_course_students(course_id)
272
+ def get_course_students(course_id, params={})
268
273
  paginated_get "/api/v1/courses/#{course_id}/students"
269
274
  end
270
275
 
271
- def get_course_active_students(course_id)
276
+ def get_course_active_students(course_id, params={})
272
277
  paginated_get "/api/v1/courses/#{course_id}/active_users"
273
278
  end
274
279
 
275
- def get_section(section_id)
280
+ def get_section(section_id, params={})
276
281
  authenticated_get "/api/v1/sections/#{section_id}"
277
282
  end
278
283
 
279
- def get_sections(course_id)
284
+ def get_sections(course_id, params={})
280
285
  paginated_get "/api/v1/courses/#{course_id}/sections", { query: { :include => ['students', 'avatar_url', 'enrollments'] } }
281
286
  end
282
287
 
283
- def get_assignments(course_id)
288
+ def get_assignments(course_id, params={})
284
289
  paginated_get "/api/v1/courses/#{course_id}/assignments"
285
290
  end
286
291
 
287
- def get_assignment(course_id, assignment_id)
292
+ def get_assignment(course_id, assignment_id, params={})
288
293
  authenticated_get "/api/v1/courses/#{course_id}/assignments/#{assignment_id}"
289
294
  end
290
295
 
291
- def get_user_profile(user_id)
296
+ def get_user_profile(user_id, params={})
292
297
  authenticated_get "/api/v1/users/#{user_id}/profile"
293
298
  end
294
299
 
295
- def create_assignment(course_id, params)
300
+ def create_assignment(course_id, params={})
296
301
  authenticated_post "/api/v1/courses/#{course_id}/assignments", { body: { assignment: params } }
297
302
  end
298
303
 
299
- def update_assignment(course_id, assignment_id, params)
304
+ def update_assignment(course_id, assignment_id, params={})
300
305
  authenticated_put "/api/v1/courses/#{course_id}/assignments/#{assignment_id}", { body: { assignment: params } }
301
306
  end
302
307
 
303
- def grade_assignment(course_id, assignment_id, user_id, params)
308
+ def grade_assignment(course_id, assignment_id, user_id, params={})
304
309
  authenticated_put "/api/v1/courses/#{course_id}/assignments/#{assignment_id}/submissions/#{user_id}", { body: params }
305
310
  end
306
311
 
307
- def get_submission(course_id, assignment_id, user_id)
312
+ def get_submission(course_id, assignment_id, user_id, params={})
308
313
  authenticated_get "/api/v1/courses/#{course_id}/assignments/#{assignment_id}/submissions/#{user_id}"
309
314
  end
310
315
 
311
- def course_account_id(course_id)
316
+ def course_account_id(course_id, params={})
312
317
  course = get_course(course_id)
313
318
  course['account_id'] if course
314
319
  end
315
320
 
316
- def root_account_id(account_id)
321
+ def root_account_id(account_id, params={})
317
322
  if account_id && account = get_account(account_id)
318
323
  root_id = account['root_account_id']
319
324
  end
@@ -321,7 +326,7 @@ module CanvasOauth
321
326
  root_id || account_id
322
327
  end
323
328
 
324
- def course_root_account_id(course_id)
329
+ def course_root_account_id(course_id, params={})
325
330
  root_account_id(course_account_id(course_id))
326
331
  end
327
332
  ### END CANVAS API ###
@@ -329,44 +334,84 @@ module CanvasOauth
329
334
  ### QALAM API ENDPOINTS ###
330
335
  # get_canvas_user_profile
331
336
  # get_course_active_pages
332
- # course_external_tool_update
333
- # account_external_tool_update
337
+ # update_external_tool_nav
334
338
  # get_school_details
335
- # get_grade_students
336
- # get_classroom_students
337
-
338
- def get_canvas_user_profile
339
+ # get_school_grades
340
+ # get_school_grade
341
+ # get_school_class_rooms
342
+ # get_school_class_room
343
+ # get_school_subjects
344
+ # get_school_subject
345
+ # get_students_by_grade
346
+ # get_students_by_class_room
347
+
348
+ def get_canvas_user_profile(params={})
339
349
  authenticated_get "/api/v1/users/#{canvas_user_id}/profile"
340
350
  end
341
351
 
342
- def get_course_active_pages(course_id, publish=nil)
352
+ def get_course_active_pages(course_id, publish=nil, params={})
343
353
  unless publish.nil?
344
- paginated_get "/api/v1/courses/#{course_id}/pages?published=#{publish}&sort=created_at&order=desc"
354
+ paginated_get "/api/v1/courses/#{course_id}/pages?published=#{publish}&sort=created_at&order=desc", params
345
355
  else
346
- paginated_get "/api/v1/courses/#{course_id}/pages?sort=created_at&order=desc"
356
+ paginated_get "/api/v1/courses/#{course_id}/pages?sort=created_at&order=desc", params
347
357
  end
348
358
  end
349
359
 
350
- def course_external_tool_update(external_tool_url, tool_id, account_id, publish)
351
- authenticated_put "/api/v1/accounts/#{account_id}/external_tools_url", { body: {"course_navigation"=>{"enabled"=>"#{publish}"},
352
- "tool_id"=>tool_id, "external_tool_url"=>external_tool_url} }
360
+ def update_external_tool_nav(external_tool_url, tool_id, publish, type, account_id=@canvas_root_account_id, params={})
361
+ account_id ||= @canvas_root_account_id
362
+ if type == 'account'
363
+ body = {"account_navigation"=>{"enabled"=>"#{publish}"},
364
+ "tool_id"=>tool_id, "external_tool_url"=>external_tool_url}
365
+ elsif type == 'course'
366
+ body = {"course_navigation"=>{"enabled"=>"#{publish}"},
367
+ "tool_id"=>tool_id, "external_tool_url"=>external_tool_url}
368
+ end
369
+ authenticated_put "/api/v1/accounts/#{account_id}/external_tools_url", { body: body } if body
353
370
  end
354
371
 
355
- def account_external_tool_update(external_tool_url, tool_id, account_id, publish)
356
- authenticated_put "/api/v1/accounts/#{account_id}/external_tools_url", { body: {"account_navigation"=>{"enabled"=>"#{publish}"},
357
- "tool_id"=>tool_id, "external_tool_url"=>external_tool_url} }
372
+ def get_school_details(account_id=@canvas_root_account_id, params={})
373
+ account_id ||= @canvas_root_account_id
374
+ authenticated_get "/api/v1/accounts/#{account_id}/school_details"
358
375
  end
359
376
 
360
- def get_school_details(account_id)
361
- authenticated_get "/api/v1/accounts/#{account_id}/school_details"
377
+ def get_school_grades(account_id=@canvas_root_account_id, params={})
378
+ account_id ||= @canvas_root_account_id
379
+ paginated_get "/api/v1/accounts/#{account_id}/school_grades", params
380
+ end
381
+
382
+ def get_school_grade(grade_id, account_id=@canvas_root_account_id, params={})
383
+ account_id ||= @canvas_root_account_id
384
+ authenticated_get "/api/v1/accounts/#{account_id}/school_grades/#{grade_id}", params
385
+ end
386
+
387
+ def get_school_subjects(account_id=@canvas_root_account_id, params={})
388
+ account_id ||= @canvas_root_account_id
389
+ paginated_get "/api/v1/accounts/#{account_id}/school_subjects", params
390
+ end
391
+
392
+ def get_school_subject(subject_id, account_id=@canvas_root_account_id, params={})
393
+ account_id ||= @canvas_root_account_id
394
+ authenticated_get "/api/v1/accounts/#{account_id}/school_subjects/#{subject_id}", params
395
+ end
396
+
397
+ def get_school_class_rooms(account_id=@canvas_root_account_id, params={})
398
+ account_id ||= @canvas_root_account_id
399
+ paginated_get "/api/v1/accounts/#{account_id}/school_class_rooms", params
400
+ end
401
+
402
+ def get_school_class_room(class_room_id, account_id=@canvas_root_account_id, params={})
403
+ account_id ||= @canvas_root_account_id
404
+ authenticated_get "/api/v1/accounts/#{account_id}/school_class_rooms/#{class_room_id}", params
362
405
  end
363
406
 
364
- def get_grade_students(account_id, grade_id)
365
- paginated_get "/api/v1/accounts/#{account_id}/grade_students/#{grade_id}"
407
+ def get_students_by_grade(grade_id, account_id=@canvas_root_account_id, params={})
408
+ account_id ||= @canvas_root_account_id
409
+ paginated_get "/api/v1/accounts/#{account_id}/grade_students/#{grade_id}", params
366
410
  end
367
411
 
368
- def get_classroom_students(account_id, class_id)
369
- paginated_get "/api/v1/accounts/#{account_id}/classroom_students/#{class_id}"
412
+ def get_students_by_class_room(class_room_id, account_id=@canvas_root_account_id, params={})
413
+ account_id ||= @canvas_root_account_id
414
+ paginated_get "/api/v1/accounts/#{account_id}/class_room_students/#{class_room_id}", params
370
415
  end
371
416
  ### END QALAM API ###
372
417
  end
@@ -1,7 +1,7 @@
1
1
  module CanvasOauth
2
2
  class CanvasApiExtensions
3
3
  def self.build(canvas_url, user_id, tool_consumer_instance_guid)
4
- account_id = CanvasOauth::Authorization.fetch_ccount(user_id, tool_consumer_instance_guid)
4
+ account_id = CanvasOauth::Authorization.fetch_account(user_id, tool_consumer_instance_guid)
5
5
  token = CanvasOauth::Authorization.fetch_token(user_id, tool_consumer_instance_guid)
6
6
  refresh_token = CanvasOauth::Authorization.fetch_refresh_token(user_id, tool_consumer_instance_guid)
7
7
  canvas_key = ((CanvasLtiKey.table_exists? && CanvasLtiKey.find_by(canvas_url: canvas_url)&.key) or CanvasConfig.key)
@@ -1,3 +1,3 @@
1
1
  module CanvasOauth
2
- VERSION = "3.0.4"
2
+ VERSION = "3.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qalam_oauth_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Donahue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-08-22 00:00:00.000000000 Z
14
+ date: 2021-08-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty