<commit_before>//
//  ABEReporter.swift
//  Pods
//
//  Created by <NAME> on 10/9/16.
//
//

import Foundation
import UIKit

fileprivate extension Dictionary {
    mutating func update(other: Dictionary) {
        for (key,value) in other {
            self.updateValue(value, forKey:key)
        }
    }
}

public protocol ABEReporterDelegate {
    
    func extraDebuggingInformationForIssue() -> [String : String]
}

public class ABEReporter: NSObject {
    
    public static var enabled: Bool = true
    internal static var delegate: ABEReporterDelegate?
    
    private weak static var reporterViewController: ABEReporterViewController?
    private static var notificationObserver: NSObjectProtocol? = nil
    
    internal class func extraDebuggingInformationForIssue() -> [String : String] {
        var info = ["Current Localization : " : Locale.preferredLanguages[0],
                    "Current Device : " : UIDevice.current.model,
                    "iOS Version : " : UIDevice.current.systemVersion]
        
        if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
            info.updateValue(appVersion, forKey: "App Version")
        }
        
        if let bundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
            info.updateValue(bundleVersion, forKey: "Bundle Version")
        }
        
        if let extra = ABEReporter.delegate?.extraDebuggingInformationForIssue() {
            info.update(other: extra)
        }
    
        return info
    }
    
    open override static func initialize() {
        
        if self !== ABEReporter.self {
            return
        }
        
        ABEReporter.notificationObserver = NotificationCenter.default.addObserver(forName: .onWindowShake, object: nil, queue: .main) { notification in
            ABEReporter.showReporterView()
        }
    }
    
    deinit {
        if let notificationObserver = ABEReporter.notificationObserver {
            NotificationCenter.default.removeObserver(notificationObserver)
        }
    }
    
    public class func setup(repositoryName name: String, owner: String, token: String, imgurKey: String? = nil) {
        ABEGithubAPIClient.githubRepositoryName = name
        ABEGithubAPIClient.githubRepositoryOwner = owner
        ABEGithubAPIClient.githubToken = token
        
        ABEImgurAPIClient.imgurAPIKey = imgurKey
    }
    
    public class func showReporterView() {
        if self.reporterViewController != nil || !enabled {
            return;
        }
        
        guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController else {
            print("No root view controller ")
            return
        }
        
        let presentationTarget = presentingTargetForReporterViewController(cannidate: rootViewController)
        let reporterViewController = ABEReporterViewController.instance(withIssueManager: ABEIssueManager(referenceView: presentationTarget.view))
        
        self.reporterViewController = reporterViewController
        let navigationController = UINavigationController(rootViewController: reporterViewController)
        
        presentationTarget.present(navigationController, animated: true)
    }
    
    private class func presentingTargetForReporterViewController(cannidate: UIViewController) -> UIViewController {
    
        if let newCannidate = cannidate.presentedViewController {
            return presentingTargetForReporterViewController(cannidate: newCannidate)
        } else {
            return cannidate
        }
    }
}
<commit_msg>Made extraDebuggingInformationForIssue as public, made small refactoring<commit_after>//
//  ABEReporter.swift
//  Pods
//
//  Created by <NAME> on 10/9/16.
//
//

import Foundation
import UIKit

public protocol ABEReporterDelegate {
    
    func extraDebuggingInformationForIssue() -> [String: String]
}

public class ABEReporter: NSObject {
    
    public static var enabled: Bool = true
    public static var delegate: ABEReporterDelegate?
    
    private weak static var reporterViewController: ABEReporterViewController?
    private static var notificationObserver: NSObjectProtocol? = nil
    
    public class func extraDebuggingInformationForIssue() -> [String: String] {
        var info = [
            "Current Localization": Locale.preferredLanguages[0],
            "Current Device": UIDevice.current.model,
            "iOS Version": UIDevice.current.systemVersion
        ]
        info["App Version"] = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
        info["Bundle Version"] = Bundle.main.infoDictionary?["CFBundleVersion"] as? String
        
        ABEReporter.delegate?.extraDebuggingInformationForIssue().forEach { info[$0] = $1 }
    
        return info
    }
    
    open override static func initialize() {
        
        if self !== ABEReporter.self {
            return
        }
        
        ABEReporter.notificationObserver = NotificationCenter.default.addObserver(forName: .onWindowShake, object: nil, queue: .main) { notification in
            ABEReporter.showReporterView()
        }
    }
    
    deinit {
        if let notificationObserver = ABEReporter.notificationObserver {
            NotificationCenter.default.removeObserver(notificationObserver)
        }
    }
    
    public class func setup(repositoryName name: String, owner: String, token: String, imgurKey: String? = nil) {
        ABEGithubAPIClient.githubRepositoryName = name
        ABEGithubAPIClient.githubRepositoryOwner = owner
        ABEGithubAPIClient.githubToken = token
        
        ABEImgurAPIClient.imgurAPIKey = imgurKey
    }
    
    public class func showReporterView() {
        if self.reporterViewController != nil || !enabled {
            return;
        }
        
        guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController else {
            print("No root view controller")
            return
        }
        
        let presentationTarget = presentingTargetForReporterViewController(cannidate: rootViewController)
        let reporterViewController = ABEReporterViewController.instance(withIssueManager: ABEIssueManager(referenceView: presentationTarget.view))
        
        self.reporterViewController = reporterViewController
        let navigationController = UINavigationController(rootViewController: reporterViewController)
        
        presentationTarget.present(navigationController, animated: true)
    }
    
    private class func presentingTargetForReporterViewController(cannidate: UIViewController) -> UIViewController {
    
        if let newCannidate = cannidate.presentedViewController {
            return presentingTargetForReporterViewController(cannidate: newCannidate)
        } else {
            return cannidate
        }
    }
}

{'fraction_non_alphanumeric': 0.0736231884057971, 'fraction_numerical': 0.002028985507246377, 'mean_word_length': 2.672698243746674, 'pattern_counts': {'":': 3, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3001879', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1729, 'n_words': 386}