openstax_exchange 0.1.0 → 0.2.0
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.
- data/lib/openstax/exchange/client_instance.rb +4 -0
- data/lib/openstax/exchange/exchange.rb +8 -0
- data/lib/openstax/exchange/fake_client/fake_client.rb +19 -0
- data/lib/openstax/exchange/real_client/real_client.rb +18 -0
- data/lib/openstax/exchange/version.rb +1 -1
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/duplicate_identifer_resource_trial_triplet/records_the_new_grade.yml +198 -0
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/invalid_resource_string/raises_an_exception.yml +148 -0
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_identifiers_to_be_saved.yml +249 -0
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_resources_to_be_saved.yml +198 -0
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_trials_to_be_saved.yml +198 -0
- data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/records_the_exercise_grade_for_the_given_identifier.yml +149 -0
- data/spec/lib/openstax/exchange/shared_examples_for_exchange_client_v1.rb +178 -8
- metadata +16 -4
@@ -100,7 +100,8 @@ RSpec.shared_examples "exchange client api v1" do
|
|
100
100
|
answer_string = 'answer_string'
|
101
101
|
|
102
102
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
103
|
-
identifier, resource_string, trial, answer_string
|
103
|
+
identifier, resource_string, trial, answer_string
|
104
|
+
)
|
104
105
|
|
105
106
|
expect(response['identifier']).to eq(identifier)
|
106
107
|
expect(response['resource']).to eq(resource_string)
|
@@ -121,13 +122,15 @@ RSpec.shared_examples "exchange client api v1" do
|
|
121
122
|
|
122
123
|
expect {
|
123
124
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
124
|
-
identifier1, resource_string, trial, answer_string
|
125
|
+
identifier1, resource_string, trial, answer_string
|
126
|
+
)
|
125
127
|
}.to_not raise_error
|
126
128
|
expect(response['identifier']).to eq(identifier1)
|
127
129
|
|
128
130
|
expect {
|
129
131
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
130
|
-
identifier2, resource_string, trial, answer_string
|
132
|
+
identifier2, resource_string, trial, answer_string
|
133
|
+
)
|
131
134
|
}.to_not raise_error
|
132
135
|
expect(response['identifier']).to eq(identifier2)
|
133
136
|
end
|
@@ -145,13 +148,15 @@ RSpec.shared_examples "exchange client api v1" do
|
|
145
148
|
|
146
149
|
expect {
|
147
150
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
148
|
-
identifier, resource_string1, trial, answer_string
|
151
|
+
identifier, resource_string1, trial, answer_string
|
152
|
+
)
|
149
153
|
}.to_not raise_error
|
150
154
|
expect(response['resource']).to eq(resource_string1)
|
151
155
|
|
152
156
|
expect {
|
153
157
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
154
|
-
identifier, resource_string2, trial, answer_string
|
158
|
+
identifier, resource_string2, trial, answer_string
|
159
|
+
)
|
155
160
|
}.to_not raise_error
|
156
161
|
expect(response['resource']).to eq(resource_string2)
|
157
162
|
end
|
@@ -169,13 +174,15 @@ RSpec.shared_examples "exchange client api v1" do
|
|
169
174
|
|
170
175
|
expect {
|
171
176
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
172
|
-
identifier, resource_string, trial1, answer_string
|
177
|
+
identifier, resource_string, trial1, answer_string
|
178
|
+
)
|
173
179
|
}.to_not raise_error
|
174
180
|
expect(response['trial']).to eq(trial1)
|
175
181
|
|
176
182
|
expect {
|
177
183
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
178
|
-
identifier, resource_string, trial2, answer_string
|
184
|
+
identifier, resource_string, trial2, answer_string
|
185
|
+
)
|
179
186
|
}.to_not raise_error
|
180
187
|
expect(response['trial']).to eq(trial2)
|
181
188
|
end
|
@@ -191,17 +198,22 @@ RSpec.shared_examples "exchange client api v1" do
|
|
191
198
|
answer_string = 'answer_string'
|
192
199
|
answer_string_2 = 'another_string'
|
193
200
|
|
201
|
+
response = nil
|
194
202
|
expect {
|
195
203
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
196
204
|
identifier, resource_string, trial, answer_string
|
197
205
|
)
|
198
206
|
}.to_not raise_error
|
199
207
|
|
208
|
+
expect(response['answer']).to eq answer_string
|
209
|
+
|
200
210
|
expect {
|
201
211
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
202
212
|
identifier, resource_string, trial, answer_string_2
|
203
213
|
)
|
204
214
|
}.to_not raise_error
|
215
|
+
|
216
|
+
expect(response['answer']).to eq answer_string_2
|
205
217
|
end
|
206
218
|
end
|
207
219
|
context "invalid resource string" do
|
@@ -216,7 +228,165 @@ RSpec.shared_examples "exchange client api v1" do
|
|
216
228
|
|
217
229
|
expect {
|
218
230
|
response = OpenStax::Exchange.record_multiple_choice_answer(
|
219
|
-
identifier, resource_string, trial, answer_string
|
231
|
+
identifier, resource_string, trial, answer_string
|
232
|
+
)
|
233
|
+
}.to raise_error(OpenStax::Exchange::ClientError)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "#record_grade" do
|
239
|
+
context "success" do
|
240
|
+
it "records the exercise grade for the given identifier" do
|
241
|
+
identifier = OpenStax::Exchange.create_identifiers.write
|
242
|
+
|
243
|
+
# must have the form of a "trusted resource"
|
244
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
245
|
+
resource_string = 'https://exercises-dev1.openstax.org/api/exercises/123@1'
|
246
|
+
trial = '1'
|
247
|
+
grade_string = '1.0'
|
248
|
+
grader_string = 'openstax'
|
249
|
+
|
250
|
+
response = OpenStax::Exchange.record_grade(
|
251
|
+
identifier, resource_string, trial, grade_string, grader_string
|
252
|
+
)
|
253
|
+
|
254
|
+
expect(response['identifier']).to eq(identifier)
|
255
|
+
expect(response['resource']).to eq(resource_string)
|
256
|
+
expect(response['trial']).to eq(trial)
|
257
|
+
expect(response['grade']).to eq(grade_string)
|
258
|
+
expect(response['grader']).to eq(grader_string)
|
259
|
+
end
|
260
|
+
it "allows grades for distinct identifiers to be saved" do
|
261
|
+
identifier1 = OpenStax::Exchange.create_identifiers.write
|
262
|
+
identifier2 = OpenStax::Exchange.create_identifiers.write
|
263
|
+
|
264
|
+
# must have the form of a "trusted resource"
|
265
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
266
|
+
resource_string = 'https://exercises-dev1.openstax.org/api/exercises/123@1'
|
267
|
+
trial = '1'
|
268
|
+
grade_string = '1.0'
|
269
|
+
grader_string = 'openstax'
|
270
|
+
|
271
|
+
response = nil
|
272
|
+
|
273
|
+
expect {
|
274
|
+
response = OpenStax::Exchange.record_grade(
|
275
|
+
identifier1, resource_string, trial, grade_string, grader_string
|
276
|
+
)
|
277
|
+
}.to_not raise_error
|
278
|
+
expect(response['identifier']).to eq(identifier1)
|
279
|
+
|
280
|
+
expect {
|
281
|
+
response = OpenStax::Exchange.record_grade(
|
282
|
+
identifier2, resource_string, trial, grade_string, grader_string
|
283
|
+
)
|
284
|
+
}.to_not raise_error
|
285
|
+
expect(response['identifier']).to eq(identifier2)
|
286
|
+
end
|
287
|
+
it "allows grades for distinct resources to be saved" do
|
288
|
+
identifier = OpenStax::Exchange.create_identifiers.write
|
289
|
+
|
290
|
+
# must have the form of a "trusted resource"
|
291
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
292
|
+
resource_string1 = 'https://exercises-dev1.openstax.org/api/exercises/12@1'
|
293
|
+
resource_string2 = 'https://exercises-dev1.openstax.org/api/exercises/123@1'
|
294
|
+
trial = '1'
|
295
|
+
grade_string = '1.0'
|
296
|
+
grader_string = 'openstax'
|
297
|
+
|
298
|
+
response = nil
|
299
|
+
|
300
|
+
expect {
|
301
|
+
response = OpenStax::Exchange.record_grade(
|
302
|
+
identifier, resource_string1, trial, grade_string, grader_string
|
303
|
+
)
|
304
|
+
}.to_not raise_error
|
305
|
+
expect(response['resource']).to eq(resource_string1)
|
306
|
+
|
307
|
+
expect {
|
308
|
+
response = OpenStax::Exchange.record_grade(
|
309
|
+
identifier, resource_string2, trial, grade_string, grader_string
|
310
|
+
)
|
311
|
+
}.to_not raise_error
|
312
|
+
expect(response['resource']).to eq(resource_string2)
|
313
|
+
end
|
314
|
+
it "allows grades for distinct trials to be saved" do
|
315
|
+
identifier = OpenStax::Exchange.create_identifiers.write
|
316
|
+
|
317
|
+
# must have the form of a "trusted resource"
|
318
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
319
|
+
resource_string = 'https://exercises-dev1.openstax.org/api/exercises/123@1'
|
320
|
+
trial1 = '1'
|
321
|
+
trial2 = '2'
|
322
|
+
grade_string = '1.0'
|
323
|
+
grader_string = 'openstax'
|
324
|
+
|
325
|
+
response = nil
|
326
|
+
|
327
|
+
expect {
|
328
|
+
response = OpenStax::Exchange.record_grade(
|
329
|
+
identifier, resource_string, trial1, grade_string, grader_string
|
330
|
+
)
|
331
|
+
}.to_not raise_error
|
332
|
+
expect(response['trial']).to eq(trial1)
|
333
|
+
|
334
|
+
expect {
|
335
|
+
response = OpenStax::Exchange.record_grade(
|
336
|
+
identifier, resource_string, trial2, grade_string, grader_string
|
337
|
+
)
|
338
|
+
}.to_not raise_error
|
339
|
+
expect(response['trial']).to eq(trial2)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
context "duplicate (identifer,resource,trial) triplet" do
|
343
|
+
it "records the new grade" do
|
344
|
+
identifier = OpenStax::Exchange.create_identifiers.write
|
345
|
+
|
346
|
+
# must have the form of a "trusted resource"
|
347
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
348
|
+
resource_string = 'https://exercises-dev1.openstax.org/api/exercises/123@1'
|
349
|
+
trial = '1'
|
350
|
+
grade_string = '0.0'
|
351
|
+
grade_string_2 = '1.0'
|
352
|
+
grader_string = 'openstax'
|
353
|
+
grader_string_2 = 'tutor'
|
354
|
+
|
355
|
+
response = nil
|
356
|
+
expect {
|
357
|
+
response = OpenStax::Exchange.record_grade(
|
358
|
+
identifier, resource_string, trial, grade_string, grader_string
|
359
|
+
)
|
360
|
+
}.to_not raise_error
|
361
|
+
|
362
|
+
expect(response['grade']).to eq grade_string
|
363
|
+
expect(response['grader']).to eq grader_string
|
364
|
+
|
365
|
+
expect {
|
366
|
+
response = OpenStax::Exchange.record_grade(
|
367
|
+
identifier, resource_string, trial, grade_string_2, grader_string_2
|
368
|
+
)
|
369
|
+
}.to_not raise_error
|
370
|
+
|
371
|
+
expect(response['grade']).to eq grade_string_2
|
372
|
+
expect(response['grader']).to eq grader_string_2
|
373
|
+
end
|
374
|
+
end
|
375
|
+
context "invalid resource string" do
|
376
|
+
it "raises an exception" do
|
377
|
+
identifier = OpenStax::Exchange.create_identifiers.write
|
378
|
+
|
379
|
+
# must have the form of a "trusted resource"
|
380
|
+
# (Exchange app/routines/find_or_create_resource_from_url.rb:35)
|
381
|
+
resource_string = 'https://example.com/api/exercises/123@1'
|
382
|
+
trial = '1'
|
383
|
+
grade_string = '1.0'
|
384
|
+
grader_string = 'openstax'
|
385
|
+
|
386
|
+
expect {
|
387
|
+
response = OpenStax::Exchange.record_grade(
|
388
|
+
identifier, resource_string, trial, grade_string, grader_string
|
389
|
+
)
|
220
390
|
}.to raise_error(OpenStax::Exchange::ClientError)
|
221
391
|
end
|
222
392
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -173,6 +173,12 @@ files:
|
|
173
173
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_id/raises_an_exception.yml
|
174
174
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_secret/raises_an_exception.yml
|
175
175
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/success/initializes_the_authentication_token.yml
|
176
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/duplicate_identifer_resource_trial_triplet/records_the_new_grade.yml
|
177
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/invalid_resource_string/raises_an_exception.yml
|
178
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_identifiers_to_be_saved.yml
|
179
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_resources_to_be_saved.yml
|
180
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_trials_to_be_saved.yml
|
181
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/records_the_exercise_grade_for_the_given_identifier.yml
|
176
182
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/duplicate_identifer_resource_trial_triplet/records_the_new_answer.yml
|
177
183
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/invalid_resource_string/raises_an_exception.yml
|
178
184
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/allows_answers_with_distinct_identifiers_to_be_saved.yml
|
@@ -199,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
205
|
version: '0'
|
200
206
|
segments:
|
201
207
|
- 0
|
202
|
-
hash:
|
208
|
+
hash: 911800936954346073
|
203
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
210
|
none: false
|
205
211
|
requirements:
|
@@ -208,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
214
|
version: '0'
|
209
215
|
segments:
|
210
216
|
- 0
|
211
|
-
hash:
|
217
|
+
hash: 911800936954346073
|
212
218
|
requirements: []
|
213
219
|
rubyforge_project:
|
214
220
|
rubygems_version: 1.8.23.2
|
@@ -224,6 +230,12 @@ test_files:
|
|
224
230
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_id/raises_an_exception.yml
|
225
231
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_secret/raises_an_exception.yml
|
226
232
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/success/initializes_the_authentication_token.yml
|
233
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/duplicate_identifer_resource_trial_triplet/records_the_new_grade.yml
|
234
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/invalid_resource_string/raises_an_exception.yml
|
235
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_identifiers_to_be_saved.yml
|
236
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_resources_to_be_saved.yml
|
237
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/allows_grades_for_distinct_trials_to_be_saved.yml
|
238
|
+
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_grade/success/records_the_exercise_grade_for_the_given_identifier.yml
|
227
239
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/duplicate_identifer_resource_trial_triplet/records_the_new_answer.yml
|
228
240
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/invalid_resource_string/raises_an_exception.yml
|
229
241
|
- spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/allows_answers_with_distinct_identifiers_to_be_saved.yml
|