Class: Conversant::V3::Services::VMS::Business

Inherits:
Object
  • Object
show all
Defined in:
lib/conversant/v3/services/vms/business.rb

Overview

Business metrics service for VMS

Provides business-level metrics for billing and reporting including duration, volume, and transcoding statistics broken down by resolution (SD, HD, UHD) and operation type.

Examples:

Get business metrics

vms = Conversant::V3.vms(12345)

# Get duration metrics for billing
duration = vms.business.duration({
  startTime: Time.now.beginning_of_month
})

# Get comprehensive transcoding breakdown
breakdown = vms.business.transcoding({
  startTime: Time.now.beginning_of_month
})
puts "SD: #{breakdown[:vms_transcoding_sd]}"
puts "HD: #{breakdown[:vms_transcoding_hd]}"
puts "UHD: #{breakdown[:vms_transcoding_uhd]}"

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Business

Initialize business metrics service

Parameters:

  • parent (VMS)

    the parent VMS service instance

Since:

  • 1.0.0



37
38
39
# File 'lib/conversant/v3/services/vms/business.rb', line 37

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentVMS (readonly)

Returns the parent VMS service instance.

Returns:

  • (VMS)

    the parent VMS service instance

Since:

  • 1.0.0



32
33
34
# File 'lib/conversant/v3/services/vms/business.rb', line 32

def parent
  @parent
end

Instance Method Details

#duration(payload) ⇒ Array

Get video duration metrics for billing

Retrieves video transcoding duration metrics aggregated by month for billing and usage reporting purposes.

Examples:

Get current month duration

duration = vms.business.duration({
  startTime: Time.now.beginning_of_month
})

Parameters:

  • payload (Hash)

    query parameters including month/year

Options Hash (payload):

  • :startTime (Time, String)

    start time (used to extract month)

Returns:

  • (Array)

    duration metrics for billing purposes, or empty array on error

Since:

  • 1.0.0



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/conversant/v3/services/vms/business.rb', line 57

def duration(payload)
  month = extract_month(payload)
  search_payload = {
    month: month,
    selectType: 'vtd',
    customerType: @parent.type || 2,
    _: (Time.now.to_f * 1000).to_i.to_s
  }

  response = @parent.send(:call, 'GET', "/v5/reporting/vms/business/usage/search?#{search_payload.to_query}")
  return [] if response.nil?

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

#transcoding(payload) ⇒ Hash

Get comprehensive transcoding metrics breakdown

Retrieves detailed transcoding metrics broken down by resolution (SD, HD, UHD) and operation type (transcoding vs transmuxing). Useful for detailed billing and capacity analysis.

Examples:

Get transcoding breakdown

breakdown = vms.business.transcoding({
  startTime: Time.now.beginning_of_month
})
puts "Total transcoding: #{breakdown[:vms_transcoding]} minutes"
puts "SD: #{breakdown[:vms_transcoding_sd]} minutes"
puts "HD: #{breakdown[:vms_transcoding_hd]} minutes"
puts "UHD: #{breakdown[:vms_transcoding_uhd]} minutes"
puts "Transmuxing: #{breakdown[:vms_transmuxing]} minutes"

Parameters:

  • payload (Hash)

    query parameters including month/year

Options Hash (payload):

  • :startTime (Time, String)

    start time (used to extract month)

Returns:

  • (Hash)

    transcoding metrics breakdown with keys:

    • :vms_transcoding [Float] total transcoding duration
    • :vms_transmuxing [Float] transmuxing duration
    • :vms_transcoding_sd [Float] SD transcoding duration
    • :vms_transcoding_hd [Float] HD transcoding duration
    • :vms_transcoding_uhd [Float] UHD transcoding duration

Since:

  • 1.0.0



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/conversant/v3/services/vms/business.rb', line 136

def transcoding(payload)
  report_vms = {
    vms_transcoding: 0,
    vms_transmuxing: 0,
    vms_transcoding_sd: 0,
    vms_transcoding_hd: 0,
    vms_transcoding_uhd: 0
  }

  vms_trans = duration(payload)&.first
  return report_vms unless vms_trans

  name = vms_trans.keys&.first
  if vms_trans[name].present? && !vms_trans[name].empty?
    vms_trans[name]&.each do |item|
      report_vms[:vms_transmuxing] += item['transmux']&.to_f || 0
      report_vms[:vms_transcoding_sd] += (item['h264SdTranscoding']&.to_f || 0) + (item['h265SdTranscoding']&.to_f || 0)
      report_vms[:vms_transcoding_hd] += (item['h264HdTranscoding']&.to_f || 0) + (item['h265HdTranscoding']&.to_f || 0)
      report_vms[:vms_transcoding_uhd] += (item['h264UhdTranscoding']&.to_f || 0) + (item['h265UhdTranscoding']&.to_f || 0)
    end
  end

  report_vms[:vms_transcoding] =
    report_vms[:vms_transcoding_sd] +
    report_vms[:vms_transcoding_hd] +
    report_vms[:vms_transcoding_uhd]

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

#volume(payload) ⇒ Array

Get video volume metrics for billing

Retrieves video transcoding volume metrics aggregated by month for storage billing and capacity planning.

Examples:

Get current month volume

volume = vms.business.volume({
  startTime: Time.now.beginning_of_month
})

Parameters:

  • payload (Hash)

    query parameters including month/year

Options Hash (payload):

  • :startTime (Time, String)

    start time (used to extract month)

Returns:

  • (Array)

    volume metrics for billing purposes, or empty array on error

Since:

  • 1.0.0



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/conversant/v3/services/vms/business.rb', line 91

def volume(payload)
  month = extract_month(payload)
  search_payload = {
    month: month,
    selectType: 'vtv',
    customerType: @parent.type || 2,
    _: (Time.now.to_f * 1000).to_i.to_s
  }

  response = @parent.send(:call, 'GET', "/v5/reporting/vms/business/usage/search?#{search_payload.to_query}")
  return [] if response.nil?

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