lms-api 1.1.0 → 1.2.0

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: 9cd9d3fda8b686908615d43da2f995cc9293c387
4
- data.tar.gz: 6884ba67486fe5df7501ee4fca575ef1f693129c
3
+ metadata.gz: 12ac6777774b73bce211ffa0619cf743b26a69e4
4
+ data.tar.gz: e4f2e69442b6f8db3c977011ec7cc3096cc549bf
5
5
  SHA512:
6
- metadata.gz: e55e6673692a637243852608355d77cd150913b44da9f04c4be4ae99ba4a9caa19a97a71cfde0a1c0dcd6c6c890f27ecced2e577c041008432f7b6b00144c370
7
- data.tar.gz: f5b5e700a2d399ef5604425108eda9eb012629a376c87cf78e7946dc5cb0473cb3160a4edc5b9a6184e213c52585374a7c371350f113ad8b7b83abf8889b2ce2
6
+ metadata.gz: e03f5dae671ec7b94ff0542e359c8caef1c7b00caf2fae2531e9d44fe6a4accaa1de24d076d9a20dc69e65f820ed7be1c9cc2825681f5e54262f8db222acb2aa
7
+ data.tar.gz: 3c5a656cf724dced157be0138f71c4b4c87db1fc2453cca72bb946bfef270d41a4523177d062cb673d7cc4d0ca198ccb639194cb1db6d4542e3159026069eb3d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # LMS::API
1
+ # LMS API
2
2
 
3
3
  This project provides a wrapper around the Instructure Canvas API.
4
4
 
@@ -28,7 +28,7 @@ end
28
28
  Then, you tell the gem about this model:
29
29
 
30
30
  ```ruby
31
- LMS::API.auth_state_model = Authentication
31
+ LMS::Canvas.auth_state_model = Authentication
32
32
  ```
33
33
 
34
34
  This allows the gem to transparently refresh the token when the token
@@ -38,7 +38,7 @@ to do so in parallel.
38
38
 
39
39
  ## Usage
40
40
 
41
- To use the API wrapper, instantiate a `LMS::API` instance with the
41
+ To use the API wrapper, instantiate a `LMS::Canvas` instance with the
42
42
  url of the LMS instance you want to communicate with, as well as the
43
43
  current authentication object, and (optionally) a hash of options to use
44
44
  when refreshing the API token.
@@ -48,7 +48,7 @@ Require the gem:
48
48
 
49
49
  ```ruby
50
50
  auth = Authentication.first # or however you are storing global auth state
51
- api = LMS::API.new("http://your.canvas.instance", auth,
51
+ api = LMS::Canvas.new("http://your.canvas.instance", auth,
52
52
  client_id: "...",
53
53
  client_secret: "..."
54
54
  redirect_uri: "..."
@@ -67,7 +67,7 @@ params = {
67
67
  all_dates: true,
68
68
  other_param: "foobar"}
69
69
 
70
- url = LMS::API.lms_url("GET_SINGLE_ASSIGNMENT", params)
70
+ url = LMS::Canvas.lms_url("GET_SINGLE_ASSIGNMENT", params)
71
71
  ```
72
72
 
73
73
  Once you have the URL, you can send the request by using `api_*_request`
data/lib/lms/canvas.rb CHANGED
@@ -7,7 +7,7 @@ require "active_support/core_ext/hash/keys"
7
7
  require "lms/canvas_urls"
8
8
 
9
9
  module LMS
10
- class API
10
+ class Canvas
11
11
 
12
12
  # a model that encapsulates authentication state. By default, it
13
13
  # is nil, but it may be set to any object that responds to:
@@ -151,7 +151,7 @@ module LMS
151
151
  def refreshably
152
152
  result = yield
153
153
  check_result(result)
154
- rescue LMS::API::RefreshTokenRequired => ex
154
+ rescue LMS::Canvas::RefreshTokenRequired => ex
155
155
  raise ex if @refresh_token_options.blank?
156
156
  @authentication = @@on_auth.call(self)
157
157
  retry
@@ -163,7 +163,7 @@ module LMS
163
163
  }.merge(@refresh_token_options)
164
164
  url = full_url("login/oauth2/token", false)
165
165
  result = HTTParty.post(url, headers: headers, body: payload)
166
- raise LMS::API::RefreshTokenFailedException, api_error(result) unless [200, 201].include?(result.response.code.to_i)
166
+ raise LMS::Canvas::RefreshTokenFailedException, api_error(result) unless [200, 201].include?(result.response.code.to_i)
167
167
  result["access_token"]
168
168
  end
169
169
 
@@ -173,10 +173,10 @@ module LMS
173
173
  return result if [200, 201].include?(code)
174
174
 
175
175
  if code == 401 && result.headers["www-authenticate"] == 'Bearer realm="canvas-lms"'
176
- raise LMS::API::RefreshTokenRequired
176
+ raise LMS::Canvas::RefreshTokenRequired
177
177
  end
178
178
 
179
- raise LMS::API::InvalidAPIRequestException, api_error(result)
179
+ raise LMS::Canvas::InvalidAPIRequestException, api_error(result)
180
180
  end
181
181
 
182
182
  def api_error(result)
@@ -198,7 +198,7 @@ module LMS
198
198
  }
199
199
 
200
200
  method = LMS::CANVAS_URLs[type][:method]
201
- url = LMS::API.lms_url(type, params, payload)
201
+ url = LMS::Canvas.lms_url(type, params, payload)
202
202
  payload_json = payload.to_json
203
203
 
204
204
  case method
@@ -219,15 +219,15 @@ module LMS
219
219
  when "DELETE"
220
220
  api_delete_request(url, additional_headers)
221
221
  else
222
- raise LMS::API::InvalidAPIMethodRequestException "Invalid method type: #{method}"
222
+ raise LMS::Canvas::InvalidAPIMethodRequestException "Invalid method type: #{method}"
223
223
  end
224
224
 
225
- rescue LMS::API::InvalidAPIRequestException => ex
225
+ rescue LMS::Canvas::InvalidAPIRequestException => ex
226
226
  error = ex.to_s
227
227
  error << "API Request Url: #{url} \n"
228
228
  error << "API Request Params: #{params} \n"
229
229
  error << "API Request Payload: #{payload} \n"
230
- new_ex = LMS::API::InvalidAPIRequestFailedException.new(error)
230
+ new_ex = LMS::Canvas::InvalidAPIRequestFailedException.new(error)
231
231
  new_ex.set_backtrace(ex.backtrace)
232
232
  raise new_ex
233
233
  end
@@ -263,7 +263,7 @@ module LMS
263
263
  end
264
264
 
265
265
  if missing.length > 0
266
- raise LMS::API::MissingRequiredParameterException, "Missing required parameter(s): #{missing.join(', ')}"
266
+ raise LMS::Canvas::MissingRequiredParameterException, "Missing required parameter(s): #{missing.join(', ')}"
267
267
  end
268
268
 
269
269
  # Generate the uri. Only allow path parameters
data/lib/lms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMS
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
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.1.0
4
+ version: 1.2.0
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-14 00:00:00.000000000 Z
13
+ date: 2016-12-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport