Class: Course::VirtualClassroom::BraincertApiService

Inherits:
Object
  • Object
show all
Defined in:
app/services/course/virtual_classroom/braincert_api_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(virtual_classroom, settings) ⇒ BraincertApiService

Returns a new instance of BraincertApiService


4
5
6
7
# File 'app/services/course/virtual_classroom/braincert_api_service.rb', line 4

def initialize(virtual_classroom, settings)
  @virtual_classroom = virtual_classroom
  @settings = settings
end

Instance Method Details


27
28
29
30
31
32
33
34
35
# File 'app/services/course/virtual_classroom/braincert_api_service.rb', line 27

def fetch_recorded_video_link(record_id)
  response = call_braincert_api('/v2/getrecording', record_id: record_id)
  response_body = JSON.parse(response.body)
  if response_body.is_a?(Hash)
    error = response_body['error']
    return [nil, I18n.t(:'course.virtual_classrooms.error_generating_video_link', error: error)]
  end
  [response_body[0]['record_url'], nil]
end

#fetch_recorded_videosObject


17
18
19
20
21
22
23
24
25
# File 'app/services/course/virtual_classroom/braincert_api_service.rb', line 17

def fetch_recorded_videos
  return nil unless @virtual_classroom.classroom_id && @virtual_classroom.ended?
  response = call_braincert_api '/v2/getclassrecording', class_id: @virtual_classroom.classroom_id
  response_body = [JSON.parse(response.body)].flatten.select do |h|
    h['id'].present? || h['status'] == 'error'
  end
  @virtual_classroom.update! recorded_videos: response_body
  response_body
end

9
10
11
12
13
14
15
# File 'app/services/course/virtual_classroom/braincert_api_service.rb', line 9

def handle_access_link(user, is_instructor)
  msg = virtual_classroom_inactive?
  return [nil, msg] if msg
  _, error = create_classroom
  return [nil, error] if error
  generate_classroom_link(user, is_instructor)
end