Skip to content

Commit

Permalink
Deprecated URL property
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik-dmg committed Mar 21, 2021
1 parent 63a7469 commit a3c5182
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
14 changes: 2 additions & 12 deletions Sources/HPNetwork/Requests/NetworkRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 23 additions & 2 deletions Tests/HPNetworkTests/NetworkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ struct BasicImageRequest: NetworkRequest {
return image
}

func makeURL() throws -> URL {
guard let url = url else {
throw NSError.failedToCreateRequest
}
return url
}

}

#endif
Expand All @@ -260,6 +267,13 @@ struct BasicDecodableRequest<Output: Decodable>: DecodableRequest {
JSONDecoder()
}

func makeURL() throws -> URL {
guard let url = url else {
throw NSError.failedToCreateRequest
}
return url
}

}

struct BasicRequest: NetworkRequest {
Expand All @@ -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 {
Expand All @@ -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")
}

}
Expand Down

0 comments on commit a3c5182

Please sign in to comment.