diff --git a/Sources/XuqmSDK/Core/ApiClient.swift b/Sources/XuqmSDK/Core/ApiClient.swift index 206b0b5..16ab211 100644 --- a/Sources/XuqmSDK/Core/ApiClient.swift +++ b/Sources/XuqmSDK/Core/ApiClient.swift @@ -45,11 +45,22 @@ public final class ApiClient: @unchecked Sendable { req.httpBody = try JSONEncoder().encode(b) } + if config.debug { + print("[XuqmSDK][HTTP] request", method, req.url?.absoluteString ?? path) + } + let (data, response) = try await session.data(for: req) guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else { + if config.debug, let http = response as? HTTPURLResponse { + print("[XuqmSDK][HTTP] response", http.statusCode, req.url?.absoluteString ?? path) + } throw URLError(.badServerResponse) } + if config.debug { + print("[XuqmSDK][HTTP] response", http.statusCode, req.url?.absoluteString ?? path) + } + let wrapper = try JSONDecoder().decode(ApiResponse.self, from: data) if let result = wrapper.data { return result diff --git a/Sources/XuqmSDK/Core/SDKConfig.swift b/Sources/XuqmSDK/Core/SDKConfig.swift index 997695b..61b2b2c 100644 --- a/Sources/XuqmSDK/Core/SDKConfig.swift +++ b/Sources/XuqmSDK/Core/SDKConfig.swift @@ -24,3 +24,21 @@ public struct SDKConfig: Sendable { self.debug = debug } } + +public extension SDKConfig { + static func development( + appId: String, + appSecret: String, + appKey: String? = nil, + debug: Bool = false + ) -> SDKConfig { + SDKConfig( + appId: appId, + appKey: appKey ?? appId, + appSecret: appSecret, + apiBaseURL: URL(string: "http://192.168.116.9:8081")!, + imWebSocketURL: URL(string: "ws://192.168.116.9:8082/ws/im")!, + debug: debug + ) + } +}