<commit_before>//
//  NetworkService.swift
//  theiostmdb
//
//  Created by <NAME>  on 10/3/17.
//
//

import Foundation
import Alamofire

class NetworkService : NSObject {
    
    let api_key = "71fbe398f71c98f66552653199f9f592"
    let base_url = "https://api.themoviedb.org/3/"
    let images_url = "https://image.tmdb.org/t/p/w500/"
    let discover_url = "discover/movie"
    let search_url = "https://api.themoviedb.org/3/search/movie?api_key=71fbe398f71c98f66552653199f9f592&language=en-US&query=%2$s&page=%3$s&amp;include_adult=false"
    
    static let shared : NetworkService = NetworkService()
    
    func discoverMovies(page: Int, completionHandler: @escaping ([Film]) -> Void, errorHandler: @escaping (String) -> Void){
        Alamofire.request("\(self.base_url)\(self.discover_url)", method: .get,parameters: self.discoverParams(page: page),encoding: URLEncoding.default, headers:nil).responseJSON(completionHandler:{ (response) in
                NSLog("DiscoverRequest Reached")
            guard  let object = response.result.value as? [String : Any] else{
               errorHandler("Error General")
                return
            }
            if let results = object["results"] as? [[String: Any]]{
                var films = [Film]()
                for i in 0..<results.count{
                    films.append(Film.init(dictionary: results[i] as [String : AnyObject]))
                }
                DispatchQueue.main.async {
                    print("Response thread: \(Thread.current) is main thread: \(Thread.isMainThread)")
                    completionHandler(films)
                }
            }else{
                errorHandler(String(describing: response.result.value));
            }
            
        })
    }
    
    
    func convertToDictionary(text: String) -> [[String: Any]]? {
        if let data = text.data(using: .utf8) {
            do {<commit_msg>Change log for load page<commit_after>//
//  NetworkService.swift
//  theiostmdb
//
//  Created by <NAME>  on 10/3/17.
//
//

import Foundation
import Alamofire

class NetworkService : NSObject {
    
    let api_key = "71fbe398f71c98f66552653199f9f592"
    let base_url = "https://api.themoviedb.org/3/"
    let images_url = "https://image.tmdb.org/t/p/w500/"
    let discover_url = "discover/movie"
    let search_url = "https://api.themoviedb.org/3/search/movie?api_key=71fbe398f71c98f66552653199f9f592&language=en-US&query=%2$s&page=%3$s&amp;include_adult=false"
    
    static let shared : NetworkService = NetworkService()
    
    func discoverMovies(page: Int, completionHandler: @escaping ([Film]) -> Void, errorHandler: @escaping (String) -> Void){
        Alamofire.request("\(self.base_url)\(self.discover_url)", method: .get,parameters: self.discoverParams(page: page),encoding: URLEncoding.default, headers:nil).responseJSON(completionHandler:{ (response) in
                NSLog("Load discover page: %d", page)
            guard  let object = response.result.value as? [String : Any] else{
               errorHandler("Error General")
                return
            }
            if let results = object["results"] as? [[String: Any]]{
                var films = [Film]()
                for i in 0..<results.count{
                    films.append(Film.init(dictionary: results[i] as [String : AnyObject]))
                }
                DispatchQueue.main.async {
                    print("Response thread: \(Thread.current) is main thread: \(Thread.isMainThread)")
                    completionHandler(films)
                }
            }else{
                errorHandler(String(describing: response.result.value));
            }
            
        })
    }
    
    
    func convertToDictionary(text: String) -> [[String: Any]]? {
        if let data = text.data(using: .utf8) {
            do {
{'fraction_non_alphanumeric': 0.12759875259875259, 'fraction_numerical': 0.032224532224532226, 'mean_word_length': 2.2236180904522613, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 6, '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': '7547098', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1149, 'n_words': 227}