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 +4 -4
- data/README.md +5 -5
- data/lib/lms/canvas.rb +10 -10
- data/lib/lms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ac6777774b73bce211ffa0619cf743b26a69e4
|
4
|
+
data.tar.gz: e4f2e69442b6f8db3c977011ec7cc3096cc549bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e03f5dae671ec7b94ff0542e359c8caef1c7b00caf2fae2531e9d44fe6a4accaa1de24d076d9a20dc69e65f820ed7be1c9cc2825681f5e54262f8db222acb2aa
|
7
|
+
data.tar.gz: 3c5a656cf724dced157be0138f71c4b4c87db1fc2453cca72bb946bfef270d41a4523177d062cb673d7cc4d0ca198ccb639194cb1db6d4542e3159026069eb3d
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# LMS
|
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::
|
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::
|
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::
|
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::
|
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
|
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::
|
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::
|
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::
|
176
|
+
raise LMS::Canvas::RefreshTokenRequired
|
177
177
|
end
|
178
178
|
|
179
|
-
raise LMS::
|
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::
|
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::
|
222
|
+
raise LMS::Canvas::InvalidAPIMethodRequestException "Invalid method type: #{method}"
|
223
223
|
end
|
224
224
|
|
225
|
-
rescue LMS::
|
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::
|
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::
|
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
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.
|
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-
|
13
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|