Class: Conversant::V3::Services::Portal

Inherits:
Base
  • Object
show all
Includes:
Authorization
Defined in:
lib/conversant/v3/services/portal.rb,
lib/conversant/v3/services/portal/dashboard.rb

Overview

Portal service for Conversant/SwiftFederation administration

Provides access to portal functionality including appliance management and infrastructure monitoring.

Examples:

Basic usage

portal = Conversant::V3.portal(12345)

# Get appliances for current month
appliances = portal.appliances

# Get appliances for specific date range
appliances = portal.appliances('2025-01-01T00:00:00Z', '2025-01-31T23:59:59Z')

Since:

  • 1.0.0

Defined Under Namespace

Classes: Dashboard

Constant Summary collapse

MASTER_APPLIANCE_REDIS_KEY =

Redis key prefix for caching appliance data

Since:

  • 1.0.0

'CONVERSANT.V3.PORTAL.APPLIANCE.ITEMS'

Constants included from HttpClient

HttpClient::LOGIN_URL, HttpClient::PORTAL_SESSION_REDIS_KEY, HttpClient::SSO_GW_SESSION2_REDIS_KEY

Instance Attribute Summary

Attributes inherited from Base

#customer_id, #type

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from HttpClient

#authenticate, #cookie_jar, #cookie_jar=, #debug_log, #request, #sso_login

Constructor Details

This class inherits a constructor from Conversant::V3::Base

Instance Method Details

#appliances(gte = nil, lte = nil) ⇒ Array<Hash>

Retrieves appliance data for a specified date range

Returns information about appliances (CDN nodes) including their IP addresses, hostnames, locations (POP), traffic volume, and federation volume. Results are cached in Redis for 10 minutes to improve performance.

Examples:

Get appliances for current month

appliances = portal.appliances
appliances.each do |appliance|
  puts "#{appliance[:hostname]} (#{appliance[:ip]}) - #{appliance[:pop]}"
  puts "  Volume: #{appliance[:volume]} bytes"
  puts "  Federation: #{appliance[:federation]} bytes"
end

Get appliances for specific date range

start_date = '2025-01-01T00:00:00Z'
end_date = '2025-01-31T23:59:59Z'
appliances = portal.appliances(start_date, end_date)

Parameters:

  • gte (String, nil) (defaults to: nil)

    Start date/time in ISO 8601 format (defaults to beginning of current month)

  • lte (String, nil) (defaults to: nil)

    End date/time in ISO 8601 format (defaults to end of current month)

Returns:

  • (Array<Hash>)

    Array of appliance hashes with keys:

    • :ip [String] IP address of the appliance
    • :hostname [String] Hostname of the appliance
    • :deleted [Boolean] Whether the appliance has been deleted
    • :pop [String] Point of Presence (datacenter location)
    • :volume [Integer] Traffic volume in bytes
    • :federation [Integer] Federation traffic volume in bytes

Since:

  • 1.0.0



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/conversant/v3/services/portal.rb', line 60

def appliances(gte = nil, lte = nil)
  today = Date.today.to_datetime

  gte ||= today.beginning_of_month.strftime('%Y-%m-%dT00:00:00Z')
  lte ||= today.end_of_month.strftime('%Y-%m-%dT23:59:59Z')

  key = "#{MASTER_APPLIANCE_REDIS_KEY}.#{gte.to_datetime&.strftime('%Y%m')}"

  items = redis.get(key)

  if items.nil?
    logger.debug "#{identifier}.METHOD:appliances.FETCHING_DATA"

    payload = {
      startTime: gte,
      endTime: lte
    }

    response = JSON.parse(call('POST', '/load_appliance_data', payload))

    items = response&.[]('applianceList')&.map do |item|
      {
        ip: item['ip'],
        hostname: item['hostname'],
        deleted: item['deleted'],
        pop: item['pop'],
        volume: item['volume'],
        federation: item['federationVolume'],
      }
    end.to_json

    redis.set(key, items, ex: 600)
  end

  JSON.parse(items)
rescue StandardError => e
  logger.error "#{identifier}.METHOD:appliances.ERROR:#{e.message}"
  []
end

#dashboardDashboard

Get dashboard service instance

Returns:

  • (Dashboard)

    dashboard service for customer metadata and reporting

Since:

  • 1.0.8



104
105
106
# File 'lib/conversant/v3/services/portal.rb', line 104

def dashboard
  @dashboard ||= Dashboard.new(self)
end