diff --git a/Sources/NetFlex/HTTPClient/HTTPClient.swift b/Sources/NetFlex/HTTPClient/HTTPClient.swift index 00da71e..103fa9b 100644 --- a/Sources/NetFlex/HTTPClient/HTTPClient.swift +++ b/Sources/NetFlex/HTTPClient/HTTPClient.swift @@ -3,7 +3,7 @@ import Foundation import FoundationNetworking #endif -protocol HTTPClient { +public protocol HTTPClient { func fetchData(with request: URLRequest) async throws -> (Data, HTTPURLResponse) } diff --git a/Sources/NetFlex/HTTPClient/HTTPMethod.swift b/Sources/NetFlex/HTTPClient/HTTPMethod.swift index 066c6a5..3efcf11 100644 --- a/Sources/NetFlex/HTTPClient/HTTPMethod.swift +++ b/Sources/NetFlex/HTTPClient/HTTPMethod.swift @@ -1,6 +1,6 @@ import Foundation -enum HTTPMethod: String { +public enum HTTPMethod: String { case get = "GET" case post = "POST" case put = "PUT" diff --git a/Sources/NetFlex/HTTPClient/RequestInterceptor.swift b/Sources/NetFlex/HTTPClient/RequestInterceptor.swift index 63cd874..babe7d7 100644 --- a/Sources/NetFlex/HTTPClient/RequestInterceptor.swift +++ b/Sources/NetFlex/HTTPClient/RequestInterceptor.swift @@ -3,7 +3,7 @@ import Foundation import FoundationNetworking #endif -protocol RequestInterceptor { +public protocol RequestInterceptor { func intercept(request: URLRequest) async throws -> URLRequest func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) } diff --git a/Sources/NetFlex/Interceptors/AuthorizationInterceptor.swift b/Sources/NetFlex/Interceptors/AuthorizationInterceptor.swift index 8da2c1d..9c9025e 100644 --- a/Sources/NetFlex/Interceptors/AuthorizationInterceptor.swift +++ b/Sources/NetFlex/Interceptors/AuthorizationInterceptor.swift @@ -1,6 +1,6 @@ import Foundation -class AuthorizationInterceptor: RequestInterceptor { +public class AuthorizationInterceptor: RequestInterceptor { private let tokenProvider: () -> String? private let headerField: String? private let tokenFormatter: (String) -> String @@ -30,7 +30,7 @@ class AuthorizationInterceptor: RequestInterceptor { self.bodyEncoding = bodyEncoding } - func intercept(request: URLRequest) async throws -> URLRequest { + public func intercept(request: URLRequest) async throws -> URLRequest { var request = request guard let token = tokenProvider() else { return request @@ -72,7 +72,7 @@ class AuthorizationInterceptor: RequestInterceptor { return request } - func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { + public func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { // No modification to the response return (data, response) } diff --git a/Sources/NetFlex/Interceptors/LoggingInterceptor.swift b/Sources/NetFlex/Interceptors/LoggingInterceptor.swift index 772adab..6479921 100644 --- a/Sources/NetFlex/Interceptors/LoggingInterceptor.swift +++ b/Sources/NetFlex/Interceptors/LoggingInterceptor.swift @@ -1,13 +1,13 @@ import Foundation -class LoggingInterceptor: RequestInterceptor { +public class LoggingInterceptor: RequestInterceptor { private let logger: (String) -> Void init(logger: @escaping (String) -> Void = { print($0) }) { self.logger = logger } - func intercept(request: URLRequest) async throws -> URLRequest { + public func intercept(request: URLRequest) async throws -> URLRequest { var logMessage = "➡️ Request: \(request.httpMethod ?? "") \(request.url?.absoluteString ?? "")\n" if let headers = request.allHTTPHeaderFields { logMessage += "Headers: \(headers)\n" @@ -19,7 +19,7 @@ class LoggingInterceptor: RequestInterceptor { return request } - func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { + public func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { var logMessage = "⬅️ Response: \(response.statusCode) for \(request.url?.absoluteString ?? "")\n" if let responseString = String(data: data, encoding: .utf8) { logMessage += "Response Body: \(responseString)\n" diff --git a/Sources/NetFlex/Interceptors/RetryInterceptor.swift b/Sources/NetFlex/Interceptors/RetryInterceptor.swift index d5f9076..d3c3818 100644 --- a/Sources/NetFlex/Interceptors/RetryInterceptor.swift +++ b/Sources/NetFlex/Interceptors/RetryInterceptor.swift @@ -1,11 +1,11 @@ import Foundation -class RetryInterceptor: RequestInterceptor { - func intercept(request: URLRequest) async throws -> URLRequest { +public class RetryInterceptor: RequestInterceptor { + public func intercept(request: URLRequest) async throws -> URLRequest { return request } - func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { + public func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { if (500...599).contains(response.statusCode) { // Optionally, introduce delay try await Task.sleep(nanoseconds: UInt64(1.0 * Double(NSEC_PER_SEC))) // 1-second delay diff --git a/Sources/NetFlex/Interceptors/TokenRefreshInterceptor.swift b/Sources/NetFlex/Interceptors/TokenRefreshInterceptor.swift index 43a2c1b..dbbf77e 100644 --- a/Sources/NetFlex/Interceptors/TokenRefreshInterceptor.swift +++ b/Sources/NetFlex/Interceptors/TokenRefreshInterceptor.swift @@ -1,6 +1,6 @@ import Foundation -class TokenRefreshInterceptor: RequestInterceptor { +public class TokenRefreshInterceptor: RequestInterceptor { private let tokenProvider: () -> String? private let tokenRefresher: () async throws -> Void private let headerField: String? @@ -21,7 +21,7 @@ class TokenRefreshInterceptor: RequestInterceptor { self.statusCodesToRefresh = statusCodesToRefresh } - func intercept(request: URLRequest) async throws -> URLRequest { + public func intercept(request: URLRequest) async throws -> URLRequest { var request = request if let token = tokenProvider(), let headerField = headerField { let formattedToken = tokenFormatter(token) @@ -30,7 +30,7 @@ class TokenRefreshInterceptor: RequestInterceptor { return request } - func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { + public func intercept(response: HTTPURLResponse, data: Data, for request: URLRequest) async throws -> (Data, HTTPURLResponse) { if statusCodesToRefresh.contains(response.statusCode) { // Refresh the token try await tokenRefresher() diff --git a/Sources/NetFlex/RequestExecutor/APIRequestExecutor.swift b/Sources/NetFlex/RequestExecutor/APIRequestExecutor.swift index 7c4bea1..eab0d98 100644 --- a/Sources/NetFlex/RequestExecutor/APIRequestExecutor.swift +++ b/Sources/NetFlex/RequestExecutor/APIRequestExecutor.swift @@ -3,7 +3,7 @@ import Foundation import FoundationNetworking #endif -final class APIRequestExecutor { +public final class APIRequestExecutor { private let requestBuilder: URLRequestBuilder private let httpClient: HTTPClient private let jsonDecoder: JSONDecoding @@ -29,7 +29,7 @@ final class APIRequestExecutor { } extension APIRequestExecutor: RequestExecutor { - func send(_ request: R) async throws -> R.Response { + public func send(_ request: R) async throws -> R.Response { let urlRequest = try requestBuilder.build(from: request) return try await execute(with: urlRequest) } diff --git a/Sources/NetFlex/RequestExecutor/Request.swift b/Sources/NetFlex/RequestExecutor/Request.swift index 396d7e3..e46acb2 100644 --- a/Sources/NetFlex/RequestExecutor/Request.swift +++ b/Sources/NetFlex/RequestExecutor/Request.swift @@ -1,6 +1,6 @@ import Foundation -protocol Request { +public protocol Request { associatedtype Response: Decodable var path: String { get } diff --git a/Sources/NetFlex/RequestExecutor/RequestExecutor.swift b/Sources/NetFlex/RequestExecutor/RequestExecutor.swift index 6300416..c9ffd63 100644 --- a/Sources/NetFlex/RequestExecutor/RequestExecutor.swift +++ b/Sources/NetFlex/RequestExecutor/RequestExecutor.swift @@ -1,5 +1,5 @@ import Foundation -protocol RequestExecutor { +public protocol RequestExecutor { func send(_ request: R) async throws -> R.Response }