proctorserv-api 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/proctorserv_api.rb +41 -6
- data/lib/proctorserv_api/session_event.rb +51 -0
- data/spec/proctorserv_api_spec.rb +59 -3
- metadata +3 -2
data/README.md
CHANGED
@@ -54,6 +54,21 @@ Creating a session through the scheduling API sets up a future or immediate oppo
|
|
54
54
|
- :first_name (String) - First name of the candidate taking the exam
|
55
55
|
- :last_name (String) - Last name of the candidate taking the exam - The tast taker downloads the ProctorApp desktop application and completes their session
|
56
56
|
|
57
|
+
**Creating a session event**
|
58
|
+
Creates a session event that is specified by session_id (int), event_type (String), severity (int), and proctor_id (String).
|
59
|
+
|
60
|
+
|
61
|
+
*Required Parameters:*
|
62
|
+
|
63
|
+
- :session_id (int) - Proctorserve id for the session to grant access to
|
64
|
+
- :event_type (String) - The type of event which can be found in session_event.rb
|
65
|
+
|
66
|
+
*Optional Parameters:*
|
67
|
+
|
68
|
+
- :severity (int) - The importance-by-color of the session event (0-> grey (system event),1-> red, 2-> yellow, and 3-> green
|
69
|
+
- :proctor_id (String) - unique identifier representing the user to grant access to. This will determine the user's display name in Proctorserve interfaces.
|
70
|
+
- :time (Time) - Time at which to create the event (defaults to now if not set)
|
71
|
+
|
57
72
|
#### Installation
|
58
73
|
|
59
74
|
$ gem install proctorserv-api
|
@@ -101,6 +116,7 @@ proctorserv_api.make_immediate_reservation
|
|
101
116
|
proctorserv_api.cancel_reservation
|
102
117
|
proctorserv_api.generate_jsonp_token
|
103
118
|
proctorserv_api.generate_secure_review_url
|
119
|
+
proctorserv_api.create_session_event
|
104
120
|
```
|
105
121
|
|
106
122
|
Further documentation for these methods can be found [here](http://rubydoc.info/github/ProctorCam/proctorserv-api-rb/master/frames)
|
data/lib/proctorserv_api.rb
CHANGED
@@ -3,6 +3,7 @@ require 'proctorserv_api/exceptions/invalid_client_exception'
|
|
3
3
|
require 'proctorserv_api/exceptions/invalid_ip_exception'
|
4
4
|
require 'proctorserv_api/exceptions/invalid_signature_exception'
|
5
5
|
require 'proctorserv_api/exceptions/missing_required_parameter_exception'
|
6
|
+
require 'proctorserv_api/session_event.rb'
|
6
7
|
|
7
8
|
#
|
8
9
|
# proctorserv_api.rb
|
@@ -29,7 +30,7 @@ module ProctorCam
|
|
29
30
|
module Proctorserv
|
30
31
|
class ProctorservApi
|
31
32
|
|
32
|
-
VERSION = "1.0.
|
33
|
+
VERSION = "1.0.4"
|
33
34
|
|
34
35
|
def initialize(api_identifier, shared_secret, service_protocol = "https", service_url = "service.proctorcam.com")
|
35
36
|
@service_protocol = service_protocol
|
@@ -53,7 +54,7 @@ module ProctorCam
|
|
53
54
|
# @return [Array<Time>] list of Time objects that represent schedulable timeslots in Proctorserve for a test of length session_duration between lower_bound and upper_bound
|
54
55
|
def get_available_timeslots_between(options)
|
55
56
|
requires_of options, [:lower_bound, :upper_bound, :session_duration]
|
56
|
-
url = "#{@service_protocol}://#{@service_url}/#{__method__}"
|
57
|
+
url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}"
|
57
58
|
convert_times_to_integer options, :lower_bound, :upper_bound
|
58
59
|
response = RestRequestClient.new.make_get_request url, @api_identifier, @shared_secret, options
|
59
60
|
parsed_response = JSON.parse response.body
|
@@ -78,7 +79,7 @@ module ProctorCam
|
|
78
79
|
# @return [Array<Time>] list (length num_slots or 20) of Time objects that represent schedulable timeslots in Proctorserve for a test of length session_duration around time passed in options hash
|
79
80
|
def get_available_timeslots_around(options)
|
80
81
|
requires_of options, [:time, :num_slots, :session_duration]
|
81
|
-
url = "#{@service_protocol}://#{@service_url}/#{__method__}"
|
82
|
+
url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}"
|
82
83
|
convert_times_to_integer options, :time
|
83
84
|
response = RestRequestClient.new.make_get_request url, @api_identifier, @shared_secret, options
|
84
85
|
parsed_response = JSON.parse response.body
|
@@ -107,7 +108,7 @@ module ProctorCam
|
|
107
108
|
# @return [int] session_id - the Proctorserve id for the created session. Will return -1 if the time passed is not scheduable.
|
108
109
|
def make_reservation(options)
|
109
110
|
requires_of options, [:time, :customer_subject_id, :customer_client_subject_id, :client_code, :reservation_id, :session_duration, :exam_code]
|
110
|
-
url = "#{@service_protocol}://#{@service_url}/#{__method__}"
|
111
|
+
url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}"
|
111
112
|
convert_times_to_integer options, :time
|
112
113
|
response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, options
|
113
114
|
|
@@ -138,7 +139,7 @@ module ProctorCam
|
|
138
139
|
# @return [int] session_id - the Proctorserve id for the created session. Will return -1 if the time passed is not scheduable.
|
139
140
|
def make_immediate_reservation(options)
|
140
141
|
requires_of options, [:customer_subject_id, :customer_client_subject_id, :client_code, :reservation_id, :session_duration, :exam_code]
|
141
|
-
url = "#{@service_protocol}://#{@service_url}/#{__method__}"
|
142
|
+
url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}"
|
142
143
|
convert_times_to_integer options, :time
|
143
144
|
response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, options
|
144
145
|
|
@@ -160,7 +161,7 @@ module ProctorCam
|
|
160
161
|
# @return [Boolean] whether or not the test was successfully canceled.
|
161
162
|
def cancel_reservation(options)
|
162
163
|
requires_of options, [:session_id]
|
163
|
-
url = "#{@service_protocol}://#{@service_url}/#{__method__}"
|
164
|
+
url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}"
|
164
165
|
response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, options
|
165
166
|
|
166
167
|
return true if response.code == 204
|
@@ -207,6 +208,40 @@ module ProctorCam
|
|
207
208
|
"#{@service_protocol}://#{@service_url}/review?secure_token=#{options.map{|k,v| "#{k}%3D#{v}"}.join '%26'}#watch/#{options[:session_id]}"
|
208
209
|
end
|
209
210
|
|
211
|
+
|
212
|
+
# Generate a session event for a testing session.
|
213
|
+
#
|
214
|
+
# @param [Hash{Symbol => String}] options
|
215
|
+
# Required:
|
216
|
+
# - :session_id (int) - Proctorserve id for the session the event will be added to
|
217
|
+
# - :event_type(String) The event to be added, acceptable events are contained in SessionEvent.rb
|
218
|
+
# Optional:
|
219
|
+
# - :proctor_id (String) - Unique identifier representing the user to grant access to. This will determine the user's display name in Proctorserve interfaces.
|
220
|
+
# - :time (String) (Time or int seconds since epoch) Date and Time that the session event happened at
|
221
|
+
# - :severity (int) (Defaults to 0) The severity of the session_event being created.
|
222
|
+
# - 0: Lowest severity
|
223
|
+
# - 1: Highest Severity, may be used for events like test revoked or emergency.
|
224
|
+
# - 2: Medium Severity, the session needs to be reviewed.
|
225
|
+
# - 3: Low Severity, common events like going through the system check.
|
226
|
+
# @return [Boolean] whether or not the session event was successfully created.
|
227
|
+
def create_session_event(options)
|
228
|
+
requires_of options, [:session_id, :event_type]
|
229
|
+
url = "#{@service_protocol}://#{@service_url}/api/session_events/create"
|
230
|
+
response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, options
|
231
|
+
|
232
|
+
return true if response.code == 201
|
233
|
+
|
234
|
+
if response.code != 200
|
235
|
+
parsed_response = JSON.parse response.body
|
236
|
+
raise_exception_if_necessary(parsed_response)
|
237
|
+
end
|
238
|
+
|
239
|
+
false
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
210
245
|
protected
|
211
246
|
|
212
247
|
def raise_exception_if_necessary(response)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# session_event.rb
|
3
|
+
# ProctorservApi
|
4
|
+
#
|
5
|
+
# Copyright 2013 ProctorCam, Inc
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License")
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# Created by Pat Durgin on 7/19/13.
|
20
|
+
#
|
21
|
+
module SessionEvent
|
22
|
+
|
23
|
+
ERROR = "ERROR"
|
24
|
+
CHECK_IN_BEGUN = "CHECK_IN_BEGUN"
|
25
|
+
APP_CONNECTED = "APP_CONNECTED"
|
26
|
+
STARTED = "STARTED"
|
27
|
+
COMPLETED = "COMPLETED"
|
28
|
+
APP_WORKFLOW = "APP_WORKFLOW"
|
29
|
+
APP_HARDWARE_ISSUE = "APP_HARDWARE_ISSUE"
|
30
|
+
APP_ISSUE = "APP_ISSUE"
|
31
|
+
APP_STREAMING_STARTED = "APP_STREAMING_STARTED"
|
32
|
+
APP_STREAMING_STOPPED = "APP_STREAMING_STOPPED"
|
33
|
+
APP_READY_FOR_GREET = "APP_READY_FOR_GREET"
|
34
|
+
SERVICE_TEST_RELEASED = "SERVICE_TEST_RELEASED"
|
35
|
+
|
36
|
+
ACCESS_CODE_RESET = "ACCESS_CODE_RESET"
|
37
|
+
UNAPPROVED_RESOURCE = "UNAPPROVED_RESOURCE"
|
38
|
+
VOICE_HEARD = "VOICE_HEARD"
|
39
|
+
PUSHED_TO_COMPLETE = "PUSHED_TO_COMPLETE"
|
40
|
+
USING_PHONE = "USING_PHONE"
|
41
|
+
LEFT_THE_ROOM = "LEFT_THE_ROOM"
|
42
|
+
EMERGENCY = "EMERGENCY"
|
43
|
+
UNUSUAL_EYE_MOVEMENT = "UNUSUAL_EYE_MOVEMENT"
|
44
|
+
OTHER = "OTHER"
|
45
|
+
APP_SUBJECT_HAND_RAISED = "APP_SUBJECT_HAND_RAISED"
|
46
|
+
SERVICE_TEST_PAUSED = "SERVICE_TEST_PAUSED"
|
47
|
+
SERVICE_TEST_RESUMED = "SERVICE_TEST_RESUMED"
|
48
|
+
SERVICE_TEST_REVOKED = "SERVICE_TEST_REVOKED"
|
49
|
+
SERVICE_PROCTOR_OUTREACH = "SERVICE_PROCTOR_OUTREACH"
|
50
|
+
|
51
|
+
end
|
@@ -25,18 +25,18 @@ require 'rspec'
|
|
25
25
|
describe ProctorCam::Proctorserv::ProctorservApi do
|
26
26
|
|
27
27
|
before :all do
|
28
|
-
@proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("
|
28
|
+
@proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("test", "shared_secret", "http", "localhost:3000")
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "when passed improper credentials" do
|
32
32
|
|
33
33
|
it "raises an invalid_client_exception when api_identifier is wrong" do
|
34
|
-
proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("wrong", "shared_secret", "http", "localhost:3000
|
34
|
+
proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("wrong", "shared_secret", "http", "localhost:3000")
|
35
35
|
expect{proctorserv_api.get_available_timeslots_between({:lower_bound => Time.now.to_i, :upper_bound => Time.now.to_i + 24*60*60, :session_duration => 60})}.to raise_error ProctorCam::Proctorserv::InvalidClientException
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises an invalid_signature_exception when shared_secret is wrong" do
|
39
|
-
proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("
|
39
|
+
proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("test", "wrong", "http", "localhost:3000")
|
40
40
|
expect{proctorserv_api.get_available_timeslots_between({:lower_bound => Time.now.to_i, :upper_bound => Time.now.to_i + 24*60*60, :session_duration => 60})}.to raise_error ProctorCam::Proctorserv::InvalidSignatureException
|
41
41
|
end
|
42
42
|
|
@@ -141,4 +141,60 @@ describe ProctorCam::Proctorserv::ProctorservApi do
|
|
141
141
|
|
142
142
|
end
|
143
143
|
|
144
|
+
describe "generate_jsonp_token" do
|
145
|
+
|
146
|
+
it "raises missing_required_parameter_exception when not passed session_id in options hash" do
|
147
|
+
expect{@proctorserv_api.generate_jsonp_token({})}.to raise_error ProctorCam::Proctorserv::MissingRequiredParameterException
|
148
|
+
end
|
149
|
+
|
150
|
+
it "generates a secure token that can be used to grant temporary jsonp access to a session for a web browser user to take a session" do
|
151
|
+
options = {:session_id => 400, :duration => 60}
|
152
|
+
jsonp_token = @proctorserv_api.generate_jsonp_token options
|
153
|
+
resultant_hash = Hash[jsonp_token.split('%26').map{|sub_hash|sub_hash.split('%3D')}]
|
154
|
+
resultant_hash['session_id'].should == options[:session_id].to_s
|
155
|
+
resultant_hash['duration'].should == options[:duration].to_s
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "generate_secure_review_url" do
|
160
|
+
|
161
|
+
it "raises missing_required_parameter_exception when not passed proctor_id and session_id" do
|
162
|
+
expect{@proctorserv_api.generate_secure_review_url({})}.to raise_error ProctorCam::Proctorserv::MissingRequiredParameterException
|
163
|
+
end
|
164
|
+
|
165
|
+
it "generate a secure token that can be used to grant temporary access to a session for a web browser user to review a session." do
|
166
|
+
options = {:proctor_id => "foo", :session_id => 500, :duration => 60}
|
167
|
+
generated_url = @proctorserv_api.generate_secure_review_url options
|
168
|
+
resultant_hash = Hash[generated_url.match(/secure_token=(.*)#watch\/[1-9]*/)[1].split('%26').map{|sub_hash|sub_hash.split('%3D')}]
|
169
|
+
resultant_hash['session_id'].should == options[:session_id].to_s
|
170
|
+
resultant_hash['proctor_id'].should == options[:proctor_id].to_s
|
171
|
+
resultant_hash['duration'].should == options[:duration].to_s
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "create_session_event" do
|
176
|
+
|
177
|
+
it "raises a missing_required_parameter_exception when not passed session_id and event_type" do
|
178
|
+
expect{@proctorserv_api.create_session_event({})}.to raise_error ProctorCam::Proctorserv::MissingRequiredParameterException
|
179
|
+
end
|
180
|
+
|
181
|
+
it "returns true if it generates a session event for a testing session if options hash contains correct values" do
|
182
|
+
options = {:session_id => 471, :event_type => SessionEvent::COMPLETED, :proctor_id => "foo", :severity => 2}
|
183
|
+
result = @proctorserv_api.create_session_event options
|
184
|
+
result.should be_true
|
185
|
+
end
|
186
|
+
|
187
|
+
it "returns false if the customer does not have the session_id passed" do
|
188
|
+
proctorserv_api = ProctorCam::Proctorserv::ProctorservApi.new("test", "shared_secret", "http", "localhost:3000")
|
189
|
+
options = {:session_id => -1, :event_type => SessionEvent::COMPLETED, :proctor_id => "foo", :severity => 2}
|
190
|
+
result = proctorserv_api.create_session_event options
|
191
|
+
result.should be_false
|
192
|
+
end
|
193
|
+
|
194
|
+
it "returns false if the event_type is not a valid event type" do
|
195
|
+
options = {:session_id => 450, :event_type => 'this isnt an event', :proctor_id => "foo", :severity => 2}
|
196
|
+
result = @proctorserv_api.create_session_event options
|
197
|
+
result.should be_false
|
198
|
+
end
|
199
|
+
end
|
144
200
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proctorserv-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
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: 2013-07-
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/proctorserv_api/exceptions/missing_required_parameter_exception.rb
|
58
58
|
- lib/proctorserv_api/hashed_authenticator.rb
|
59
59
|
- lib/proctorserv_api/rest_request_client.rb
|
60
|
+
- lib/proctorserv_api/session_event.rb
|
60
61
|
- lib/proctorserv_api.rb
|
61
62
|
- LICENSE
|
62
63
|
- README.md
|