Skip to content

Commit 837e8e9

Browse files
committed
Create OpenAPI client in a single place for better consistency and remove unused Response
1 parent c13cfa6 commit 837e8e9

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,47 +123,32 @@ public class HTTPRequestExecutorImpl: HTTPRequestExecutor {
123123
try await self.httpClient.execute(request, timeout: timeout)
124124
}
125125

126-
public func getCurrentSwiftlyRelease() async throws -> Components.Schemas.SwiftlyRelease {
127-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
126+
private func client() throws -> Client {
128127
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
128+
let transport: ClientTransport
129+
130+
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(30))
131+
transport = AsyncHTTPClientTransport(configuration: config)
129132

130-
let client = Client(
133+
return Client(
131134
serverURL: try Servers.Server1.url(),
132-
transport: AsyncHTTPClientTransport(configuration: config),
135+
transport: transport,
133136
middlewares: [swiftlyUserAgent]
134137
)
138+
}
135139

136-
let response = try await client.getCurrentSwiftlyRelease()
140+
public func getCurrentSwiftlyRelease() async throws -> Components.Schemas.SwiftlyRelease {
141+
let response = try await self.client().getCurrentSwiftlyRelease()
137142
return try response.ok.body.json
138143
}
139144

140145
public func getReleaseToolchains() async throws -> [Components.Schemas.Release] {
141-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
142-
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
143-
144-
let client = Client(
145-
serverURL: try Servers.Server1.url(),
146-
transport: AsyncHTTPClientTransport(configuration: config),
147-
middlewares: [swiftlyUserAgent]
148-
)
149-
150-
let response = try await client.listReleases()
151-
146+
let response = try await self.client().listReleases()
152147
return try response.ok.body.json
153148
}
154149

155150
public func getSnapshotToolchains(branch: Components.Schemas.SourceBranch, platform: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
156-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
157-
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
158-
159-
let client = Client(
160-
serverURL: try Servers.Server1.url(),
161-
transport: AsyncHTTPClientTransport(configuration: config),
162-
middlewares: [swiftlyUserAgent]
163-
)
164-
165-
let response = try await client.listDevToolchains(.init(path: .init(branch: branch, platform: platform)))
166-
151+
let response = try await self.client().listDevToolchains(.init(path: .init(branch: branch, platform: platform)))
167152
return try response.ok.body.json
168153
}
169154
}
@@ -301,11 +286,6 @@ public struct SwiftlyHTTPClient {
301286
self.httpRequestExecutor = httpRequestExecutor
302287
}
303288

304-
private struct Response {
305-
let status: HTTPResponseStatus
306-
let buffer: ByteBuffer
307-
}
308-
309289
public struct JSONNotFoundError: LocalizedError {
310290
public var url: String
311291
}

0 commit comments

Comments
 (0)