<commit_before>//
//  KatsanaAPI+Other.swift
//  KatsanaSDK
//
//  Created by <NAME> on 17/10/2016.
//  Copyright © 2016 pixelated. All rights reserved.
//
import SwiftyJSON

extension KatsanaAPI{
    
    func uploadImage(image : UIImage, path : String, completion : @escaping (Bool, Error?) -> Void) -> Void {
        //        let path = self.baseURL().absoluteString + "profile/avatar"
        let data = UIImageJPEGRepresentation(image, 0.9)! //Change to data
        Just.post(
            path,
            data: ["token": self.authToken],
            files: ["file": .data("avatar.png", data, "image/jpeg")]
        ) { r in
//            let strData = NSString(data: r.content!, encoding: String.Encoding.utf8.rawValue)
            if r.ok {
                completion(true, nil)
            }else{
                completion(false, r.error)
            }
        }
    }
    
    
    /// Request custom response from other application using current KatsanaAPI endpoint.
    ///
    /// - parameter path:       path to append to current endpoint
    /// - parameter completion: completion
    public func requestResponse(for path: String, completion: @escaping (_ response: Dictionary<String, Any>?, _ error: Error?) -> Void) -> Void {
        
        
        let fullPath = self.baseURL().absoluteString + path
        Just.get(
            fullPath,
            data: ["token": self.authToken]
        ) { r in
            let json = JSON(data: r.content!)
            let dicto = json.dictionaryObject
            completion(dicto, r.error)<commit_msg>Fixed custom path response not working<commit_after>//
//  KatsanaAPI+Other.swift
//  KatsanaSDK
//
//  Created by <NAME> on 17/10/2016.
//  Copyright © 2016 pixelated. All rights reserved.
//
import SwiftyJSON

extension KatsanaAPI{
    
    func uploadImage(image : UIImage, path : String, completion : @escaping (Bool, Error?) -> Void) -> Void {
        //        let path = self.baseURL().absoluteString + "profile/avatar"
        let data = UIImageJPEGRepresentation(image, 0.9)! //Change to data
        Just.post(
            path,
            data: ["token": self.authToken],
            files: ["file": .data("avatar.png", data, "image/jpeg")]
        ) { r in
//            let strData = NSString(data: r.content!, encoding: String.Encoding.utf8.rawValue)
            if r.ok {
                completion(true, nil)
            }else{
                completion(false, r.error)
            }
        }
    }
    
    
    /// Request custom response from other application using current KatsanaAPI endpoint.
    ///
    /// - parameter path:       path to append to current endpoint
    /// - parameter completion: completion
    public func requestResponse(for path: String, completion: @escaping (_ response: Dictionary<String, Any>?, _ error: Error?) -> Void) -> Void {
        
        let resource = API.resource(path);
        let request = resource.loadIfNeeded()
        request?.onSuccess({(entity) in
            let json = entity.content as? JSON
            let dicto = json?.dictionaryObject
            completion(dicto, nil)
        }).onFailure({ (error) in
            completion(nil, error)
        })
        
        if request == nil {
            let json = resource.latestData?.content as? JSON
            let dicto = json?.dictionaryObject
            completion(dicto, nil)
{'fraction_non_alphanumeric': 0.1178909952606635, 'fraction_numerical': 0.008886255924170616, 'mean_word_length': 1.8937446443873178, 'pattern_counts': {'":': 5, '<': 7, '<?xml version=': 0, '>': 15, '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': '2126718', 'n_tokens_mistral': 971, 'n_tokens_neox': 917, 'n_words': 262}