<commit_before>//
//  Created by <NAME>
//  http://www.petethedeveloper.com
//
//
//  License
//  Copyright © 2016-present <NAME>
//  Released under an MIT license: http://opensource.org/licenses/MIT
//

import Foundation

/**
 ### API client
 
 An API client for performing API requests
 */
struct APIClient {
    
    /**
     Perform GET requests using the specified URL
     
     - parameter url:        The URL endpoint
     - parameter completion: Completion closure expression
     */
    static func get(from url: String, completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()) {
        
        if let request = clientURLRequest(url) {
            dataTask(for: request, completion: completion)
        }
    }
    
    fileprivate static func clientURLRequest(_ url: String) -> URLRequest? {
        if let url = URL(string: url) {
            let request = URLRequest(url: url)
            return request
        }
        
        return nil
    }
    
    fileprivate static func dataTask(for request: URLRequest, completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()) {
        
        let session = URLSession(configuration: URLSessionConfiguration.default)
        
        session.dataTask(with: request) { (data, response, error) -> Void in
            
            DispatchQueue.main.async(execute: {
                
                if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) , let response = response as? HTTPURLResponse,  200...299 ~= response.statusCode {
                    
                    completion(true, json as AnyObject)
                    
                } else {
                    
                    completion(false, nil)
                }
            })
            
        }.resume()
    }
}<commit_msg>Leaks<commit_after>//
//  Created by <NAME>
//  http://www.petethedeveloper.com
//
//
//  License
//  Copyright © 2016-present <NAME>
//  Released under an MIT license: http://opensource.org/licenses/MIT
//

import Foundation

/**
 ### API client
 
 An API client for performing API requests
 */
struct APIClient {
    
    /**
     Perform GET requests using the specified URL
     
     - parameter url:        The URL endpoint
     - parameter completion: Completion closure expression
     */
    static func get(from url: String, completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()) {
        
        if let request = clientURLRequest(url) {
            dataTask(for: request, completion: completion)
        }
    }
    
    fileprivate static func clientURLRequest(_ url: String) -> URLRequest? {
        if let url = URL(string: url) {
            let request = URLRequest(url: url)
            return request
        }
        
        return nil
    }
    
    fileprivate static func dataTask(for request: URLRequest, completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()) {
        
        let session = URLSession(configuration: URLSessionConfiguration.default)
        
        session.dataTask(with: request) { (data, response, error) in
            
            DispatchQueue.main.async(execute: {
                
                if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) , let response = response as? HTTPURLResponse,  200...299 ~= response.statusCode {
                    
                    completion(true, json as AnyObject)
                    
                } else {
                    
                    completion(false, nil)
                }
            })
            
        }.resume()
        
        session.finishTasksAndInvalidate()
    }
}
{'fraction_non_alphanumeric': 0.0983739837398374, 'fraction_numerical': 0.005420054200542005, 'mean_word_length': 1.688273852876912, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5370410', 'n_tokens_mistral': 971, 'n_tokens_neox': 930, 'n_words': 268}