mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 02:52:53 +00:00
- Add AnalyticsAPI with churn prediction (predict, metrics, at-risk), market analytics (metrics, competitors, opportunities), predictive maintenance (metrics, assets, alerts, predict), and pricing optimization (metrics, optimize, elasticity) endpoints - Add SecurityAPI with fraud detection (analyze, alerts, update status, metrics, patterns) and SIM swap protection (verify, history) endpoints - Add CurrencyAPI with currency conversion (convert, exchange rates, rate
83 lines
2.6 KiB
Ruby
83 lines
2.6 KiB
Ruby
require "httparty"
|
|
require "json"
|
|
require "websocket-client-simple"
|
|
require "uri"
|
|
|
|
require_relative "telecom_sdk/auth"
|
|
require_relative "telecom_sdk/http_client"
|
|
require_relative "telecom_sdk/subscribers_api"
|
|
require_relative "telecom_sdk/usage_api"
|
|
require_relative "telecom_sdk/payments_api"
|
|
require_relative "telecom_sdk/rating_plans_api"
|
|
require_relative "telecom_sdk/system_api"
|
|
require_relative "telecom_sdk/analytics_api"
|
|
require_relative "telecom_sdk/security_api"
|
|
require_relative "telecom_sdk/currency_api"
|
|
|
|
module TelecomSDK
|
|
class Error < StandardError; end
|
|
class AuthenticationError < Error; end
|
|
class APIError < Error; end
|
|
class NetworkError < Error; end
|
|
class ValidationError < Error; end
|
|
class RateLimitError < Error; end
|
|
class ServerError < Error; end
|
|
|
|
class Client
|
|
attr_reader :config, :subscribers, :usage, :payments, :rating_plans, :system, :analytics, :security, :currency
|
|
|
|
def initialize(config = {})
|
|
@config = Config.new(config)
|
|
@auth_provider = AuthProvider.new(api_key: @config.api_key, jwt_secret: @config.jwt_secret)
|
|
@http_client = HTTPClient.new(
|
|
@config.api_url,
|
|
@auth_provider,
|
|
timeout: @config.timeout,
|
|
max_retries: @config.max_retries,
|
|
retry_delay: @config.retry_delay,
|
|
enable_logging: @config.enable_logging
|
|
)
|
|
|
|
# Initialize API modules
|
|
@subscribers = SubscriberAPI.new(@http_client)
|
|
@usage = UsageAPI.new(@http_client)
|
|
@payments = PaymentAPI.new(@http_client)
|
|
@rating_plans = RatingPlanAPI.new(@http_client)
|
|
@system = SystemAPI.new(@http_client)
|
|
@analytics = AnalyticsAPI.new(@http_client)
|
|
@security = SecurityAPI.new(@http_client)
|
|
@currency = CurrencyAPI.new(@http_client)
|
|
end
|
|
|
|
# Authentication methods
|
|
|
|
def generate_jwt_token(user_id, expiry_hours = 24, additional_claims = {})
|
|
@auth_provider.generate_jwt_token(user_id, expiry_hours, additional_claims)
|
|
end
|
|
|
|
def validate_jwt_token(token)
|
|
@auth_provider.validate_jwt_token(token)
|
|
end
|
|
|
|
# Cleanup
|
|
|
|
def close
|
|
@http_client.close
|
|
end
|
|
end
|
|
|
|
class Config
|
|
attr_accessor :api_url, :api_key, :jwt_secret, :timeout, :max_retries, :retry_delay, :enable_logging
|
|
|
|
def initialize(config = {})
|
|
@api_url = config[:api_url] || "http://localhost:8000"
|
|
@api_key = config[:api_key]
|
|
@jwt_secret = config[:jwt_secret]
|
|
@timeout = config[:timeout] || 30
|
|
@max_retries = config[:max_retries] || 3
|
|
@retry_delay = config[:retry_delay] || 1
|
|
@enable_logging = config[:enable_logging] || false
|
|
end
|
|
end
|
|
end
|