Class: Conversant::V3::Services::CDN::Business

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

Overview

Business metrics service for CDN billing and usage reporting

Provides access to business-level metrics used for billing calculations, usage reporting, and 95th percentile bandwidth measurements. These metrics are typically used for financial reporting and capacity planning.

Examples:

Get billing metrics

business = cdn.business

# Get traffic usage for billing
usage = business.bandwidth({
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-31T23:59:59Z",
  pageSize: 1000,
  pageNumber: 0
})

# Get 95th percentile bandwidth
bandwidth_95th = business.bandwidth95th(year: 2025)

Since:

  • 1.0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Business

Initialize business metrics service

Parameters:

  • parent (CDN)

    the parent CDN service instance

Since:

  • 1.0.1



35
36
37
# File 'lib/conversant/v3/services/cdn/business.rb', line 35

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentCDN (readonly)

Returns the parent CDN service instance.

Returns:

  • (CDN)

    the parent CDN service instance

Since:

  • 1.0.1



30
31
32
# File 'lib/conversant/v3/services/cdn/business.rb', line 30

def parent
  @parent
end

Instance Method Details

#bandwidth(payload) ⇒ Array

Get domain traffic usage for billing

Retrieves detailed traffic usage data by domain for billing and reporting purposes. This data is typically used for invoicing and usage analysis.

Examples:

Get monthly traffic usage

usage = cdn.business.bandwidth({
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-31T23:59:59Z",
  pageSize: 1000,
  pageNumber: 0
})

usage.each do |record|
  puts "Domain: #{record['domain']}"
  puts "Traffic: #{record['traffic_bytes']} bytes"
  puts "Period: #{record['period']}"
end

Parameters:

  • payload (Hash)

    query parameters for traffic usage

Options Hash (payload):

  • :startTime (String)

    start time in ISO 8601 format ("2025-01-01T00:00:00Z")

  • :endTime (String)

    end time in ISO 8601 format ("2025-01-31T23:59:59Z")

  • :pageSize (Integer)

    number of results per page (recommended: 1000)

  • :pageNumber (Integer)

    page number for pagination (0-based)

Returns:

  • (Array, Array)

    array of domain traffic usage records, or empty array on error

Since:

  • 1.0.1



67
68
69
70
71
72
73
74
75
# File 'lib/conversant/v3/services/cdn/business.rb', line 67

def bandwidth(payload)
  response = @parent.send(:call, 'POST', '/api/domain_traffic_usage', payload)
  return [] if response.nil?

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

#bandwidth95th(params) ⇒ Array

Get 95th percentile bandwidth measurements

Retrieves 95th percentile bandwidth measurements for the specified year. This metric is commonly used in CDN billing to calculate peak usage while excluding traffic spikes that occur less than 5% of the time.

Examples:

Get 95th percentile for current year

bandwidth_95th = cdn.business.bandwidth95th(year: 2025)

bandwidth_95th.each do |measurement|
  puts "Month: #{measurement['month']}"
  puts "95th Percentile: #{measurement['bandwidth_95th']} bps"
  puts "Peak: #{measurement['peak_bandwidth']} bps"
end

Calculate annual 95th percentile

measurements = cdn.business.bandwidth95th(year: 2025)
annual_95th = measurements.map { |m| m['bandwidth_95th'] }.max
puts "Annual 95th percentile: #{annual_95th} bps"

Parameters:

  • params (Hash)

    query parameters

Options Hash (params):

  • :year (Integer)

    the year to get 95th percentile data for (e.g., 2025)

Returns:

  • (Array, Array)

    array of 95th percentile bandwidth measurements, or empty array on error

Since:

  • 1.0.1



103
104
105
106
107
108
109
110
111
# File 'lib/conversant/v3/services/cdn/business.rb', line 103

def bandwidth95th(params)
  response = @parent.send(:call, 'GET', "/api/report/bandwidth95th/#{params[:year]}", nil)
  return [] if response.nil?

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