From a3c51823653821ca7bc89c49f7168cc1196ea4ef Mon Sep 17 00:00:00 2001 From: Henrik Panhans Date: Sun, 21 Mar 2021 12:18:37 +0100 Subject: [PATCH] Deprecated URL property --- .../HPNetwork/Requests/NetworkRequest.swift | 14 ++--------- Tests/HPNetworkTests/NetworkTests.swift | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Sources/HPNetwork/Requests/NetworkRequest.swift b/Sources/HPNetwork/Requests/NetworkRequest.swift index 1ad63ee..0d75a57 100644 --- a/Sources/HPNetwork/Requests/NetworkRequest.swift +++ b/Sources/HPNetwork/Requests/NetworkRequest.swift @@ -10,18 +10,15 @@ public protocol NetworkRequest { typealias Completion = (RequestResult) -> Void var finishingQueue: DispatchQueue { get } - @available(*, deprecated, message: "Please use makeURL instead, this property will be removed in a future release") - var url: URL? { get } var httpBody: Data? { get } var urlSession: URLSession { get } - - func makeURL() throws -> URL - var headerFields: [NetworkRequestHeaderField]? { get } /// The request method that will be used var requestMethod: NetworkRequestMethod { get } var authentication: NetworkRequestAuthentication? { get } + func makeURL() throws -> URL + func convertResponse(response: NetworkResponse) throws -> Output func convertError(_ error: Error, data: Data?, response: URLResponse?) -> Error @@ -63,13 +60,6 @@ public extension NetworkRequest { var authentication: NetworkRequestAuthentication? { nil } - func makeURL() throws -> URL { - guard let url = url else { - throw NSError.failedToCreateRequest.withFailureReason("The URL instance to create the request is nil") - } - return url - } - func convertError(_ error: Error, data: Data?, response: URLResponse?) -> Error { error } diff --git a/Tests/HPNetworkTests/NetworkTests.swift b/Tests/HPNetworkTests/NetworkTests.swift index a7df440..3a33411 100644 --- a/Tests/HPNetworkTests/NetworkTests.swift +++ b/Tests/HPNetworkTests/NetworkTests.swift @@ -247,6 +247,13 @@ struct BasicImageRequest: NetworkRequest { return image } + func makeURL() throws -> URL { + guard let url = url else { + throw NSError.failedToCreateRequest + } + return url + } + } #endif @@ -260,6 +267,13 @@ struct BasicDecodableRequest: DecodableRequest { JSONDecoder() } + func makeURL() throws -> URL { + guard let url = url else { + throw NSError.failedToCreateRequest + } + return url + } + } struct BasicRequest: NetworkRequest { @@ -268,6 +282,13 @@ struct BasicRequest: NetworkRequest { let url: URL? let requestMethod: NetworkRequestMethod = .get + func makeURL() throws -> URL { + guard let url = url else { + throw NSError.failedToCreateRequest + } + return url + } + } struct FaultyRequest: NetworkRequest { @@ -278,8 +299,8 @@ struct FaultyRequest: NetworkRequest { .get } - var url: URL? { - nil + func makeURL() throws -> URL { + throw NSError.failedToCreateRequest.withFailureReason("The URL instance to create the request is nil") } }