commit 870fef1b7dfa13c8f01d88c3457e0b54a95afd70
parent 9ac6c7476c974f26fc5faeb7548bfa3eecb9ac33
Author: FIGBERT <figbert@figbert.com>
Date: Sat, 3 Sep 2022 13:32:31 -0700
Export public API
Diffstat:
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/Sources/SwiftGemini/MetaHeader.swift b/Sources/SwiftGemini/MetaHeader.swift
@@ -1,6 +1,6 @@
import Foundation
-enum MetaHeader {
+public enum MetaHeader {
case Prompt(String)
case MIME(String)
case Redirect(URL)
diff --git a/Sources/SwiftGemini/StatusCode.swift b/Sources/SwiftGemini/StatusCode.swift
@@ -1,6 +1,6 @@
import Foundation
-enum StatusCode: Int {
+public enum StatusCode: Int {
case Input = 10
case SensitiveInput = 11
case Success = 20
diff --git a/Sources/SwiftGemini/SwiftGemini.swift b/Sources/SwiftGemini/SwiftGemini.swift
@@ -1,15 +1,15 @@
import Foundation
import Network
-class GeminiRequestor {
+public class GeminiRequestor {
static let queue = DispatchQueue(label: "gemini", qos: .default)
- fileprivate var conn: NWConnection?
+ var conn: NWConnection?
- enum GeminiRequestorError: Error {
+ public enum GeminiRequestorError: Error {
case invalidResponseHeader
}
- func request(url: URL) async throws -> GeminiResponse {
+ public func request(url: URL) async throws -> GeminiResponse {
let response: GeminiResponse = try await withCheckedThrowingContinuation({ continuation in
requestWithCompletion(url: url, completion: { result in
switch result {
@@ -23,7 +23,7 @@ class GeminiRequestor {
return response
}
- func requestWithCompletion(url: URL, completion: @escaping (Result<GeminiResponse, Error>) -> Void) {
+ public func requestWithCompletion(url: URL, completion: @escaping (Result<GeminiResponse, Error>) -> Void) {
guard url.user == nil && url.password == nil,
url.host != nil && url.absoluteString.data(using: .utf8)!.count <= 1024 else { return }
@@ -51,7 +51,7 @@ class GeminiRequestor {
}))
}
- fileprivate func parseResponse(url: URL, data: Data) -> Result<GeminiResponse, Error> {
+ func parseResponse(url: URL, data: Data) -> Result<GeminiResponse, Error> {
guard let ix = data.firstIndex(of: 13),
data[ix+1] == 10, ix < (1024+3) else { return .failure(GeminiRequestorError.invalidResponseHeader) }
var header = String(data: data.prefix(upTo: ix), encoding: .utf8)!
@@ -82,7 +82,7 @@ class GeminiRequestor {
))
}
- fileprivate func parseBody(header: MetaHeader, data: Data) -> GeminiBody {
+ func parseBody(header: MetaHeader, data: Data) -> GeminiBody {
let ix = data.firstIndex(of: 13)! + 2
let body = data.suffix(from: ix)
var gemtext, text: String?
@@ -98,14 +98,14 @@ class GeminiRequestor {
}
}
-struct GeminiResponse {
+public struct GeminiResponse {
let url: URL
let status: StatusCode
let header: MetaHeader
let body: GeminiBody?
}
-struct GeminiBody {
+public struct GeminiBody {
let raw: Data
let text, gemtext: String?
}