<commit_before>//
//  WSClient.swift
//  Pods
//
//  Created by <NAME> on 2016-06-03.
//
//

import Foundation
import SwiftWebSocket
import SwiftyJSON


public class WSClient : RestClient {
    
    public func watch(completion: ((AnyObject) -> Void), failure: (NSError) -> Void) -> WebSocket {
        
        let request = NSMutableURLRequest(URL: NSURL(string:super.pushUrl!)!)
        if let accessToken : String = super.accessToken() {
            request.addValue("Bearer " + accessToken, forHTTPHeaderField: "Authorization")

        }
        
        let ws = WebSocket(request: request)
        
        ws.event.close = { code, reason, clean in
            print("close")
        }
        ws.event.error = { error in
            print("error \(error)")
        }
        
        ws.event.open = {
            print("OPENED")
        }
        ws.event.message = { message in
            if let text = message as? String {
                do {
                    if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
                        if let dict = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions()) as? NSDictionary {
                            if let obj = super.parseDict(dict) {
                                completion(obj)
                            }
                        }
                    }
                }
                catch let error as NSError {
                    failure(error)
                }
            }
        }
        ws.open()
        
        /*
         return AnonymousDisposable {
         request.cancel()
         }
         */
        
        return ws
    }<commit_msg>Cleaned up web socket messages<commit_after>//
//  WSClient.swift
//  Pods
//
//  Created by <NAME> on 2016-06-03.
//
//

import Foundation
import SwiftWebSocket
import SwiftyJSON


public class WSClient : RestClient {
    
    public func watch(completion: ((AnyObject) -> Void), failure: (NSError) -> Void) -> WebSocket {
        
        let request = NSMutableURLRequest(URL: NSURL(string:super.pushUrl!)!)
        if let accessToken : String = super.accessToken() {
            request.addValue("Bearer " + accessToken, forHTTPHeaderField: "Authorization")

        }
        
        let ws = WebSocket(request: request)
        
        ws.event.close = { code, reason, clean in
            print("WEBSOCKET: CLOSED")
        }
        ws.event.error = { error in
            print("WEBSOCKET ERROR: \(error)")
        }
        ws.event.open = {
            print("WEBSOCKET: OPENED")
        }
        
        ws.event.message = { message in
            if let text = message as? String {
                do {
                    if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
                        if let dict = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions()) as? NSDictionary {
                            if let obj = super.parseDict(dict) {
                                completion(obj)
                            }
                        }
                    }
                }
                catch let error as NSError {
                    failure(error)
                }
            }
        }
        ws.open()
        
        /*
         return AnonymousDisposable {
         request.cancel()
         }
         */
        
        return ws
    }
{'fraction_non_alphanumeric': 0.09480481361901967, 'fraction_numerical': 0.005283240387437629, 'mean_word_length': 1.256953642384106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370480', 'n_tokens_mistral': 950, 'n_tokens_neox': 871, 'n_words': 201}