Skip to content

Commit c35f86a

Browse files
authored
Merge pull request #78 from makinosp/feature/available-for-linux
feature/available-for-linux
2 parents e6d6d9f + 3d78220 commit c35f86a

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Sources/VRCKit/APIClient.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public final class APIClient {
1114
typealias HTTPResponse = (data: Data, response: HTTPURLResponse)
@@ -95,12 +98,41 @@ public final class APIClient {
9598
request.httpBody = body
9699
}
97100

101+
#if canImport(FoundationNetworking)
102+
return try await requestWithFoundationNetworking(request)
103+
#else
104+
return try await requestWithFoundation(request)
105+
#endif
106+
}
107+
108+
#if canImport(FoundationNetworking)
109+
private func requestWithFoundationNetworking(_ request: URLRequest) async throws -> HTTPResponse {
110+
var requestError: Error?
111+
let httpResponse = await withCheckedContinuation { continuation in
112+
URLSession.shared.dataTask(with: request) { data, urlResponse, error in
113+
guard let data = data, let reponse = urlResponse as? HTTPURLResponse else {
114+
requestError = error
115+
return
116+
}
117+
continuation.resume(returning: (data, reponse))
118+
}
119+
.resume()
120+
}
121+
if let requestError = requestError {
122+
throw requestError
123+
}
124+
return httpResponse
125+
}
126+
127+
#else
128+
private func requestWithFoundation(_ request: URLRequest) async throws -> HTTPResponse {
98129
let (data, response) = try await URLSession.shared.data(for: request)
99130
guard let response = response as? HTTPURLResponse else {
100131
throw VRCKitError.invalidResponse
101132
}
102133
return (data, response)
103134
}
135+
#endif
104136
}
105137

106138
extension APIClient.Method: CustomStringConvertible {

Sources/VRCKit/Utils/CookieManager.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public final class CookieManager {
1114
private var domainURL: String?

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
build:
3+
image: swift:5.10.1
4+
command: bash -c "swift build -c release"
5+
volumes:
6+
- ${PWD}:${PWD}
7+
working_dir: ${PWD}
8+
lint:
9+
image: ghcr.io/realm/swiftlint:latest
10+
volumes:
11+
- ${PWD}:${PWD}
12+
working_dir: ${PWD}

0 commit comments

Comments
 (0)