Class: Conversant::V3::Services::LMS::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/conversant/v3/services/lms/dashboard.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Dashboard

Returns a new instance of Dashboard.

Since:

  • 1.0.0



10
11
12
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 10

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Since:

  • 1.0.0



8
9
10
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 8

def parent
  @parent
end

Instance Method Details

#dvrObject

Since:

  • 1.0.0



36
37
38
39
40
41
42
43
44
45
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 36

def dvr
  payload = { _: (Time.now.to_f * 1000).to_i }
  response = @parent.send(:call, 'GET', "/v4/dvr/duration?#{payload.to_query}")
  return nil if response.nil?

  JSON.parse(response)
rescue StandardError => e
  logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#liveObject

Since:

  • 1.0.0



14
15
16
17
18
19
20
21
22
23
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 14

def live
  payload = { _: (Time.now.to_f * 1000).to_i }
  response = @parent.send(:call, 'GET', "/v4/live/duration?#{payload.to_query}")
  return nil if response.nil?

  JSON.parse(response)
rescue StandardError => e
  logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#recent_jobsObject

Since:

  • 1.0.0



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 47

def recent_jobs
  response = @parent.send(:call, 'GET', '/dashboard/dashboard')
  return [] if response.nil?

  # Parse HTML response to extract job data
  require 'nokogiri' if defined?(Nokogiri)
  return [] unless defined?(Nokogiri)

  doc = Nokogiri::HTML.parse(response)
  table = doc.at('table')
  return [] if table.nil?

  jobs = table.search('tr').map do |row|
    cells = row.search('td')
    next [] if cells.length.zero?

    app_name, stream_name, type, created, started, recording, status = cells

    {
      app_name: app_name&.text&.strip,
      stream_name: stream_name&.text&.strip,
      type: type&.text&.strip,
      created: parse_timestamp(created&.text),
      started: parse_timestamp(started&.text),
      recording: recording&.text&.strip,
      status: status&.text&.strip
    }
  end.flatten.compact

  jobs
rescue StandardError => e
  logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#vodObject

Since:

  • 1.0.0



25
26
27
28
29
30
31
32
33
34
# File 'lib/conversant/v3/services/lms/dashboard.rb', line 25

def vod
  payload = { _: (Time.now.to_f * 1000).to_i }
  response = @parent.send(:call, 'GET', "/v4/live/duration?#{payload.to_query}")
  return nil if response.nil?

  JSON.parse(response)
rescue StandardError => e
  logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end