 import UIKit
 import Alamofire
 
+public typealias DictionaryCallback = (Dictionary<String,AnyObject>) -> Void
+public typealias ArrayCallback = (Array<AnyObject>) -> Void
+
 public class Worktile : AuthorizeWebControllerDelegate {
     
     /// 申请应用时分配的 AppKey

    
    :param: finishCallback 返回内容
    */
    public func profile(finishCallback:(Dictionary<String,AnyObject>) -> Void) {
        if let accessToken = accessToken {
            httpManager.request(.GET, "https://api.worktile.com/v1/user/profile", parameters: ["access_token":accessToken])
                .responseJSON { (_, _, JSON, _) -> Void in
                    if let jsonDict = JSON as? Dictionary<String,AnyObject> {
                        

        }
    }
    
    /**
    获取 access_token
    
    :returns: access_token
    */
    public func getAccessToken() {
        if let authorizeCode = self.authorizeCode {
            httpManager.request(.POST, "https://api.worktile.com/oauth2/access_token", parameters: ["client_id": self.clientID,"code":authorizeCode])
                .responseJSON { (_, _, JSON, _) in

                    var jsonDict = JSON as! [String:AnyObject]

                    // Success
                    if let accessToken = jsonDict["access_token"] as? String {
                        self.accessToken = accessToken
                    }

                    if let refreshToken = jsonDict["refresh_token"] as? String {
                        self.refreshToken = refreshToken
                    }
                    
                    
                    // Error
                    self.printErrorInfo(jsonDict)
            }
        }else{
            print("error : No authorizeCode.")
        }


    }
    
    /**
    刷新 access_token
    
    :returns: access_token
    */
    public func toRefreshToken(){
        if let refreshToken = self.refreshToken {
            Alamofire.request(.GET, URLString: "https://api.worktile.com/oauth2/refresh_token", parameters: ["client_id": clientID,"refresh_token": refreshToken])
                .responseJSON { (_, _, JSON, _) in
                    if let jsonDict = JSON as? Dictionary<String,AnyObject>{
                        
                        // Success
                        if let accessToken = jsonDict["access_token"] as? String {
                            self.accessToken = accessToken
                        }
                        
                        // Error
                        self.printErrorInfo(jsonDict)
                    }
            }
        }
    }

    /// 获取授权视图控制器
    public func authorizeViewController() -> UIViewController {
        currentAuthorizeViewController = AuthorizeWebController(url: self.authorizeURL, delegate: self)
        return currentAuthorizeViewController!
    }
    
    // MARK: User
    
    /**
