 
 public enum HTTPMethod: String {
     case GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, CONNECT
+}
+
+extension HTTPMethod {
+    func alamofireMethod() -> Alamofire.Method {
+        switch self {
+        case GET:
+            return .GET
+        case POST:
+            return .POST
+        case PUT:
+            return .PUT
+        case DELETE:
+            return .DELETE
+        case OPTIONS:
+            return .OPTIONS
+        case HEAD:
+            return .HEAD
+        case PATCH:
+            return .PATCH
+        case TRACE:
+            return .TRACE
+        case CONNECT:
+            return .CONNECT
+        }
+    }
 }
 
 public enum HTTPParameterEncoding {

extension DroskyResponse {
    func dataAsJSON() -> [String: AnyObject]? {
        let json: [String: AnyObject]?

        do {
            json = try NSJSONSerialization.JSONObjectWithData(self.data, options: NSJSONReadingOptions.AllowFragments) as? [String: AnyObject]
        } catch {
            json = nil
        }

        return json
    }
}

        }
        
        return Future(deferred)
    }
}

public typealias Signature = (header: String, value: String)

struct Router {
    let environment: Environment
    let signature: Signature?
    
    func urlRequestForEndpoint(endpoint: Endpoint) -> Result<URLRequestConvertible> {
        guard let URL = NSURL(string: environment.routeURL(endpoint.path)) else {
            return Result<URLRequestConvertible>(error: DroskyErrorKind.MalformedURLError)
        }
        
        let request = NSMutableURLRequest(URL: URL)
        request.HTTPMethod = endpoint.method.rawValue
        request.allHTTPHeaderFields = endpoint.httpHeaderFields
        if let signature = self.signature {
            request.setValue(signature.value, forHTTPHeaderField: signature.header)
        }
        
        let requestTuple = endpoint.parameterEncoding.alamofireParameterEncoding().encode(request, parameters: endpoint.parameters)
        
        if let error = requestTuple.1 {
            return Result<URLRequestConvertible>(error: error)
        } else {
            return Result<URLRequestConvertible>(requestTuple.0)
        }
    }
}

