lms-api 1.2.7 → 1.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24c84120ece41009fe047528839394f91d801e9f
4
- data.tar.gz: 7c07f89e2b00a8f41bfe437324b04bed8c6511d4
3
+ metadata.gz: 67b3b72f988679b53c1765c8865815d08be99ac2
4
+ data.tar.gz: 27a7f36cdcd20407e5d5ece8e41959a03a4083e5
5
5
  SHA512:
6
- metadata.gz: 83663596c06851b2ff53b9f3903f0ac259c489f6f836b573d2b1fcd0d342ac8c9538851e706c41a49671167788bedb506b310f2fe98e9a54185ea6098f80c709
7
- data.tar.gz: bdef58c1d1254908169d4e20259ea55654c25c595cc04577b16a1c78afb7e441c58f1d51282cc9d3dd1ffcd2fe3f7cb3e771f8d27eab080ba9e7657e08e407a8
6
+ metadata.gz: 70d881c7ff2b502d960832f59cb828d23342f09ced74671d0c0df3989a6f6a023e9d01526479399a1b10fab7eebf208b96282bd4f6db718b6651c17945f2ba09
7
+ data.tar.gz: aad199ea1ec1c3232b59e220e2e566512ae13ff4fd048608c56588b5f0240f6990fa48adab77f9e0b1e464dcdf01b47d5d71fd22ac2ca3ae2b4117975558134a
data/lib/lms/canvas.rb CHANGED
@@ -7,13 +7,10 @@ require "active_support/core_ext/hash/indifferent_access"
7
7
  require "ostruct"
8
8
 
9
9
  require "lms/canvas_urls"
10
+ require "lms/helper_urls"
10
11
 
11
12
  module LMS
12
13
 
13
- CANVAS_HELPER_URLs = {
14
- "HELPER_ALL_ACCOUNTS" => :all_accounts
15
- }
16
-
17
14
  class Canvas
18
15
 
19
16
  # a model that encapsulates authentication state. By default, it
@@ -205,8 +202,7 @@ module LMS
205
202
  end
206
203
  end
207
204
 
208
- def proxy(type, params, payload = nil, get_all = false)
209
-
205
+ def multi_proxy(type, params, payload = nil, get_all = false)
210
206
  # Helper methods call several Canvas methods to return a block of data to the client
211
207
  if helper = CANVAS_HELPER_URLs[type]
212
208
  result = self.send(helper)
@@ -216,7 +212,9 @@ module LMS
216
212
  body: result.to_json
217
213
  )
218
214
  end
215
+ end
219
216
 
217
+ def single_proxy(type, params, payload = nil, get_all = false)
220
218
  additional_headers = {
221
219
  "Content-Type" => "application/json"
222
220
  }
@@ -259,13 +257,27 @@ module LMS
259
257
  raise new_ex
260
258
  end
261
259
 
260
+ def proxy(type, params, payload = nil, get_all = false, &block)
261
+ multi_proxy(type, params, payload, get_all) ||
262
+ single_proxy(type, params, payload, get_all, &block)
263
+ end
264
+
262
265
  # Ignore required params for specific calls. For example, the external tool calls
263
266
  # have required params "name, privacy_level, consumer_key, shared_secret". However, those
264
267
  # params are not required if the call specifies config_type: "by_xml".
265
268
  def self.ignore_required(type)
266
269
  [
267
270
  "CREATE_EXTERNAL_TOOL_COURSES",
268
- "CREATE_EXTERNAL_TOOL_ACCOUNTS"
271
+ "CREATE_EXTERNAL_TOOL_ACCOUNTS",
272
+ ].include?(type)
273
+ end
274
+
275
+ # These methods allow custom paths to be appended to the API endpoint.
276
+ def self.allow_scoped_path(type)
277
+ [
278
+ "STORE_CUSTOM_DATA",
279
+ "LOAD_CUSTOM_DATA",
280
+ "DELETE_CUSTOM_DATA",
269
281
  ].include?(type)
270
282
  end
271
283
 
@@ -302,6 +314,14 @@ module LMS
302
314
  args = params.slice(*path_parameters).symbolize_keys
303
315
  uri = args.blank? ? uri_proc.call : uri_proc.call(**args)
304
316
 
317
+ # Handle scopes in the url. These API endpoints allow for additional path
318
+ # information to be added to their urls.
319
+ # ie "users/#{user_id}/custom_data/favorite_color/green"
320
+ if allow_scoped_path(type) &&
321
+ scope = params[:scope]&.gsub("../", "").gsub("..", "") # Don't allow moving up in the path
322
+ uri = File.join(uri, scope)
323
+ end
324
+
305
325
  # Generate the query string
306
326
  query_parameters = parameters.select { |p| p["paramType"] == "query" }.
307
327
  map { |p| p["name"].to_sym }
@@ -326,9 +346,9 @@ module LMS
326
346
  # Get all accounts including sub accounts
327
347
  def all_accounts
328
348
  all = []
329
- proxy("LIST_ACCOUNTS", {}, nil, true).each do |account|
349
+ single_proxy("LIST_ACCOUNTS", {}, nil, true).each do |account|
330
350
  all << account
331
- sub_accounts = proxy("GET_SUB_ACCOUNTS_OF_ACCOUNT",
351
+ sub_accounts = single_proxy("GET_SUB_ACCOUNTS_OF_ACCOUNT",
332
352
  {
333
353
  account_id: account["id"],
334
354
  recursive: true,
@@ -0,0 +1,8 @@
1
+
2
+ module LMS
3
+
4
+ CANVAS_HELPER_URLs = {
5
+ "HELPER_ALL_ACCOUNTS" => :all_accounts
6
+ }
7
+
8
+ end
data/lib/lms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMS
2
- VERSION = "1.2.7".freeze
2
+ VERSION = "1.2.8".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lms-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atomic Jolt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-23 00:00:00.000000000 Z
13
+ date: 2017-02-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -109,6 +109,7 @@ files:
109
109
  - Rakefile
110
110
  - lib/lms/canvas.rb
111
111
  - lib/lms/canvas_urls.rb
112
+ - lib/lms/helper_urls.rb
112
113
  - lib/lms/version.rb
113
114
  - lib/lms_api.rb
114
115
  - lib/tasks/canvas_api.rake