lms-api 1.2.3 → 1.2.4

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: 31cd2969fb85d7b0594f8a168c76104f521e9705
4
- data.tar.gz: 85d5ea9a8c6cd17c6f0e9d902eb340dabcac9114
3
+ metadata.gz: 32377199608ae195be9f19c7f77dd605ead04f14
4
+ data.tar.gz: b85788d8c68781b28c35469ae45ff9d081315f72
5
5
  SHA512:
6
- metadata.gz: 7f5bd2e2aaec03c9ff5bf15927009117706954a6680793408147f9fbe701ff0007edcd4fa3ece85fbc84a812f5f508ffa5e6e98b6151053802b316e45a9d1dd4
7
- data.tar.gz: abda015f052117b144ae795d0d8626ae143390c16ecdef7c35d33fc350a8b8f6eeffcfe679e89f387efaa943c1e53c445367a6cca1d65d7b4af37ed4e42094a1
6
+ metadata.gz: a7240adaed7b9ff946afddafa74134b034b2325d8d0bd024b1e5ad0ff0fa1e95db78e7bbe2500c3f260dd08b493b87dd47473ae0cc84e4fffa642250d4cef212
7
+ data.tar.gz: 9a4d9bb8f56e159a3db8fe391dfa8eedd1f673b37abf51cf0a2a0caf34cbe625b930868dc05789bf30d978fee7493e099a2ffab90cb71e7b1354f58b665b97ee
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 Atomic Jolt
1
+ Copyright 2016-2017 Atomic Jolt
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,25 +1,25 @@
1
1
  begin
2
- require 'bundler/setup'
2
+ require "bundler/setup"
3
3
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
5
  end
6
6
 
7
- require 'rdoc/task'
7
+ require "rdoc/task"
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'LMS API'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "LMS API"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.rdoc")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
15
  end
16
16
 
17
- load './lib/tasks/canvas_api.rake'
17
+ load "./lib/tasks/canvas_api.rake"
18
18
 
19
19
  Bundler::GemHelper.install_tasks
20
20
 
21
21
  begin
22
- require 'rspec/core/rake_task'
22
+ require "rspec/core/rake_task"
23
23
  RSpec::Core::RakeTask.new(:spec)
24
24
 
25
25
  task default: :spec
data/lib/lms/canvas.rb CHANGED
@@ -3,6 +3,7 @@ require "active_support"
3
3
  require "active_support/core_ext/object/blank"
4
4
  require "active_support/core_ext/object/to_query"
5
5
  require "active_support/core_ext/hash/keys"
6
+ require "active_support/core_ext/hash/indifferent_access"
6
7
 
7
8
  require "lms/canvas_urls"
8
9
 
@@ -33,7 +34,7 @@ module LMS
33
34
  # set up a default auth callback. It assumes that #auth_state_model
34
35
  # is set. If #auth_state_model will not be set, the client app must
35
36
  # define a custom on_auth callback.
36
- self.on_auth do |api|
37
+ on_auth do |api|
37
38
  api.lock do |record|
38
39
  if record.token == api.authentication.token
39
40
  record.update token: api.refresh_token
@@ -52,18 +53,24 @@ module LMS
52
53
  @per_page = 100
53
54
  @lms_uri = lms_uri
54
55
  @refresh_token_options = refresh_token_options
55
- if authentication.is_a?(String)
56
- @authentication = OpenStruct.new(token: authentication)
57
- else
58
- @authentication = authentication
59
- end
56
+ @authentication = if authentication.is_a?(String)
57
+ OpenStruct.new(token: authentication)
58
+ else
59
+ authentication
60
+ end
60
61
 
61
62
  if refresh_token_options.present?
62
63
  required_options = [:client_id, :client_secret, :redirect_uri, :refresh_token]
63
64
  extra_options = @refresh_token_options.keys - required_options
64
- raise InvalidRefreshOptionsException, "Invalid option(s) provided: #{extra_options.join(', ')}" unless extra_options.length == 0
65
+ unless extra_options.empty?
66
+ raise InvalidRefreshOptionsException,
67
+ "Invalid option(s) provided: #{extra_options.join(', ')}"
68
+ end
65
69
  missing_options = required_options - @refresh_token_options.keys
66
- raise InvalidRefreshOptionsException, "Missing required option(s): #{missing_options.join(', ')}" unless missing_options.length == 0
70
+ unless missing_options.empty?
71
+ raise InvalidRefreshOptionsException,
72
+ "Missing required option(s): #{missing_options.join(', ')}"
73
+ end
67
74
  end
