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
97 lines
3.1 KiB
Swift
97 lines
3.1 KiB
Swift
import Foundation
|
|
import NIO
|
|
import AsyncAlgorithms
|
|
|
|
/// Telecom Platform Swift SDK
|
|
///
|
|
/// Provides async/await support with Swift Concurrency for the Telecom Platform API.
|
|
public class TelecomSDK {
|
|
|
|
// MARK: - Properties
|
|
|
|
private let config: TelecomConfig
|
|
private let authProvider: AuthProvider
|
|
private let httpClient: HTTPClient
|
|
|
|
// API modules
|
|
public let subscribers: SubscriberAPI
|
|
public let usage: UsageAPI
|
|
public let payments: PaymentAPI
|
|
public let ratingPlans: RatingPlanAPI
|
|
public let system: SystemAPI
|
|
public let analytics: AnalyticsAPI
|
|
public let security: SecurityAPI
|
|
public let currency: CurrencyAPI
|
|
|
|
/// Initialize a new TelecomSDK instance
|
|
/// - Parameter config: Configuration for the SDK
|
|
public init(config: TelecomConfig = TelecomConfig()) {
|
|
self.config = config
|
|
self.authProvider = AuthProvider(apiKey: config.apiKey, jwtSecret: config.jwtSecret)
|
|
self.httpClient = HTTPClient(config: config, authProvider: authProvider)
|
|
|
|
// Initialize API modules
|
|
self.subscribers = SubscriberAPI(client: httpClient)
|
|
self.usage = UsageAPI(client: httpClient)
|
|
self.payments = PaymentAPI(client: httpClient)
|
|
self.ratingPlans = RatingPlanAPI(client: httpClient)
|
|
self.system = SystemAPI(client: httpClient)
|
|
self.analytics = AnalyticsAPI(client: httpClient)
|
|
self.security = SecurityAPI(client: httpClient)
|
|
self.currency = CurrencyAPI(client: httpClient)
|
|
}
|
|
|
|
// MARK: - Authentication Methods
|
|
|
|
/// Generate a JWT token for authentication
|
|
public func generateJWTToken(userID: String, expiryHours: Int, additionalClaims: [String: Any] = [:]) throws -> String {
|
|
return try authProvider.generateJWTToken(userID: userID, expiryHours: expiryHours, additionalClaims: additionalClaims)
|
|
}
|
|
|
|
/// Validate a JWT token
|
|
public func validateJWTToken(_ token: String) throws -> [String: Any] {
|
|
return try authProvider.validateJWTToken(token)
|
|
}
|
|
|
|
// MARK: - Cleanup
|
|
|
|
/// Close the SDK and cleanup resources
|
|
public func close() {
|
|
httpClient.close()
|
|
}
|
|
}
|
|
|
|
// MARK: - Configuration
|
|
|
|
/// Configuration for Telecom SDK
|
|
public struct TelecomConfig {
|
|
/// Base URL for the API server
|
|
public var apiURL: String
|
|
/// API key for authentication
|
|
public var apiKey: String?
|
|
/// JWT secret for token generation
|
|
public var jwtSecret: String?
|
|
/// Request timeout in seconds
|
|
public var timeout: TimeInterval
|
|
/// Maximum number of retry attempts
|
|
public var maxRetries: Int
|
|
/// Delay between retries in seconds
|
|
public var retryDelay: TimeInterval
|
|
|
|
public init(
|
|
apiURL: String = "http://localhost:8000",
|
|
apiKey: String? = nil,
|
|
jwtSecret: String? = nil,
|
|
timeout: TimeInterval = 30.0,
|
|
maxRetries: Int = 3,
|
|
retryDelay: TimeInterval = 1.0
|
|
) {
|
|
self.apiURL = apiURL
|
|
self.apiKey = apiKey
|
|
self.jwtSecret = jwtSecret
|
|
self.timeout = timeout
|
|
self.maxRetries = maxRetries
|
|
self.retryDelay = retryDelay
|
|
}
|
|
}
|