<commit_before>import Foundation
import p2_OAuth2

@objc class UberAuth: NSObject {
    static let sharedInstance = UberAuth()
    
    var oauth2: OAuth2?
    
    var token: String? {
        let defaults = NSUserDefaults.standardUserDefaults()
        return defaults.stringForKey("uber_token")
    }
    
    func save(token token: String) {
        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setValue(token, forKey: "uber_token")
    }
    
    var request_id: String? {
        let defaults = NSUserDefaults.standardUserDefaults()
        return defaults.stringForKey("request_id")
    }
    
    func saveRequestId(request_id request_id: String) {
        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setValue(request_id, forKey: "request_id")
    }
    
    func authenticate(completionHandler: Void -> Void) {
        print("authenticate")
        
        if let _ = token {
            return completionHandler()
        }
        
        let settings = [
            "client_id": Constants.uberClientId,
            "client_secret": Constants.uberClientSecret,
            "authorize_uri": "https://login.uber.com/oauth/v2/authorize",
            "token_uri": "https://login.uber.com/oauth/token",
            "redirect_uris": ["UBERGuide://oauth/callback"],
            "scope": "request",
        ] as OAuth2JSON
        
        oauth2 = OAuth2CodeGrant(settings: settings)
        oauth2!.verbose = true
        oauth2!.forgetTokens()
        oauth2!.onAuthorize = { parameters in
            print("Did authorize with parameters: \(parameters)")
            let token = parameters["access_token"] as! String
            self.save(token: token)<commit_msg>…fix bug<commit_after>import Foundation
import p2_OAuth2

@objc class UberAuth: NSObject {
    static let sharedInstance = UberAuth()
    
    var oauth2: OAuth2?
    
    var token: String? {
        let defaults = NSUserDefaults.standardUserDefaults()
        return defaults.stringForKey("uber_token")
    }
    
    func save(token token: String) {
        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setValue(token, forKey: "uber_token")
    }
    
    var request_id: String? {
        let defaults = NSUserDefaults.standardUserDefaults()
        if defaults.objectForKey("request_id") == nil {
            return " "
        } else {
            return defaults.stringForKey("request_id")
        }
    }
    
    func saveRequestId(request_id request_id: String) {
        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setValue(request_id, forKey: "request_id")
    }
    
    func authenticate(completionHandler: Void -> Void) {
        print("authenticate")
        
        if let _ = token {
            return completionHandler()
        }
        
        let settings = [
            "client_id": Constants.uberClientId,
            "client_secret": Constants.uberClientSecret,
            "authorize_uri": "https://login.uber.com/oauth/v2/authorize",
            "token_uri": "https://login.uber.com/oauth/token",
            "redirect_uris": ["UBERGuide://oauth/callback"],
            "scope": "request",
        ] as OAuth2JSON
        
        oauth2 = OAuth2CodeGrant(settings: settings)
        oauth2!.verbose = true
        oauth2!.forgetTokens()
        oauth2!.onAuthorize = { parameters in
            print("Did authorize with parameters: \(parameters)")
            let token = parameters["access_token"] as! String
            self.save(token: token)
{'fraction_non_alphanumeric': 0.10239099859353024, 'fraction_numerical': 0.006188466947960619, 'mean_word_length': 2.2774193548387096, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '322016', 'n_tokens_mistral': 1028, 'n_tokens_neox': 990, 'n_words': 201}