From 55ab4bd2962b37902f78fabea666505bf4788eba Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 13 Nov 2023 17:01:34 -1000 Subject: [PATCH] Removes unnecessary E: Encodable generic type --- .../Calls/NetworkingClient+Data.swift | 6 +++--- .../Calls/NetworkingClient+Decodable.swift | 16 ++++++++-------- .../Calls/NetworkingClient+JSON.swift | 8 ++++---- .../Calls/NetworkingClient+Requests.swift | 4 ++-- .../Calls/NetworkingClient+Void.swift | 6 +++--- Sources/Networking/NetworkingService.swift | 18 +++++++++--------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Sources/Networking/Calls/NetworkingClient+Data.swift b/Sources/Networking/Calls/NetworkingClient+Data.swift index fd698f1..e912393 100644 --- a/Sources/Networking/Calls/NetworkingClient+Data.swift +++ b/Sources/Networking/Calls/NetworkingClient+Data.swift @@ -18,7 +18,7 @@ public extension NetworkingClient { request(.post, route, params: params).publisher() } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { request(.post, route, encodableBody: body).publisher() } @@ -30,7 +30,7 @@ public extension NetworkingClient { request(.patch, route, params: params).publisher() } - func patch(_ route: String, body: E) -> AnyPublisher { + func patch(_ route: String, body: Encodable) -> AnyPublisher { request(.patch, route, encodableBody: body).publisher() } @@ -49,7 +49,7 @@ public extension NetworkingClient { try await request(.post, route, params: params).execute() } - func post(_ route: String, body: E) async throws -> Data { + func post(_ route: String, body: Encodable) async throws -> Data { try await request(.post, route, encodableBody: body).execute() } diff --git a/Sources/Networking/Calls/NetworkingClient+Decodable.swift b/Sources/Networking/Calls/NetworkingClient+Decodable.swift index ed3ab3e..e48ff5b 100644 --- a/Sources/Networking/Calls/NetworkingClient+Decodable.swift +++ b/Sources/Networking/Calls/NetworkingClient+Decodable.swift @@ -39,8 +39,8 @@ public extension NetworkingClient { .eraseToAnyPublisher() } - func post(_ route: String, - body: E, + func post(_ route: String, + body: Encodable, keypath: String? = nil ) -> AnyPublisher { return post(route, body: body) @@ -90,8 +90,8 @@ public extension NetworkingClient { } - func patch(_ route: String, - body: E, + func patch(_ route: String, + body: Encodable, keypath: String? = nil ) -> AnyPublisher { return patch(route, body: body) @@ -158,8 +158,8 @@ public extension NetworkingClient { return try self.toModel(json, keypath: keypath) } - func post(_ route: String, - body: E, + func post(_ route: String, + body: Encodable, keypath: String? = nil ) async throws -> T { let json: Any = try await post(route, body: body) @@ -204,8 +204,8 @@ public extension NetworkingClient { return try self.toModel(json, keypath: keypath) } - func patch(_ route: String, - body: E, + func patch(_ route: String, + body: Encodable, keypath: String? = nil ) async throws -> T { let json: Any = try await patch(route, body: body) diff --git a/Sources/Networking/Calls/NetworkingClient+JSON.swift b/Sources/Networking/Calls/NetworkingClient+JSON.swift index ae660de..677b6db 100644 --- a/Sources/Networking/Calls/NetworkingClient+JSON.swift +++ b/Sources/Networking/Calls/NetworkingClient+JSON.swift @@ -18,7 +18,7 @@ public extension NetworkingClient { post(route, params: params).toJSON() } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { post(route, body: body).toJSON() } @@ -30,7 +30,7 @@ public extension NetworkingClient { patch(route, params: params).toJSON() } - func patch(_ route: String, body: E) -> AnyPublisher { + func patch(_ route: String, body: Encodable) -> AnyPublisher { patch(route, body: body).toJSON() } @@ -53,7 +53,7 @@ public extension NetworkingClient { return try JSONSerialization.jsonObject(with: data, options: []) } - func post(_ route: String, body: E) async throws -> Any { + func post(_ route: String, body: Encodable) async throws -> Any { let req = request(.post, route, encodableBody: body) let data = try await req.execute() return try JSONSerialization.jsonObject(with: data, options: []) @@ -71,7 +71,7 @@ public extension NetworkingClient { return try JSONSerialization.jsonObject(with: data, options: []) } - func patch(_ route: String, body: E) async throws -> Any { + func patch(_ route: String, body: Encodable) async throws -> Any { let req = request(.patch, route, encodableBody: body) let data = try await req.execute() return try JSONSerialization.jsonObject(with: data, options: []) diff --git a/Sources/Networking/Calls/NetworkingClient+Requests.swift b/Sources/Networking/Calls/NetworkingClient+Requests.swift index 67b9efa..e891f5d 100644 --- a/Sources/Networking/Calls/NetworkingClient+Requests.swift +++ b/Sources/Networking/Calls/NetworkingClient+Requests.swift @@ -59,10 +59,10 @@ public extension NetworkingClient { return req } - internal func request(_ httpMethod: HTTPMethod, + internal func request(_ httpMethod: HTTPMethod, _ route: String, params: Params = Params(), - encodableBody: E? = nil + encodableBody: Encodable? = nil ) -> NetworkingRequest { let req = NetworkingRequest() req.httpMethod = httpMethod diff --git a/Sources/Networking/Calls/NetworkingClient+Void.swift b/Sources/Networking/Calls/NetworkingClient+Void.swift index 44dd2d4..dea4a75 100644 --- a/Sources/Networking/Calls/NetworkingClient+Void.swift +++ b/Sources/Networking/Calls/NetworkingClient+Void.swift @@ -22,7 +22,7 @@ public extension NetworkingClient { .eraseToAnyPublisher() } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { post(route, body: body) .map { (data: Data) -> Void in () } .eraseToAnyPublisher() @@ -40,7 +40,7 @@ public extension NetworkingClient { .eraseToAnyPublisher() } - func patch(_ route: String, body: E) -> AnyPublisher { + func patch(_ route: String, body: Encodable) -> AnyPublisher { patch(route, body: body) .map { (data: Data) -> Void in () } .eraseToAnyPublisher() @@ -65,7 +65,7 @@ public extension NetworkingClient { _ = try await req.execute() } - func post(_ route: String, body: E) async throws { + func post(_ route: String, body: Encodable) async throws { let req = request(.post, route, encodableBody: body) _ = try await req.execute() } diff --git a/Sources/Networking/NetworkingService.swift b/Sources/Networking/NetworkingService.swift index 42fec31..096083e 100644 --- a/Sources/Networking/NetworkingService.swift +++ b/Sources/Networking/NetworkingService.swift @@ -26,7 +26,7 @@ public extension NetworkingService { network.post(route, params: params) } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { network.post(route, body: body) } @@ -38,7 +38,7 @@ public extension NetworkingService { network.patch(route, params: params) } - func patch(_ route: String, body: E) -> AnyPublisher { + func patch(_ route: String, body: Encodable) -> AnyPublisher { network.patch(route, body: body) } @@ -56,7 +56,7 @@ public extension NetworkingService { network.post(route, params: params) } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { network.post(route, body: body) } @@ -82,7 +82,7 @@ public extension NetworkingService { network.post(route, params: params) } - func post(_ route: String, body: E) -> AnyPublisher { + func post(_ route: String, body: Encodable) -> AnyPublisher { network.post(route, body: body) } @@ -242,7 +242,7 @@ public extension NetworkingService { try await network.post(route, params: params) } - func post(_ route: String, body: E) async throws -> Data { + func post(_ route: String, body: Encodable) async throws -> Data { try await network.post(route, body: body) } @@ -268,7 +268,7 @@ public extension NetworkingService { return try await network.post(route, params: params) } - func post(_ route: String, body: E) async throws { + func post(_ route: String, body: Encodable) async throws { return try await network.post(route, body: body) } @@ -294,7 +294,7 @@ public extension NetworkingService { try await network.post(route, params: params) } - func post(_ route: String, body: E) async throws -> Any { + func post(_ route: String, body: Encodable) async throws -> Any { try await network.post(route, body: body) } @@ -324,7 +324,7 @@ public extension NetworkingService { try await network.post(route, params: params, keypath: keypath) } - func post(_ route: String, body: E) async throws -> T { + func post(_ route: String, body: Encodable) async throws -> T { try await network.post(route, body: body) } @@ -340,7 +340,7 @@ public extension NetworkingService { try await network.patch(route, params: params, keypath: keypath) } - func patch(_ route: String, body: E) async throws -> T { + func patch(_ route: String, body: Encodable) async throws -> T { try await network.patch(route, body: body) }