<commit_before>//
//  NetworkOperation.swift
//  Stormy
//
//  Created by Domenico on 16/04/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

class NetworkOperation{
    
    lazy var config:NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
    lazy var session:NSURLSession = NSURLSession(configuration: self.config)
    var queryUrl:NSURL
    
    init(url:NSURL){
        self.queryUrl = url
    }
}<commit_msg>Adding function for downloading the json from the forecast service<commit_after>//
//  NetworkOperation.swift
//  Stormy
//
//  Created by Domenico on 16/04/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

class NetworkOperation{
    
    lazy var config:NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
    lazy var session:NSURLSession = NSURLSession(configuration: self.config)
    var queryUrl:NSURL
    typealias JSONDictionaryCompletion = ([String: AnyObject]? -> Void)
    
    init(url:NSURL){
        self.queryUrl = url
    }
    
    func downloadJSONFromURL(completion: JSONDictionaryCompletion){
        // Create the request
        let request = NSURLRequest(URL: self.queryUrl)
        
        let dataTask = session.dataTaskWithRequest(request){
            (let data, let response, let error) in
            // Clousure!
            
            if let httpResponse = response as? NSHTTPURLResponse{
                // NSHTTPURLRespons has a status code property!
                
                switch(httpResponse.statusCode){
                case 200: // Successful request
                    // Parse the json data
                    do{
                        let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as? [String:AnyObject]
                        // Call the callback function "completion"
                        completion(jsonDictionary!)
                    }catch(_){
                        print("Error parsing the data!!")
                    }
                    
                    
                default:
                    print("Error requesting the data. Status Code \(httpResponse.statusCode)")
                }
            }else{
                print("Error requesting the data. The response is invalid")
            }
        }
        
        dataTask.resume()
    
    }
}
{'fraction_non_alphanumeric': 0.08110333470564018, 'fraction_numerical': 0.009468917249897077, 'mean_word_length': 1.832167832167832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2221594', 'n_tokens_mistral': 627, 'n_tokens_neox': 595, 'n_words': 160}