Module: Proctoring::HundredMsServiceHelper
Instance Method Summary
collapse
encode_authentication_token, #generate_authentication_token, #generate_management_token
Instance Method Details
#add_room_to_the_cache(room_id, user_id, role, event_id) ⇒ Object
46
47
48
49
50
51
|
# File 'app/helpers/proctoring/hundred_ms_service_helper.rb', line 46
def add_room_to_the_cache(room_id, user_id, role, event_id)
candidates = [{ user_id: user_id, role: role }]
rooms = fetch_rooms_for_a_event(event_id) || {}
rooms[room_id] = candidates
Rails.cache.write("100ms_room_details_#{event_id}", rooms, expires_in: 2.hours)
end
|
#generate_room(params) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/helpers/proctoring/hundred_ms_service_helper.rb', line 7
def generate_room(params)
uri = get_api_url('create_room')
uri = URI.parse(uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' })
request['Authorization'] = "Bearer #{generate_management_token}"
body = get_create_room_request_parameters(params[:event_id])
request.body = body.to_json
response = http.request(request)
JSON.parse(response.body)
end
|
#room_already_exists?(event_id, user_id) ⇒ Boolean
20
21
22
23
24
25
26
27
28
29
|
# File 'app/helpers/proctoring/hundred_ms_service_helper.rb', line 20
def room_already_exists?(event_id, user_id)
rooms = fetch_rooms_for_a_event(event_id)
return if rooms.blank?
rooms.each do |room_id, candidates|
candidates.each do |candidate_hash|
return room_id if candidate_hash[:user_id] == user_id
end
end; nil
end
|
#room_exists_with_space?(event_id, user_id, role, max_people_allowed) ⇒ Boolean
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/helpers/proctoring/hundred_ms_service_helper.rb', line 31
def room_exists_with_space?(event_id, user_id, role, max_people_allowed)
rooms = fetch_rooms_for_a_event(event_id)
return if rooms.blank?
rooms.each do |room_id, candidates|
roles = candidates.map { |candidate_hash| candidate_hash[:role] }
next if roles.count(role) >= max_people_allowed.to_i
candidates << { user_id: user_id, role: role }
rooms[room_id] = candidates
Rails.cache.write("100ms_room_details_#{event_id}", rooms, expires_in: 2.hours)
return room_id
end; nil
end
|