<commit_before>//
//  Neptune.swift
//  Neptune
//
//  Created by <NAME> on 11/24/15.
//  Copyright © 2015 HODINKEE. All rights reserved.
//

import Foundation

extension NSUserDefaults {

    public typealias Completion = ([String: AnyObject]?, NSError?) -> ()

    public func registerDefaults(localURL localURL: NSURL, remoteURL: NSURL, completion: Completion? = nil) {
        let request = NSMutableURLRequest(URL: remoteURL, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 10.0)
        request.setValue("application/json", forHTTPHeaderField: "Accept")
        registerDefaults(fileURL: localURL, URLRequest: request, completion: completion)
    }

    public func registerDefaults(fileURL fileURL: NSURL, URLRequest request: NSURLRequest, completion: Completion? = nil) {
        guard let dictionary = NSDictionary(contentsOfURL: fileURL) as? [String: AnyObject] else {
            fatalError("The item at \(fileURL) is not a valid dictionary.")
        }

        for (key, value) in dictionary {
            self.setObject(value, forKey: key)
        }

        NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { data, response, error in
            guard
                let response = response as? NSHTTPURLResponse where ClosedInterval(200, 299).contains(response.statusCode),
                let data = data<commit_msg>Switch from ClosedInterval to Range.<commit_after>//
//  Neptune.swift
//  Neptune
//
//  Created by <NAME> on 11/24/15.
//  Copyright © 2015 HODINKEE. All rights reserved.
//

import Foundation

extension NSUserDefaults {

    public typealias Completion = ([String: AnyObject]?, NSError?) -> ()

    public func registerDefaults(localURL localURL: NSURL, remoteURL: NSURL, completion: Completion? = nil) {
        let request = NSMutableURLRequest(URL: remoteURL, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 10.0)
        request.setValue("application/json", forHTTPHeaderField: "Accept")
        registerDefaults(fileURL: localURL, URLRequest: request, completion: completion)
    }

    public func registerDefaults(fileURL fileURL: NSURL, URLRequest request: NSURLRequest, completion: Completion? = nil) {
        guard let dictionary = NSDictionary(contentsOfURL: fileURL) as? [String: AnyObject] else {
            fatalError("The item at \(fileURL) is not a valid dictionary.")
        }

        for (key, value) in dictionary {
            self.setObject(value, forKey: key)
        }

        NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { data, response, error in
            guard
                let response = response as? NSHTTPURLResponse where (200...299).contains(response.statusCode),
                let data = data
{'fraction_non_alphanumeric': 0.09871703492516037, 'fraction_numerical': 0.0135424091233072, 'mean_word_length': 3.3184615384615386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '75065', 'n_tokens_mistral': 807, 'n_tokens_neox': 749, 'n_words': 216}