quiz_api_client 0.1.3 → 0.1.4

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: a7510dde6f3ff21858b72aa6fc3054583b210b9b
4
- data.tar.gz: c5354fba783d3dc1399afae7462ac6d112568430
3
+ metadata.gz: b4bf29ac754ada773490f0576569a0a204226669
4
+ data.tar.gz: 0c3cf4baae7eaa570c2e3186377cd1f9d121883f
5
5
  SHA512:
6
- metadata.gz: 3868dd59280ee8c59b3517d12ba5fd31e88c77ae9649736ef5d4b6c1083e133c6a1e40269143279e0a44d1f0c2588b824f462c3b32cf72345c198fd0423456b8
7
- data.tar.gz: a453ef98e547383558b24f78f57992f5ecae5f62660e980821b6aad22cca4ffe86e33f56ced23676c7f28550c7843127553e7151438e2c4877383543bd9b5279
6
+ metadata.gz: cceeefa90889b19abcdd0bf516db220096469924b573b83beaac864ff0ed610508a7f48d15be57e0b911c4c9cae18256b5f62dfc0ef2a9d43122f27f65f511ed
7
+ data.tar.gz: ab7b4bfb05c414ca931d8c00d0d1cdbdfbe0841f44754bfbcb1a0e15b37cf0a9f6d58f413351a001f6793667b94b6abaf2f752281eee71e0d5bbc4c3b959fa28
data/.dockerignore ADDED
@@ -0,0 +1,4 @@
1
+ /coverage
2
+ /docker-compose.yml
3
+ /Dockerfile
4
+ /**/*.gem
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/Dockerfile ADDED
@@ -0,0 +1,23 @@
1
+ FROM instructure/ruby:2.3
2
+
3
+ USER root
4
+
5
+ RUN apt-get update \
6
+ && apt-get install -y unzip \
7
+ && apt-get clean \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ ENV LANG C.UTF-8
11
+ WORKDIR /app
12
+
13
+ COPY Gemfile quiz_api_client.gemspec Gemfile.lock /app/
14
+ COPY . /app
15
+ RUN chown -R docker:docker /app
16
+
17
+ USER docker
18
+ RUN bundle install --jobs 8
19
+ USER root
20
+
21
+ RUN mkdir -p /app/coverage && chown -R docker:docker /app
22
+
23
+ USER docker
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+
6
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ quiz_api_client (0.1.4)
5
+ httparty
6
+ jwt
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.0)
12
+ public_suffix (~> 2.0, >= 2.0.2)
13
+ coderay (1.1.1)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ docile (1.1.5)
18
+ hashdiff (0.3.2)
19
+ httparty (0.14.0)
20
+ multi_xml (>= 0.5.2)
21
+ json (2.0.3)
22
+ jwt (1.5.6)
23
+ method_source (0.8.2)
24
+ multi_xml (0.6.0)
25
+ pry (0.10.4)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.8.1)
28
+ slop (~> 3.4)
29
+ public_suffix (2.0.5)
30
+ rake (10.4.2)
31
+ rspec (3.5.0)
32
+ rspec-core (~> 3.5.0)
33
+ rspec-expectations (~> 3.5.0)
34
+ rspec-mocks (~> 3.5.0)
35
+ rspec-core (3.5.4)
36
+ rspec-support (~> 3.5.0)
37
+ rspec-expectations (3.5.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.5.0)
40
+ rspec-mocks (3.5.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.5.0)
43
+ rspec-support (3.5.0)
44
+ safe_yaml (1.0.4)
45
+ simplecov (0.13.0)
46
+ docile (~> 1.1.0)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.0)
50
+ slop (3.6.0)
51
+ webmock (2.3.2)
52
+ addressable (>= 2.3.6)
53
+ crack (>= 0.3.2)
54
+ hashdiff
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 1.12)
61
+ pry
62
+ quiz_api_client!
63
+ rake (~> 10.0)
64
+ rspec (~> 3.0)
65
+ simplecov
66
+ webmock
67
+
68
+ BUNDLED WITH
69
+ 1.14.3
data/README.md CHANGED
@@ -150,6 +150,100 @@ client.quiz_sessions_service.create(
150
150
  )
