Skip to content

Commit

Permalink
Merge pull request #9 from EgzonArifi/feature/public-access-modifier
Browse files Browse the repository at this point in the history
Public access modifier
  • Loading branch information
EgzonArifi authored Nov 2, 2024
2 parents a17706f + 2d1d297 commit 32b05c4
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Sources/NetFlex/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import FoundationNetworking
#endif

protocol HTTPClient {
public protocol HTTPClient {
func fetchData(with request: URLRequest) async throws -> (Data, HTTPURLResponse)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NetFlex/HTTPClient/HTTPMethod.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

enum HTTPMethod: String {
public enum HTTPMethod: String {
case get = "GET"
case post = "POST"
case put = "PUT"
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetFlex/HTTPClient/RequestInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions Sources/NetFlex/Interceptors/AuthorizationInterceptor.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NetFlex/Interceptors/LoggingInterceptor.swift
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Sources/NetFlex/Interceptors/RetryInterceptor.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Sources/NetFlex/Interceptors/TokenRefreshInterceptor.swift
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Sources/NetFlex/RequestExecutor/APIRequestExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@ final class APIRequestExecutor {
}

extension APIRequestExecutor: RequestExecutor {
func send<R: Request>(_ request: R) async throws -> R.Response {
public func send<R: Request>(_ request: R) async throws -> R.Response {
let urlRequest = try requestBuilder.build(from: request)
return try await execute(with: urlRequest)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetFlex/RequestExecutor/Request.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

protocol Request {
public protocol Request {
associatedtype Response: Decodable

var path: String { get }
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetFlex/RequestExecutor/RequestExecutor.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

protocol RequestExecutor {
public protocol RequestExecutor {
func send<R: Request>(_ request: R) async throws -> R.Response
}

0 comments on commit 32b05c4

Please sign in to comment.