Skip to content

Commit

Permalink
🔀 Merge pull request #44 from MrSkwiggs/bleeding_edge
Browse files Browse the repository at this point in the history
🐛 Fix Linux compilation issues
  • Loading branch information
MrSkwiggs committed Jun 23, 2023
2 parents f050aa3 + 79a847e commit fd60df1
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/HTTPPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// An HTTP Performer works with low-level URLRequests and validates the response's status code
public protocol HTTPPerformer {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Netswift/Core/NetswiftError/NetswiftError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private extension Data {
return "Invalid JSON\n\(plainString ?? plainDescription)"
}
return prettyString
} else if let plainString {
} else if let plainString = plainString {
return plainString
} else {
return plainDescription
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/NetswiftHTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// Convenience wrapper for URLResponses
public struct NetswiftHTTPResponse {
Expand Down
6 changes: 4 additions & 2 deletions Sources/Netswift/Core/NetswiftHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ public struct NetswiftHeaders {
var all = additionalHeaders
all.update(with: .accept(accept))
all.update(with: .contentType(contentType))
if let authorization { all.update(with: .authorization(authorization)) }

if let authorization = authorization {
all.update(with: .authorization(authorization))
}

return all
}
}
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/NetswiftNetworkPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/**
A `NetswiftNetworkPerformer` is the link between low-level url requests and high-level api requests
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/NetswiftRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// Generic structure that defines its own Response type. Comes with a few convenience extensions for common types such as JSON
public protocol NetswiftRequest {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/NetswiftRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// swiftlint:disable force_unwrapping

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/**
Protocol defining URL Routes for APIs.
Expand Down
26 changes: 25 additions & 1 deletion Sources/Netswift/Core/NetswiftSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// Protocol that allows to mock URLSessions
public protocol NetswiftSession {
Expand All @@ -31,14 +34,35 @@ extension URLSession: NetswiftSession {
return task
}

#if os(Linux)
/// Asynchronous data call made via NetswiftSession Protocol
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func perform(_ urlRequest: URLRequest) async -> NetswiftHTTPResponse {
do {
let (data, response) = try await data(for: urlRequest)
let response: (Data?, URLResponse?) = try await withCheckedThrowingContinuation { continuation in
dataTask(with: urlRequest) { data, response, error in
if let error = error {
continuation.resume(throwing: error)
}
continuation.resume(returning: (data, response))
}
}

return NetswiftHTTPResponse(data: response.0, response: response.1)
} catch {
return NetswiftHTTPResponse(data: nil, response: nil, error: error)
}
}
#else
/// Asynchronous data call made via NetswiftSession Protocol
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func perform(_ urlRequest: URLRequest) async -> NetswiftHTTPResponse {
do {
let (data, response) = try await self.data(for: urlRequest)
return NetswiftHTTPResponse(data: data, response: response)
} catch {
return NetswiftHTTPResponse(data: nil, response: nil, error: error)
}
}
#endif
}
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/NetswiftTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

public protocol NetswiftTask {

Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/Core/URLRequestExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// Convenience wrapper functions
public extension URLRequest {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/NetswiftHTTPPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// A generic HTTP Performer. For detailed doc please refer to HTTPPerformer protocol
open class NetswiftHTTPPerformer: HTTPPerformer {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Netswift/NetswiftPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// Generic NetswiftRequest performer. For detailed doc please refer to NetswiftNetworkPerformer protocol
open class NetswiftPerformer: NetswiftNetworkPerformer {
Expand Down

0 comments on commit fd60df1

Please sign in to comment.