From 431d2f907b5693b2c14ea044ac69ffd8d6268ab0 Mon Sep 17 00:00:00 2001 From: mino Date: Thu, 30 Nov 2023 11:46:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A0=91=EA=B7=BC=EC=A0=9C=EC=96=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CuteNetwork/Cute.swift | 10 +++++----- Sources/CuteNetwork/Encodable+parameter.swift | 2 +- Sources/CuteNetwork/EndPointType.swift | 2 +- Sources/CuteNetwork/NetworkError.swift | 2 +- Sources/CuteNetwork/NetworkLogger.swift | 3 +-- Sources/CuteNetwork/ResponseHandler.swift | 2 +- Tests/CuteNetworkTests/CuteNetworkTests.swift | 1 - 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/CuteNetwork/Cute.swift b/Sources/CuteNetwork/Cute.swift index 7d8f73a..972d2a3 100644 --- a/Sources/CuteNetwork/Cute.swift +++ b/Sources/CuteNetwork/Cute.swift @@ -7,11 +7,11 @@ import Foundation -class Cute: NSObject, NetworkRouter, URLSessionDelegate { +open class Cute: NSObject, NetworkRouter, URLSessionDelegate { /// Properties private var task: URLSessionTask? /// petit(_ root: EndPoint, petitLogVisible: Bool) async throws -> Data 함수를 통해 받은 Data를 파싱해주는 함수입니다. - func petit(_ root: EndPoint, petitLogVisible: Bool = true) async throws -> T { + open func petit(_ root: EndPoint, petitLogVisible: Bool = true) async throws -> T { do { let result = try await petit(root, petitLogVisible: petitLogVisible) @@ -28,7 +28,7 @@ class Cute: NSObject, NetworkRouter, URLSessionDelegate } /// petit(_ route: EndPoint, logAccess: Bool, completion: @escaping NetworkRouterCompletion)를 받아 /// 에러, 데이터를 넘겨주는 함수, 정상일 경우 Data를 반환합니다. - func petit(_ root: EndPoint, petitLogVisible: Bool) async throws -> Data { + open func petit(_ root: EndPoint, petitLogVisible: Bool) async throws -> Data { return try await withCheckedThrowingContinuation({ value in petit(root, logAccess: petitLogVisible) { data, response, error in if let error { @@ -55,7 +55,7 @@ class Cute: NSObject, NetworkRouter, URLSessionDelegate }) } /// dataTask를 걸친 데이터 까지 넘겨주는 역할 - func petit(_ route: EndPoint, logAccess: Bool, completion: @escaping NetworkRouterCompletion) { + open func petit(_ route: EndPoint, logAccess: Bool, completion: @escaping NetworkRouterCompletion) { guard Reachability.isConnectedToNetwork() else { completion(nil, nil, NetworkError.noConnectionToInternet) return @@ -78,7 +78,7 @@ class Cute: NSObject, NetworkRouter, URLSessionDelegate self.task?.resume() } - func cancel() { + open func cancel() { self.task?.cancel() } } diff --git a/Sources/CuteNetwork/Encodable+parameter.swift b/Sources/CuteNetwork/Encodable+parameter.swift index 119bb72..06cef5e 100644 --- a/Sources/CuteNetwork/Encodable+parameter.swift +++ b/Sources/CuteNetwork/Encodable+parameter.swift @@ -8,7 +8,7 @@ import Foundation extension Encodable { - var toParameter: [String: Any]? { + public var toParameter: [String: Any]? { guard let object = try? JSONEncoder().encode(self) else { return nil } guard let dictionary = try? JSONSerialization.jsonObject(with: object, options: []) as? [String: Any] else { return nil } diff --git a/Sources/CuteNetwork/EndPointType.swift b/Sources/CuteNetwork/EndPointType.swift index 3567ac5..4daa592 100644 --- a/Sources/CuteNetwork/EndPointType.swift +++ b/Sources/CuteNetwork/EndPointType.swift @@ -10,7 +10,7 @@ import Foundation public typealias Parameters = [String: Any] public typealias HTTPHeaders = [String: String] /// EndPointType -protocol EndPointType { +public protocol EndPointType { var baseURL: URL { get } var path: String { get } var httpMethod: HTTPMethod { get } diff --git a/Sources/CuteNetwork/NetworkError.swift b/Sources/CuteNetwork/NetworkError.swift index 028b73c..8ad70ff 100644 --- a/Sources/CuteNetwork/NetworkError.swift +++ b/Sources/CuteNetwork/NetworkError.swift @@ -18,7 +18,7 @@ public enum NetworkError: Error { case paging case custom(message: String) - var errorMessage: String { + public var errorMessage: String { switch self { case .parametersNil: return "파라미터가 nil 입니다." diff --git a/Sources/CuteNetwork/NetworkLogger.swift b/Sources/CuteNetwork/NetworkLogger.swift index 0ce1da1..faf3046 100644 --- a/Sources/CuteNetwork/NetworkLogger.swift +++ b/Sources/CuteNetwork/NetworkLogger.swift @@ -7,7 +7,7 @@ import Foundation -class NetworkLogger { +open class NetworkLogger { static func log(request: URLRequest) { @@ -17,7 +17,6 @@ class NetworkLogger { let method = request.httpMethod != nil ? "\(request.httpMethod ?? "")" : "" let path = "\(urlComponents?.path ?? "")" let query = "\(urlComponents?.query ?? "")" - let host = "\(urlComponents?.host ?? "")" var bodyLog: String = "" diff --git a/Sources/CuteNetwork/ResponseHandler.swift b/Sources/CuteNetwork/ResponseHandler.swift index adb9c6d..923b2dc 100644 --- a/Sources/CuteNetwork/ResponseHandler.swift +++ b/Sources/CuteNetwork/ResponseHandler.swift @@ -7,7 +7,7 @@ import Foundation -class ResponseHandler { +open class ResponseHandler { enum NetworkResponse: String { case success diff --git a/Tests/CuteNetworkTests/CuteNetworkTests.swift b/Tests/CuteNetworkTests/CuteNetworkTests.swift index 30e8b8a..fce673b 100644 --- a/Tests/CuteNetworkTests/CuteNetworkTests.swift +++ b/Tests/CuteNetworkTests/CuteNetworkTests.swift @@ -31,7 +31,6 @@ final class CuteNetworkTests: XCTestCase { let cute = Cute() do { - let a = try await cute.petit(.test, petitLogVisible: false) // XCTAssertNotEqual(a, Data()) } catch { print("error: \(error)")