<commit_before>//
//  CuriosityRoverDataService.swift
//  CuriosityRover
//
//  Created by <NAME> on 3/4/16.
//
//

import Foundation

class CuriosityRoverDataService
{
    func getData(_ completion: @escaping ((_ JSON: JSONType?, _ error:ServiceError?) -> Void))
    {
        let options = Options()
        
        let sessionConfig = URLSessionConfiguration.default
        let session = URLSession(configuration: sessionConfig)
        
        let apiKey = CuriosityRoverDataService.apiKey()
        let URLString = "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=\(options.dateString)&page=\(options.page)&api_key=\(apiKey)"
        
        print("requesting data from: \(URLString)")
        
        if let URL = URL(string: URLString)
        {
            let task = session.dataTask(with: URL, completionHandler: { (data, URLResponse, error) -> Void in
                
                print("response: \n\tdata:\(data)\n\tURLResponse:\(URLResponse)\n\terror:\(error)")
                
                if let error = error
                {
                    print("[--ERROR--]")
                    completion(nil,.errorInResponse(error: error as NSError))
                }
                else
                {
                    if let data = data,
                        let JSONObject = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions(rawValue: 0))
                    {
                        print("[--GOOD RESPONSE--]:")
                        let JSON = JSONType.create(jsonObject: JSONObject)
                        completion(JSON,nil)
                    }
                    else
                    {
                        print("[--BAD RESPONSE--]: NON-JSON")
                        completion(nil,.nonJSONResponseData(data:data))
                    }
                }
            }) 
            task.resume()
        }
        else
        {<commit_msg>minor simplification to son serialization<commit_after>//
//  CuriosityRoverDataService.swift
//  CuriosityRover
//
//  Created by <NAME> on 3/4/16.
//
//

import Foundation

class CuriosityRoverDataService
{
    func getData(_ completion: @escaping ((_ JSON: JSONType?, _ error:ServiceError?) -> Void))
    {
        let options = Options()
        
        let sessionConfig = URLSessionConfiguration.default
        let session = URLSession(configuration: sessionConfig)
        
        let apiKey = CuriosityRoverDataService.apiKey()
        let URLString = "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=\(options.dateString)&page=\(options.page)&api_key=\(apiKey)"
        
        print("requesting data from: \(URLString)")
        
        if let URL = URL(string: URLString)
        {
            let task = session.dataTask(with: URL, completionHandler: { (data, URLResponse, error) -> Void in
                
                print("response: \n\tdata:\(data)\n\tURLResponse:\(URLResponse)\n\terror:\(error)")
                
                if let error = error
                {
                    print("[--ERROR--]")
                    completion(nil,.errorInResponse(error: error as NSError))
                }
                else
                {
                    if let data = data,
                        let JSONObject = try? JSONSerialization.jsonObject(with: data, options: [])
                    {
                        print("[--GOOD RESPONSE--]:")
                        let JSON = JSONType.create(jsonObject: JSONObject)
                        completion(JSON,nil)
                    }
                    else
                    {
                        print("[--BAD RESPONSE--]: NON-JSON")
                        completion(nil,.nonJSONResponseData(data:data))
                    }
                }
            }) 
            task.resume()
        }
        else
        {
{'fraction_non_alphanumeric': 0.11119612343789849, 'fraction_numerical': 0.0028054067839836778, 'mean_word_length': 1.3870967741935485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '7050401', 'n_tokens_mistral': 1065, 'n_tokens_neox': 994, 'n_words': 188}