151
151
  ```
152
152
 
153
+ #### QTI Imports Service
154
+
155
+ **Tokens**
156
+ ```ruby
157
+ # Generate token: Create Qti Import
158
+ client.qti_imports_service.token(
159
+ scope: client.quizzes_service.scope_create,
160
+ exp: some_expiration
161
+ )
162
+ ```
163
+
164
+ **API Calls**
165
+ ```ruby
166
+ # Create QTI Import
167
+ client.qti_imports_service.create(
168
+ params: {
169
+ quiz_id: quiz_id_to_create_import_under,
170
+ qti_import: {
171
+ url: url where QTI Export is stored
172
+ }
173
+ }
174
+ )
175
+ ```
176
+
177
+ #### Item Analyses Service
178
+
179
+ **Tokens**
180
+ ```ruby
181
+ # Generate token: Fetch Item Analyses
182
+ client.item_analyses_service.token(
183
+ scope: client.item_analyses_service.scope_analysis,
184
+ exp: some_expiration
185
+ )
186
+ ```
187
+
188
+ **API Calls**
189
+ ```ruby
190
+ # List item analyses
191
+ client.item_analyses_service.list(
192
+ params: {
193
+ quiz_id: quiz_id_to_list_items_under
194
+ }
195
+ )
196
+ # get specific item analysis
197
+ client.item_analyses_service.get(
198
+ params: {
199
+ quiz_id: quiz_id_to_list_items_under,
200
+ id: item_id_to_get_under
201
+ }
202
+ )
203
+ ```
204
+
205
+ #### Quiz Analyses Service
206
+
207
+ **Tokens**
208
+ ```ruby
209
+ # Generate token: Fetch Quiz Analyses
210
+ client.quiz_analyses_service.token(
211
+ scope: client.quiz_analyses_service.scope_analysis,
212
+ exp: some_expiration
213
+ )
214
+ ```
215
+
216
+ **API Calls**
217
+ ```ruby
218
+ # get specific item analysis
219
+ client.quiz_analyses_service.get(
220
+ params: {
221
+ quiz_id: quiz_id_to_get_analysis
222
+ }
223
+ )
224
+ ```
225
+
226
+ #### Quiz Session Events Service
227
+
228
+ **Tokens**
229
+ ```ruby
230
+ # Generate token: Fetch Quiz Session Events
231
+ client.quiz_session_events_service.token(
232
+ scope: client.quiz_session_events_service.scope_list,
233
+ exp: some_expiration
234
+ )
235
+ ```
236
+
237
+ **API Calls**
238
+ ```ruby
239
+ # list quiz session events
240
+ client.quiz_session_events_service.list(
241
+ params: {
242
+ quiz_session_id: quiz_session_id_to_get_events_under
243
+ }
244
+ )
245
+ ```
246
+
153
247
  ## Development
154
248
 
155
249
  After checking out the repo, run `bin/setup` to install dependencies.
data/build.sh ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ export COMPOSE_PROJECT_NAME=api_client
4
+
5
+ function cleanup() {
6
+ exit_code=$?
7
+ set +e
8
+
9
+ docker rmi -f $(docker images -qf "dangling=true") &>/dev/null
10
+ exit $exit_code
11
+ }
12
+ trap cleanup INT TERM EXIT
13
+
14
+ set -e
15
+
16
+ docker-compose build --pull
17
+
18
+ echo "Running test suite..."
19
+ docker-compose run -d testrunner bash -c 'bundle exec rspec && sleep 10'
20
+ docker-compose run testrunner bundle exec rspec
21
+
22
+ docker cp $(docker-compose ps -q testrunner):/app/coverage .
@@ -0,0 +1,5 @@
1
+ version: '2'
2
+
3
+ services:
4
+ testrunner:
5
+ build: .
@@ -1,9 +1,13 @@
1
1
  require 'quiz_api_client/version'
2
+ require 'quiz_api_client/services/qti_imports_service'
2
3
  require 'quiz_api_client/services/quiz_service'
3
4
  require 'quiz_api_client/services/quizzes_service'
4
5
  require 'quiz_api_client/services/quiz_sessions_service'
5
6
  require 'quiz_api_client/services/quiz_session_service'
6
7
  require 'quiz_api_client/services/quiz_sessions_service'
8
+ require 'quiz_api_client/services/item_analyses_service'
9
+ require 'quiz_api_client/services/quiz_analyses_service'
10
+ require 'quiz_api_client/services/quiz_session_events_service'
7
11
 
8
12
  module QuizApiClient
9
13
  class Client
@@ -17,16 +21,38 @@ module QuizApiClient
17
21
  end
18
22
 
19
23
  def quiz_service
20
- @_quiz_service ||= Services::QuizService.new(
24
+ @_quiz_service ||= Services::QuizService.new(service_params)
25
+ end
26
+
27
+ def quizzes_service
28
+ @_quizzes_service ||= Services::QuizzesService.new(service_params)
29
+ end
30
+
31
+ def quiz_session_service
32
+ @_quiz_session_service ||= Services::QuizSessionService.new(service_params)
33
+ end
34
+
35
+ def quiz_sessions_service
36
+ @_quiz_sessions_service ||= Services::QuizSessionsService.new(service_params)
37
+ end
38
+
39
+ def qti_imports_service
40
+ @_qti_imports_service ||= Services::QtiImportsService.new(service_params)
41
+ end
42
+
43
+ private
44
+
45
+ def service_params
46
+ {
21
47
  consumer_key: consumer_key,
22
48
  host: host,
23
49
  shared_secret: shared_secret,
24
50
  protocol: protocol
25
- )
51
+ }
26
52
  end
27
53
 
28
- def quizzes_service
29
- @_quizzes_service ||= Services::QuizzesService.new(
54
+ def item_analyses_service
55
+ @_item_analyses_service ||= Services::ItemAnalysesService.new(
30
56
  consumer_key: consumer_key,
31
57
  host: host,
32
58
  shared_secret: shared_secret,
@@ -34,8 +60,8 @@ module QuizApiClient
34
60
  )
35
61
  end
36
62
 
37
- def quiz_session_service
38
- @_quiz_session_service ||= Services::QuizSessionService.new(
63
+ def quiz_analyses_service
64
+ @_quiz_analyses_service ||= Services::QuizAnalysesService.new(
39
65
  consumer_key: consumer_key,
40
66
  host: host,
41
67
  shared_secret: shared_secret,
@@ -43,8 +69,8 @@ module QuizApiClient
43
69
  )
44
70
  end
45
71
 
46
- def quiz_sessions_service
47
- @_quiz_sessions_service ||= Services::QuizSessionsService.new(
72
+ def quiz_session_events_service
73
+ @_quiz_session_events_service ||= Services::QuizSessionEventsService.new(
48
74
  consumer_key: consumer_key,
49
75
  host: host,
50
76
  shared_secret: shared_secret,
@@ -0,0 +1,36 @@
1
+ require 'quiz_api_client/services/base_api_service'
2
+
3
+ module QuizApiClient::Services
4
+ class ItemAnalysesService < BaseApiService
5
+ def token(scope:, exp: nil, resource_id: nil)
6
+ return unless allowed_scopes.include?(scope)
7
+ generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
+ end
9
+
10
+ def list(params:, default_token: nil)
11
+ raise 'Quiz Id Required' unless params.key?(:quiz_id)
12
+ client(token: token_for_api(default_token, scope_analysis, params[:quiz_id])).get(
13
+ "/api/quizzes/#{params[:quiz_id]}/stats/item_analyses",
14
+ {}
15
+ )
16
+ end
17
+
18
+ def get(params:, default_token: nil)
19
+ raise 'Quiz Id and Item Id are Required' unless params.key?(:id) && params.key?(:quiz_id)
20
+ client(token: token_for_api(default_token, scope_analysis, params[:quiz_id])).get(
21
+ "/api/quizzes/#{params[:quiz_id]}/stats/item_analyses/#{params[:id]}",
22
+ {}
23
+ )
24
+ end
25
+
26
+ def scope_analysis
27
+ 'quiz.analysis'
28
+ end
29
+
30
+ private
31
+
32
+ def allowed_scopes
33
+ [scope_analysis]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ require 'quiz_api_client/services/base_api_service'
2
+
3
+ module QuizApiClient::Services
4
+ class QtiImportsService < BaseApiService
5
+ def token(scope:, exp: nil, resource_id: nil)
6
+ return unless allowed_scopes.include?(scope)
7
+ generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
+ end
9
+
10
+ def create(params:, default_token: nil)
11
+ raise 'Quiz Id Required' unless params && params[:quiz_id]
12
+ post_to_quiz_api(params: params, token: token_for_api(default_token, scope_create, params[:quiz_id]))
13
+ end
14
+
15
+ def scope_create
16
+ 'qti_import.create'
17
+ end
18
+
19
+ private
20
+
21
+ def post_to_quiz_api(params:, token:)
22
+ client(token: token).post(
23
+ "/api/quizzes/#{params[:quiz_id]}/qti_imports",
24
+ qti_import: params
25
+ )
26
+ end
27
+
28
+ def allowed_scopes
29
+ [scope_create]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'quiz_api_client/services/base_api_service'
2
+
3
+ module QuizApiClient::Services
4
+ class QuizAnalysesService < BaseApiService
5
+ def token(scope:, exp: nil, resource_id: nil)
6
+ return unless allowed_scopes.include?(scope)
7
+ generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
+ end
9
+
10
+ def get(params:, default_token: nil)
11
+ raise 'Quiz Id Required' unless params.key?(:quiz_id)
12
+ get_from_quiz_api(params: params, token: token_for_api(default_token, scope_analysis, params[:quiz_id]))
13
+ end
14
+
15
+ def scope_analysis
16
+ 'quiz.analysis'
17
+ end
18
+
19
+ private
20
+
21
+ def get_from_quiz_api(params:, token:)
22
+ client(token: token).get(
23
+ "/api/quizzes/#{params[:quiz_id]}/stats/quiz_analysis",
24
+ {}
25
+ )
26
+ end
27
+
28
+ def allowed_scopes
29
+ [scope_analysis]
30
+ end
31
+ end
32
+ end
@@ -3,13 +3,18 @@ require 'quiz_api_client/services/base_api_service'
3
3
  module QuizApiClient::Services
4
4
  class QuizService < BaseApiService
5
5
  def token(scope:, exp: nil, resource_id: nil)
6
- return unless scope == scope_build
6
+ return unless allowed_scopes.include?(scope)
7
7
  generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
8
  end
9
9
 
10
- # Allowed scopes
11
10
  def scope_build
12
11
  'quiz.build'
13
12
  end
13
+
14
+ private
15
+
16
+ def allowed_scopes
17
+ [scope_build]
18
+ end
14
19
  end
15
20
  end
@@ -0,0 +1,32 @@
1
+ require 'quiz_api_client/services/base_api_service'
2
+
3
+ module QuizApiClient::Services
4
+ class QuizSessionEventsService < BaseApiService
5
+ def token(scope:, exp: nil, resource_id: nil)
6
+ return unless allowed_scopes.include?(scope)
7
+ generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
+ end
9
+
10
+ def list(params:, default_token: nil)
11
+ raise 'Quiz Session Id Required' unless params.key?(:quiz_session_id)
12
+ get_from_quiz_api(params: params, token: token_for_api(default_token, scope_list, params[:quiz_session_id]))
13
+ end
14
+
15
+ def scope_list
16
+ 'quiz_session.take'
17
+ end
18
+
19
+ private
20
+
21
+ def get_from_quiz_api(params:, token:)
22
+ client(token: token).get(
23
+ "/api/quiz_sessions/#{params[:quiz_session_id]}/quiz_session_events",
24
+ {}
25
+ )
26
+ end
27
+
28
+ def allowed_scopes
29
+ [scope_list]
30
+ end
31
+ end
32
+ end
@@ -3,7 +3,7 @@ require 'quiz_api_client/services/base_api_service'
3
3
  module QuizApiClient::Services
4
4
  class QuizSessionService < BaseApiService
5
5
  def token(scope:, exp: nil, resource_id: nil)
6
- return unless (scope == scope_update) || (scope == scope_take)
6
+ return unless allowed_scopes.include?(scope)
7
7
  generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
8
  end
9
9
 
@@ -11,7 +11,6 @@ module QuizApiClient::Services
11
11
  patch_to_quiz_api(params: params, token: token_for_api(default_token, scope_update, params[:id]))
12
12
  end
13
13
 
14
- # Allowed scopes
15
14
  def scope_update
16
15
  'quiz_session.update'
17
16
  end
@@ -28,5 +27,9 @@ module QuizApiClient::Services
28
27
  quiz_session: params
29
28
  )
30
29
  end
30
+
31
+ def allowed_scopes
32
+ [scope_update, scope_take]
33
+ end
31
34
  end
32
35
  end
@@ -3,7 +3,7 @@ require 'quiz_api_client/services/base_api_service'
3
3
  module QuizApiClient::Services
4
4
  class QuizSessionsService < BaseApiService
5
5
  def token(scope:, exp: nil, resource_id: nil)
6
- return unless (scope == scope_create) || (scope == scope_list)
6
+ return unless allowed_scopes.include?(scope)
7
7
  generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
8
  end
9
9
 
@@ -12,7 +12,6 @@ module QuizApiClient::Services
12
12
  post_to_quiz_api(params: params, token: token_for_api(default_token, scope_create, params[:quiz_id]))
13
13
  end
14
14
 
15
- # Allowed scopes
16
15
  def scope_create
17
16
  'quiz_session.create'
18
17
  end
@@ -29,5 +28,9 @@ module QuizApiClient::Services
29
28
  quiz_session: params
30
29
  )
31
30
  end
31
+
32
+ def allowed_scopes
33
+ [scope_create, scope_list]
34
+ end
32
35
  end
33
36
  end
@@ -3,7 +3,7 @@ require 'quiz_api_client/services/base_api_service'
3
3
  module QuizApiClient::Services
4
4
  class QuizzesService < BaseApiService
5
5
  def token(scope:, exp: nil, resource_id: nil)
6
- return unless (scope == scope_create) || (scope == scope_list)
6
+ return unless allowed_scopes.include?(scope)
7
7
  generate_token(scope: scope, exp: exp, resource_id: resource_id)
8
8
  end
9
9
 
@@ -15,7 +15,6 @@ module QuizApiClient::Services
15
15
  get_from_quiz_api(params: params, token: token_for_api(default_token, scope_list))
16
16
  end
17
17
 
18
- ## Allowed scopes
19
18
  def scope_create
20
19
  'quiz.create'
21
20
  end
@@ -39,5 +38,9 @@ module QuizApiClient::Services
39
38
  params
40
39
  )
41
40
  end
41
+
42
+ def allowed_scopes
43
+ [scope_create, scope_list]
44
+ end
42
45
  end
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quiz_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -115,20 +115,29 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".dockerignore"
118
119
  - ".editorconfig"
119
120
  - ".gitignore"
120
121
  - ".rspec"
121
122
  - ".rubocop.yml"
123
+ - Dockerfile
122
124
  - Gemfile
125
+ - Gemfile.lock
123
126
  - README.md
124
127
  - Rakefile
125
128
  - bin/console
126
129
  - bin/setup
130
+ - build.sh
131
+ - docker-compose.yml
127
132
  - lib/quiz_api_client.rb
128
133
  - lib/quiz_api_client/http_client.rb
129
134
  - lib/quiz_api_client/services/base_api_service.rb
135
+ - lib/quiz_api_client/services/item_analyses_service.rb
130
136
  - lib/quiz_api_client/services/jwt_service.rb
137
+ - lib/quiz_api_client/services/qti_imports_service.rb
138
+ - lib/quiz_api_client/services/quiz_analyses_service.rb
131
139
  - lib/quiz_api_client/services/quiz_service.rb
140
+ - lib/quiz_api_client/services/quiz_session_events_service.rb
132
141
  - lib/quiz_api_client/services/quiz_session_service.rb
133
142
  - lib/quiz_api_client/services/quiz_sessions_service.rb
134
143
  - lib/quiz_api_client/services/quizzes_service.rb