Class: ProctorCam::Proctorserv::ProctorservApi
- Inherits:
-
Object
- Object
- ProctorCam::Proctorserv::ProctorservApi
- Defined in:
- lib/proctorserv_api.rb,
lib/proctorserv_api/version.rb
Constant Summary collapse
- VERSION =
"1.4.0"
Instance Method Summary collapse
-
#cancel_reservation(options) ⇒ Boolean
Cancels a reservation for a specific session_id.
-
#create_session_event(options) ⇒ Object
Generate a session event for a testing session.
-
#data_deletions(options) ⇒ Object
dataDeletions.
-
#data_retrievals(options) ⇒ Object
data_retrievals.
-
#generate_jsonp_token(options) ⇒ String
Generate a secure token that can be used to grant temporary jsonp access to a session for a web browser user to take a session.
-
#generate_secure_review_url(options) ⇒ String
Generate a secure token that can be used to grant temporary access to a session for a web browser user to review a session.
-
#get_access_code(options) ⇒ Object
get_access_code Will return a hash containing access code and its expiration date time based on a session ID provided in the request.
-
#get_available_timeslots_around(options) ⇒ Array<Time>
Get a list of schedulable timeslots (represented as Time objects) around the time for a given exam that needs to be scheduled.
-
#get_available_timeslots_between(options) ⇒ Array<Time>
Get a list of schedulable timeslots (represented as Time objects) between two times for a given exam that needs to be scheduled.
-
#initialize(api_identifier, shared_secret, service_protocol = "https", service_url = "service.proctorcam.com") ⇒ ProctorservApi
constructor
A new instance of ProctorservApi.
-
#make_immediate_reservation(options) ⇒ int
Makes a reservation for a session if now is a schedulable time.
-
#make_reservation(options) ⇒ int
Makes a reservation for a session if the time passed in options is a schedulable time.
-
#reset_access_code(options) ⇒ Object
reset_access_code Will return a hash containing new access code for a session based on a session ID provided in the request.
Constructor Details
#initialize(api_identifier, shared_secret, service_protocol = "https", service_url = "service.proctorcam.com") ⇒ ProctorservApi
Returns a new instance of ProctorservApi.
33 34 35 36 37 38 |
# File 'lib/proctorserv_api.rb', line 33 def initialize(api_identifier, shared_secret, service_protocol = "https", service_url = "service.proctorcam.com") @service_protocol = service_protocol @service_url = service_url @api_identifier = api_identifier @shared_secret = shared_secret end |
Instance Method Details
#cancel_reservation(options) ⇒ Boolean
Cancels a reservation for a specific session_id. A session is no longer cancelable if it has already begun or the scheduled time has passed.
This method will raise exceptions related to authentication (InvalidClientException, InvalidSignatureException, InvalidIpException) or not providing required data (MissingRequiredParameterException)
260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/proctorserv_api.rb', line 260 def cancel_reservation() requires_of , [:session_id] url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}" response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, return true if response.code == 204 if response.code != 200 parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) end false end |
#create_session_event(options) ⇒ Object
Generate a session event for a testing session.
@return [Boolean] whether or not the session event was successfully created.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/proctorserv_api.rb', line 331 def create_session_event() requires_of , [:session_id, :event_type] url = "#{@service_protocol}://#{@service_url}/api/session_events/create" response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, return true if response.code == 201 if response.code != 200 parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) end false end |
#data_deletions(options) ⇒ Object
dataDeletions
Will delete all identifying data associated with a set of sessions
that are scoped to the smallest possible set by any of the following parameters
optional parameters:
- ids (only delete from this list) eg [123,124,125]
- customer_subject_id (only delete sessions associated with a customer's subject id)
- customer_client_subject_id (only delete sessions associated with a customer's client's subject id)
- client_code (API identifier for customer client)
- exam_code
- lower_bound - UTC Datetime Object (UTC seconds since epoch after which to delete sessions by reservation time. Defaults to 0)
- upper_bound - UTC Datetime Object (UTC seconds since epoch before which to delete sessions by reservation time.
Defaults to max 32 bit unsigned int)
Note that if no parameters are passed, no sessions will be deleted.
returns an array of session ids that were successfully deleted
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/proctorserv_api.rb', line 207 def data_deletions() url = "#{@service_protocol}://#{@service_url}/api/#{__method__}/sessions" # API accepts UTC Datetime Object so we must convert it to # UTC seconds as that is what is required by the proctorserve api convert_times_to_integer , :upper_bound if [:upper_bound] convert_times_to_integer , :lower_bound if [:lower_bound] response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 201 parsed_response end |
#data_retrievals(options) ⇒ Object
data_retrievals
Will return data associated with a list of sessions.
The information returned is dependant on the elements
provided in the request
required parameters:
- ids (session id's you would like to obtain data from) - Array of IDs (string)
- elements (the type of data that you would like to retrieve for each session) - Array of elements (string)
optional elements: Select one or more elements to receive data, if left blank no data will be returned
- review_url (url to proctorcam to review the past session)
- video_url (url to download the sessions video)
- id_photo_url (url to download the photo of the id provided by the sessions test taker)
- headshot_photo_url (url to download the photo of test taker)
- session_activity (an array of all session events associated with the session)
example:
- params = {:ids => ["393", "392"], :elements => ["id_photo_url", "headshot_photo_url", "session_activity", "video_url"]}
141 142 143 144 145 146 147 148 149 |
# File 'lib/proctorserv_api.rb', line 141 def data_retrievals() requires_of , [:ids, :elements] url = "#{@service_protocol}://#{@service_url}/api/#{__method__}/sessions" response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 parsed_response end |
#generate_jsonp_token(options) ⇒ String
Generate a secure token that can be used to grant temporary jsonp access to a session for a web browser user to take a session.
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/proctorserv_api.rb', line 283 def generate_jsonp_token() requires_of , [:session_id] [:time] = Time.now.to_i [:duration] ||= 60 [:duration] = 180 if [:duration] > 180 HashedAuthenticator.apply_reverse_guid_and_sign(, @api_identifier, @shared_secret) .map{|k,v| "#{k}%3D#{v}"}.join '%26' end |
#generate_secure_review_url(options) ⇒ String
Generate a secure token that can be used to grant temporary access to a session for a web browser user to review a session. Can be loaded in an iframe or a new window to grant secure access to a single user for a specified period of time
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/proctorserv_api.rb', line 304 def generate_secure_review_url() requires_of , [:proctor_id, :session_id] [:time] = Time.now.to_i [:duration] ||= 5 [:duration] = 180 if [:duration] > 180 HashedAuthenticator.apply_reverse_guid_and_sign(, @api_identifier, @shared_secret) "#{@service_protocol}://#{@service_url}/review?secure_token=#{.map{|k,v| "#{k}%3D#{v}"}.join '%26'}#watch/#{[:session_id]}" end |
#get_access_code(options) ⇒ Object
get_access_code
Will return a hash containing access code and its expiration date time based
on a session ID provided in the request
required parameters:
- session_id Integer
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/proctorserv_api.rb', line 158 def get_access_code() requires_of , [:session_id] url = "#{@service_protocol}://#{@service_url}/api/access_code/#{__method__}" response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 return parsed_response["message"] if parsed_response["message"] parsed_response["access_code"] end |
#get_available_timeslots_around(options) ⇒ Array<Time>
Get a list of schedulable timeslots (represented as Time objects) around the time for a given exam that needs to be scheduled. This API request takes the provided session_duration into account when comparing Proctorserve business hours. The timeslots returned are specific for an exam of duration provided. At most 20 slots will be returned
This method will raise exceptions related to authentication (InvalidClientException, InvalidSignatureException, InvalidIpException) or not providing required data (MissingRequiredParameterException)
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/proctorserv_api.rb', line 78 def get_available_timeslots_around() requires_of , [:time, :num_slots, :session_duration] url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}" convert_times_to_integer , :time response = RestRequestClient.new.make_get_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 parsed_response.map{|| Time.at()} end |
#get_available_timeslots_between(options) ⇒ Array<Time>
Get a list of schedulable timeslots (represented as Time objects) between two times for a given exam that needs to be scheduled. This API request takes the provided session_duration into account when comparing Proctorserve business hours. The timeslots returned are specific for an exam of duration provided.
This method will raise exceptions related to authentication (InvalidClientException, InvalidSignatureException, InvalidIpException) or not providing required data (MissingRequiredParameterException)
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/proctorserv_api.rb', line 53 def get_available_timeslots_between() requires_of , [:lower_bound, :upper_bound, :session_duration] url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}" convert_times_to_integer , :lower_bound, :upper_bound response = RestRequestClient.new.make_get_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 parsed_response.map{|| Time.at()} end |
#make_immediate_reservation(options) ⇒ int
Makes a reservation for a session if now is a schedulable time.
This method will raise exceptions related to authentication (InvalidClientException, InvalidSignatureException, InvalidIpException) or not providing required data (MissingRequiredParameterException)
238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/proctorserv_api.rb', line 238 def make_immediate_reservation() requires_of , [:customer_subject_id, :customer_client_subject_id, :client_code, :reservation_id, :session_duration, :exam_code] url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}" convert_times_to_integer , :time response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 return -1 if response.code == 404 parsed_response["session_id"] end |
#make_reservation(options) ⇒ int
Makes a reservation for a session if the time passed in options is a schedulable time.
This method will raise exceptions related to authentication (InvalidClientException, InvalidSignatureException, InvalidIpException) or not providing required data (MissingRequiredParameterException)
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/proctorserv_api.rb', line 107 def make_reservation() requires_of , [:time, :customer_subject_id, :customer_client_subject_id, :client_code, :reservation_id, :session_duration, :exam_code] url = "#{@service_protocol}://#{@service_url}/api/scheduling/#{__method__}" convert_times_to_integer , :time response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 return -1 if response.code == 404 parsed_response["session_id"] end |
#reset_access_code(options) ⇒ Object
reset_access_code
Will return a hash containing new access code for a session
based on a session ID provided in the request
required parameters:
- session_id Integer
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/proctorserv_api.rb', line 177 def reset_access_code() requires_of , [:session_id] url = "#{@service_protocol}://#{@service_url}/api/access_code/#{__method__}" response = RestRequestClient.new.make_post_request url, @api_identifier, @shared_secret, parsed_response = JSON.parse response.body raise_exception_if_necessary(parsed_response) if response.code != 200 return parsed_response if parsed_response["message"] parsed_response["access_code"] end |