         let injectableRequest = mocked.copy() as! NSURLRequest
         
         return injectableRequest
-
+        
     }
     
     private func mockURLForRequestURL(url: NSURL, requestMethod: RequestMethod, mocks: Dictionary<String,AnyObject>) -> NSURL? {

            return "html"
        case "application/json":
            return "json"
        default:
            return "txt"
        }
    }
    
    private func mockedResponseFilePath(url: NSURL)->String? {
        
        return mockedFilePath(mockedResponseFileName(url))
    }
    
    private func mockedResponseHeadersFilePath(url: NSURL)->String? {
        
        return mockedFilePath(mockedResponseHeadersFileName(url))
    }
    
    private func mockedFilePath(fileName: String?)->String? {
        
        let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
        let documentsDirectory = paths[0] as? String
        
        guard let fileName =  fileName,
            let filePath = documentsDirectory?.stringByAppendingString("/\(fileName)") else {
                return nil
        }
        
        print("Mocked response recorded in: \(filePath)")
        return filePath
    }
    
    private func mockedResponseFileName(url: NSURL)->String? {
        
        return  mockedResponseFileName(url, isData: true)
    }
    
    private func mockedResponseHeadersFileName(url: NSURL)->String? {
        
        return  mockedResponseFileName(url, isData: false)
    }
    
    private func mockedResponseFileName(url: NSURL, isData:Bool)->String? {
        
        var urlString = url.absoluteString
        let urlStringLengh = urlString.characters.count
        let fromIndex = (urlStringLengh > maxFileLegth) ?maxFileLegth : urlStringLengh
        urlString = urlString.substringFromIndex(urlString.endIndex.advancedBy(-fromIndex))
        guard let fileName = urlString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()) else {
            fatalError("You must provide a request with a valid URL")
        }
        if isData && recording {
            return  fileName + "DATA." + fileType(mimeType(url))
        }
        return  fileName + "." + fileType(mimeType(url))
    }
    
    private func mockFileOutOfBundle()->String? {
        
        let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
        let documentsDirectory = paths[0] as? String
        guard let mockPath = documentsDirectory?.stringByAppendingString("/\(mocksFile)"),
            let bundle = bundle else {
                return nil
        }
        
        if !NSFileManager.defaultManager().fileExistsAtPath(mockPath),
            let definitionsPath = bundle.pathForResource("Mocks", ofType: "plist"),
            let definitions = NSMutableDictionary(contentsOfFile: definitionsPath) {
                definitions.writeToFile(mockPath, atomically: true)
        } else {
            let mockDictionary = NSDictionary(dictionary:["mimes":[["htm":"text/html"],["html":"text/html"],["json":"application/json"]],["mocks"]:[["DELETE":[:]],["POST":[:]],["PUT":[:]],["GET":[:]]]])
            mockDictionary.writeToFile(mockPath, atomically: true)
        }
        
        return mockPath
    }
}


            let definitions = NSDictionary(contentsOfFile: definitionsPath) as? Dictionary<String,AnyObject>,
            let mocks = definitions["mocks"] as? Dictionary<String,AnyObject>,
            let mimes = definitions["mimes"] as? Dictionary<String,String> {
                self.mocks = mocks
                self.mimes = mimes
        }
    }
    
