<commit_before>import Foundation
import SocketIOClientSwift

@objc class LiveAuctionSocketCommunicator: NSObject {
    private let socket: SocketIOClient

    @objc init(host: String, accessToken: String, saleID: String) {
        socket = SocketIOClient(socketURL: NSURL(string: host)!, options: [.Log(true)])

        super.init()

        setupSocketWithAccessToken(accessToken, saleID: saleID)
    }

    deinit {
        socket.disconnect()
    }
}

private typealias SocketSetup = LiveAuctionSocketCommunicator
private extension SocketSetup {
    func setupSocketWithAccessToken(accessToken: String, saleID: String) {

        defer {
            socket.connect()
        }

        socket.on("connect") {data, ack in
            print("socket connected, authing...")
            self.socket.emit("authentication", ["accessToken": accessToken, "saleId": saleID])

            self.socket.on("authenticated") { data, ack in
                print("socket authenticated.")
            }
        }
    }
}<commit_msg>[Sockets] Cleans up auth handling.<commit_after>import Foundation
import SocketIOClientSwift

@objc class LiveAuctionSocketCommunicator: NSObject {
    private let socket: SocketIOClient

    @objc init(host: String, accessToken: String, saleID: String) {
        socket = SocketIOClient(socketURL: NSURL(string: host)!, options: [.Log(true)])

        super.init()

        setupSocketWithAccessToken(accessToken, saleID: saleID)
    }

    deinit {
        socket.disconnect()
    }
}

private typealias SocketSetup = LiveAuctionSocketCommunicator
private extension SocketSetup {

    /// Connects to, then authenticates against, the socket. Listens for sale events.
    func setupSocketWithAccessToken(accessToken: String, saleID: String) {
        socket.authenticateWithAccessToken(accessToken, saleID: saleID)
        self.listenForSaleEvents()
        socket.connect()
    }

    func listenForSaleEvents() {

    }
}

private typealias Socket = SocketIOClient
extension SocketIOClient {
    func authenticateWithAccessToken(accessToken: String, saleID: String) {

        on("connect") { data, ack in
            self.emit("authentication", ["accessToken": accessToken, "saleId": saleID])
            self.on("authenticated") { data, ack in
                // TODO: Handle auth failure.
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09808102345415778, 'fraction_numerical': 0.0, 'mean_word_length': 2.9965928449744466, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2369929', 'n_tokens_mistral': 682, 'n_tokens_neox': 646, 'n_words': 156}