<commit_before>//
//  MFPClient.swift
//  HelloCordova
//
//  Created by <NAME> on 9/15/15.
//
//
import Foundation
import IMFCore

@objc(CDVBMSClient) class CDVBMSClient : CDVPlugin {
    
    func initialize(command: CDVInvokedUrlCommand) {
        
        guard let route  = command.arguments[0] as? String else {
            let message = "Invalid route."
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: message)
            // call success callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            return
        }
        
        guard let guid = command.arguments[1] as? String else{
            let message = "Invalid guid."
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: message)
            // call failure callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            return
        }
        
        self.commandDelegate!.runInBackground({
            let client = IMFClient.sharedInstance()
            
            //use category to handle objective-c exception
            let exceptionString = client.tryInitializeWithBackendRoute(route, backendGUID: guid)
            
            if exceptionString  == "" {
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: "")
                // call success callback
                self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            }
            else{
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: exceptionString)
                // call failure callback
                self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            }
        })
    }
    
    func backendRoute(command: CDVInvokedUrlCommand) {
        
        let client = IMFClient.sharedInstance()
        let backendRoute: String = client.backendRoute
        let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: backendRoute)
        // call success callback
        self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
        
    }
    
    func backendGUID(command: CDVInvokedUrlCommand) {
        
        let client = IMFClient.sharedInstance()
        let backendGUID: String = client.backendGUID
        let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: backendGUID)
        // call success callback
        self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
        
    }
}<commit_msg>added background threading to client methods<commit_after>//
//  MFPClient.swift
//  HelloCordova
//
//  Created by <NAME> on 9/15/15.
//
//
import Foundation
import IMFCore

@objc(CDVBMSClient) class CDVBMSClient : CDVPlugin {
    
    func initialize(command: CDVInvokedUrlCommand) {
        
        guard let route  = command.arguments[0] as? String else {
            let message = "Invalid route."
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: message)
            // call success callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            return
        }
        
        guard let guid = command.arguments[1] as? String else{
            let message = "Invalid guid."
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: message)
            // call failure callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            return
        }
        
        self.commandDelegate!.runInBackground({
            let client = IMFClient.sharedInstance()
            
            //use category to handle objective-c exception
            let exceptionString = client.tryInitializeWithBackendRoute(route, backendGUID: guid)
            
            if exceptionString  == "" {
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: "")
                // call success callback
                self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            }
            else{
                let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: exceptionString)
                // call failure callback
                self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
            }
        })
    }
    
    func backendRoute(command: CDVInvokedUrlCommand) {
        
        self.commandDelegate!.runInBackground({
            let client = IMFClient.sharedInstance()
            let backendRoute: String = client.backendRoute
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: backendRoute)
            // call success callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
        })
    }
    
    func backendGUID(command: CDVInvokedUrlCommand) {
        
        self.commandDelegate!.runInBackground({
            let client = IMFClient.sharedInstance()
            let backendGUID: String = client.backendGUID
            let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: backendGUID)
            // call success callback
            self.commandDelegate!.sendPluginResult(pluginResult, callbackId:command.callbackId)
        })
        
    }
}
{'fraction_non_alphanumeric': 0.07521186440677965, 'fraction_numerical': 0.0024717514124293787, 'mean_word_length': 2.3109292811221507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4481976', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1383, 'n_words': 299}