mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-04 10:52:19 +00:00
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
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import Foundation
|
||||
|
||||
/// API for usage management
|
||||
public class UsageAPI {
|
||||
private let client: HTTPClient
|
||||
|
||||
public init(client: HTTPClient) {
|
||||
self.client = client
|
||||
}
|
||||
|
||||
/// Get usage statistics for a subscriber
|
||||
public func getStats(subscriberID: Int64, startDate: Date, endDate: Date) async throws -> UsageStats {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
let params: [String: String] = [
|
||||
"start_date": formatter.string(from: startDate),
|
||||
"end_date": formatter.string(from: endDate)
|
||||
]
|
||||
|
||||
return try await client.get(path: "/v1/subscribers/\(subscriberID)/usage", params: params)
|
||||
}
|
||||
|
||||
/// List usage events
|
||||
public func listEvents(
|
||||
subscriberID: Int64? = nil,
|
||||
usageType: UsageType? = nil,
|
||||
startDate: Date? = nil,
|
||||
endDate: Date? = nil,
|
||||
page: Int = 1,
|
||||
pageSize: Int = 50
|
||||
) async throws -> UsageEventList {
|
||||
var params: [String: String] = [
|
||||
"page": "\(page)",
|
||||
"page_size": "\(pageSize)"
|
||||
]
|
||||
|
||||
if let subscriberID = subscriberID {
|
||||
params["subscriber_id"] = "\(subscriberID)"
|
||||
}
|
||||
if let usageType = usageType {
|
||||
params["usage_type"] = "\(usageType)"
|
||||
}
|
||||
if let startDate = startDate {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
params["start_date"] = formatter.string(from: startDate)
|
||||
}
|
||||
if let endDate = endDate {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
params["end_date"] = formatter.string(from: endDate)
|
||||
}
|
||||
|
||||
return try await client.get(path: "/v1/usage/events", params: params)
|
||||
}
|
||||
|
||||
/// Get real-time usage for a subscriber
|
||||
public func getRealtime(subscriberID: Int64) async throws -> RealTimeUsage {
|
||||
return try await client.get(path: "/v1/subscribers/\(subscriberID)/realtime")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user