From 9e3cb79bbfe4eb55ef820b6afed2129412eaabe9 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Wed, 13 Dec 2023 02:17:12 -0700 Subject: public structs --- Sources/swiftGopherClient/gopherClient.swift | 2 +- .../gopherRequestResponseHandler.swift | 29 ++++++++++++++-------- Sources/swiftGopherClient/gopherTypes.swift | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'Sources') diff --git a/Sources/swiftGopherClient/gopherClient.swift b/Sources/swiftGopherClient/gopherClient.swift index 6b76d94..e508285 100644 --- a/Sources/swiftGopherClient/gopherClient.swift +++ b/Sources/swiftGopherClient/gopherClient.swift @@ -19,7 +19,7 @@ public class GopherClient { try? group.syncShutdownGracefully() } - public func sendRequest(to host: String, port: Int = 70, message: String, completion: @escaping (Result) -> Void) { + public func sendRequest(to host: String, port: Int = 70, message: String, completion: @escaping (Result<[gopherItem], Error>) -> Void) { let bootstrap = ClientBootstrap(group: group) .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in diff --git a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift index 0cd040a..3d15d66 100644 --- a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift +++ b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift @@ -14,9 +14,9 @@ final class GopherRequestResponseHandler: ChannelInboundHandler { private var accumulatedData: ByteBuffer private let message: String - private let completion: (Result) -> Void + private let completion: (Result<[gopherItem], Error>) -> Void - init(message: String, completion: @escaping (Result) -> Void) { + init(message: String, completion: @escaping (Result<[gopherItem], Error>) -> Void) { self.message = message self.completion = completion self.accumulatedData = ByteBuffer() @@ -95,17 +95,24 @@ final class GopherRequestResponseHandler: ChannelInboundHandler { print("done parsing") - completion(.success(response)) + completion(.success(gopherServerResponse)) + + //completion(.success(response)) } } -struct gopherItem { - var rawLine: String - var message: String = "" - var parsedItemType: gopherItemType = .info - var host: String = "error.host" - var port: Int = 1 - var selector: String = "" - var valid: Bool = true +public struct gopherItem { + + public var rawLine: String + public var message: String = "" + public var parsedItemType: gopherItemType = .info + public var host: String = "error.host" + public var port: Int = 1 + public var selector: String = "" + public var valid: Bool = true + + public init(rawLine: String) { + self.rawLine = rawLine + } } diff --git a/Sources/swiftGopherClient/gopherTypes.swift b/Sources/swiftGopherClient/gopherTypes.swift index 2f1c99f..efec92e 100644 --- a/Sources/swiftGopherClient/gopherTypes.swift +++ b/Sources/swiftGopherClient/gopherTypes.swift @@ -41,7 +41,7 @@ import Foundation X document xml file "eXtensive Markup Language" ) */ -enum gopherItemType { +public enum gopherItemType { case text case directory case nameserver -- cgit v1.2.3