68
75
  end
69
76
 
@@ -93,12 +100,10 @@ module LMS
93
100
  def full_url(api_url, use_api_prefix = true)
94
101
  if api_url[0...4] == "http"
95
102
  api_url
103
+ elsif use_api_prefix
104
+ "#{@lms_uri}/api/v1/#{api_url}"
96
105
  else
97
- if use_api_prefix
98
- "#{@lms_uri}/api/v1/#{api_url}"
99
- else
100
- "#{@lms_uri}/#{api_url}"
101
- end
106
+ "#{@lms_uri}/#{api_url}"
102
107
  end
103
108
  end
104
109
 
@@ -141,7 +146,7 @@ module LMS
141
146
  def api_get_blocks_request(api_url, additional_headers = {})
142
147
  connector = api_url.include?("?") ? "&" : "?"
143
148
  next_url = "#{api_url}#{connector}per_page=#{@per_page}"
144
- while next_url do
149
+ while next_url
145
150
  result = api_get_request(next_url, additional_headers)
146
151
  yield result
147
152
  next_url = get_next_url(result.headers["link"])
@@ -163,7 +168,9 @@ module LMS
163
168
  }.merge(@refresh_token_options)
164
169
  url = full_url("login/oauth2/token", false)
165
170
  result = HTTParty.post(url, headers: headers, body: payload)
166
- raise LMS::Canvas::RefreshTokenFailedException, api_error(result) unless [200, 201].include?(result.response.code.to_i)
171
+ unless [200, 201].include?(result.response.code.to_i)
172
+ raise LMS::Canvas::RefreshTokenFailedException, api_error(result)
173
+ end
167
174
  result["access_token"]
168
175
  end
169
176
 
@@ -187,7 +194,7 @@ module LMS
187
194
 
188
195
  def get_next_url(link)
189
196
  return nil if link.blank?
190
- if url = link.split(",").find{ |l| l.split(";")[1].strip == 'rel="next"' }
197
+ if url = link.split(",").detect { |l| l.split(";")[1].strip == 'rel="next"' }
191
198
  url.split(";")[0].gsub(/[\<\>\s]/, "")
192
199
  end
193
200
  end
@@ -199,9 +206,10 @@ module LMS
199
206
  payload = {} if payload.blank?
200
207
  payload_json = payload.is_a?(String) ? payload : payload.to_json
201
208
  parsed_payload = payload.is_a?(String) ? JSON.parse(payload) : payload
209
+ parsed_payload = parsed_payload.with_indifferent_access
202
210
 
203
211
  method = LMS::CANVAS_URLs[type][:method]
204
- url = LMS::Canvas.lms_url(type, params, payload)
212
+ url = LMS::Canvas.lms_url(type, params, parsed_payload)
205
213
 
206
214
  case method
207
215
  when "GET"
@@ -250,32 +258,36 @@ module LMS
250
258
 
251
259
  # Make sure all required parameters are present
252
260
  missing = []
253
- if !self.ignore_required(type)
254
- parameters.find_all{|p| p["required"]}.map{|p| p["name"]}.each do |p|
261
+ if !ignore_required(type)
262
+ parameters.select { |p| p["required"] }.map { |p| p["name"] }.each do |p|
255
263
  if p.include?("[") && p.include?("]")
256
- parts = p.split('[')
264
+ parts = p.split("[")
257
265
  parent = parts[0].to_sym
258
266
  child = parts[1].gsub("]", "").to_sym
259
267
  missing << p unless (params[parent].present? && params[parent][child].present?) ||
260
- (payload.present? && payload[parent].present? && payload[parent][child].present?)
268
+ (payload.present? && payload[parent].present? && payload[parent][child].present?)
261
269
  else
262
- missing << p unless params[p.to_sym].present? || (payload.present? && !payload.is_a?(String) && payload[p.to_sym].present?)
270
+ missing << p unless params[p.to_sym].present? ||
271
+ (payload.present? && !payload.is_a?(String) && payload[p.to_sym].present?)
263
272
  end
264
273
  end
265
274
  end
266
275
 
267
- if missing.length > 0
268
- raise LMS::Canvas::MissingRequiredParameterException, "Missing required parameter(s): #{missing.join(', ')}"
276
+ if !missing.empty?
277
+ raise LMS::Canvas::MissingRequiredParameterException,
278
+ "Missing required parameter(s): #{missing.join(', ')}"
269
279
  end
