Files
telecom-platform/sdk/swift/Sources/TelecomSDK/TelecomSDK.swift
T
nutcas3 f6590462f5 docs: Add Swift SDK README with comprehensive API documentation and implement authentication provider with JWT support
- Add README.md with installation instructions, architecture overview, and API examples for all SDK modules
- Add AuthProvider class with API key and JWT token support (generateJWTToken, validateJWTToken, getHeaders, clearTokenCache methods)
- Add HTTPClient base class with retry logic, error handling, and timeout management
- Add GraphQLAPI, PaymentAPI, RatingPlanAPI, SubscriberAPI, SystemAPI, and UsageAPI modules
- Add TelecomSDK main client integrating all API
2026-04-25 04:53:22 +03:00

95 lines
3.0 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 graphql: GraphQLAPI
// MARK: - Initialization
/// 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.graphql = GraphQLAPI(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
}
}