270
280
 
271
281
  # Generate the uri. Only allow path parameters
272
282
  uri_proc = endpoint[:uri]
273
- path_parameters = parameters.find_all{|p| p["paramType"] == "path"}.map{|p| p["name"].to_sym}
283
+ path_parameters = parameters.select { |p| p["paramType"] == "path" }.
284
+ map { |p| p["name"].to_sym }
274
285
  args = params.slice(*path_parameters).symbolize_keys
275
286
  uri = args.blank? ? uri_proc.call : uri_proc.call(**args)
276
287
 
277
288
  # Generate the query string
278
- query_parameters = parameters.find_all{ |p| p["paramType"] == "query" }.map{ |p| p["name"].to_sym }
289
+ query_parameters = parameters.select { |p| p["paramType"] == "query" }.
290
+ map { |p| p["name"].to_sym }
279
291
 
280
292
  # always allow paging parameters
281
293
  query_parameters << :per_page
@@ -297,9 +309,12 @@ module LMS
297
309
  # Get all accounts including sub accounts
298
310
  def all_accounts
299
311
  all = []
300
- self.proxy("LIST_ACCOUNTS", {}, nil, true).each do |account|
312
+ proxy("LIST_ACCOUNTS", {}, nil, true).each do |account|
301
313
  all << account
302
- sub_accounts = self.proxy("GET_SUB_ACCOUNTS_OF_ACCOUNT", {account_id: account['id']}, nil, true)
314
+ sub_accounts = proxy("GET_SUB_ACCOUNTS_OF_ACCOUNT",
315
+ { account_id: account["id"] },
316
+ nil,
317
+ true)
303
318
  all = all.concat(sub_accounts)
304
319
  end
305
320
  all
@@ -309,28 +324,28 @@ module LMS
309
324
  # Exceptions
310
325
  #
311
326
 
312
- class Exception < RuntimeError
327
+ class CanvasException < RuntimeError
313
328
  end
314
329
 
315
- class RefreshTokenRequired < Exception
330
+ class RefreshTokenRequired < CanvasException
316
331
  end
317
332
 
318
- class InvalidRefreshOptionsException < Exception
333
+ class InvalidRefreshOptionsException < CanvasException
319
334
  end
320
335
 
321
- class RefreshTokenFailedException < Exception
336
+ class RefreshTokenFailedException < CanvasException
322
337
  end
323
338
 
324
- class InvalidAPIRequestException < Exception
339
+ class InvalidAPIRequestException < CanvasException
325
340
  end
326
341
 
327
- class InvalidAPIRequestFailedException < Exception
342
+ class InvalidAPIRequestFailedException < CanvasException
328
343
  end
329
344
 
330
- class InvalidAPIMethodRequestException < Exception
345
+ class InvalidAPIMethodRequestException < CanvasException
331
346
  end
332
347
 
333
- class MissingRequiredParameterException < Exception
348
+ class MissingRequiredParameterException < CanvasException
334
349
  end
335
350
 
336
351
  end
data/lib/lms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMS
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -16,11 +16,11 @@ namespace :canvas do
16
16
  graphql_primitive(type, property["format"])
17
17
  when "array"
18
18
  begin
19
- if property["items"]["$ref"]
20
- type = property["items"]["$ref"]
21
- else
22
- type = graphql_primitive(property["items"]["type"], property["items"]["format"])
23
- end
19
+ type = if property["items"]["$ref"]
20
+ property["items"]["$ref"]
21
+ else
22
+ graphql_primitive(property["items"]["type"], property["items"]["format"])
23
+ end
24
24
  rescue
25
25
  type = "GraphQLString"
26
26
  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.3
4
+ version: 1.2.4
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: 2016-12-22 00:00:00.000000000 Z
13
+ date: 2017-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -82,6 +82,20 @@ dependencies:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: byebug
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
85
99
  description: Wrapper for the Instructure Canvas API
86
100
  email:
87
101
  - jamis@jamisbuck.org
@@ -130,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
144
  version: '0'
131
145
  requirements: []
132
146
  rubyforge_project:
133
- rubygems_version: 2.5.1
147
+ rubygems_version: 2.6.8
134
148
  signing_key:
135
149
  specification_version: 4
136
150
  summary: Wrapper for the Instructure Canvas API