     
 }
 
-public class AldoMainCallback: Callback {
+class AldoMainCallback: Callback {
     
     private var callback: Callback?
     

    public func onResponse(request: String, responseCode: Int, response: NSDictionary) {
        if responseCode == 200 {
            switch request {
            case Regex(pattern: AldoRequest.REQUEST_AUTH_TOKEN.regex()):
                Aldo.getStorage().set(response["token"], forKey: Aldo.Keys.AUTH_TOKEN.rawValue)
                break
            case Regex(pattern: AldoRequest.SESSION_CREATE.regex()):
                let data: [String: String] = [
                    "sessionID": response["sessionID"] as! String,
                    "playerID": response["playerID"] as! String,
                    "modToken": response["modToken"] as! String,
                    "userToken": response["userToken"] as! String,
                    "username": response["username"] as! String
                ]
                let session: AldoSession = AldoSession(data: data)
                let sessionData: Data = NSKeyedArchiver.archivedData(withRootObject: session)
                Aldo.getStorage().set(sessionData, forKey: Aldo.Keys.SESSION.rawValue)
                break
            case Regex(pattern: AldoRequest.SESSION_JOIN.regex()):
                let data: [String: String] = [
                    "sessionID": response["sessionID"] as! String,
                    "playerID": response["playerID"] as! String,
                    "modToken": "",
                    "userToken": "",
                    "username": response["username"] as! String
                ]
                let session: AldoSession = AldoSession(data: data)
                let sessionData: Data = NSKeyedArchiver.archivedData(withRootObject: session)
                Aldo.getStorage().set(sessionData, forKey: Aldo.Keys.SESSION.rawValue)
                break
            case Regex(pattern: AldoRequest.SESSION_INFO.regex()):
                print(response)
                break
            case Regex(pattern: AldoRequest.SESSION_PLAYERS.regex()):
                break
            case Regex(pattern: AldoRequest.SESSION_STATE_PLAY.regex()):
                break
            case Regex(pattern: AldoRequest.SESSION_STATE_PAUSE.regex()):
                break
            case AldoRequest.SESSION_DELETE.regex():
                Aldo.getStorage().removeObject(forKey: Aldo.Keys.SESSION.rawValue)
                Aldo.getStorage().synchronize()
                break
            case Regex(pattern: AldoRequest.PLAYER_ALL.regex()):
                break
            case Regex(pattern: AldoRequest.PLAYER_INFO.regex()):
                break
            case Regex(pattern: AldoRequest.PLAYER_USERNAME_UPDATE.regex()):
                break
            default:
                break

        }
    }
    
    private func createSession(response: NSDictionary) -> Session {
        let sessionId = response["sessionID"] as! String
        let adminId = response["adminID"] as! String
        let tokens = (response["tokens"] != nil) ? response["tokens"] as! NSDictionary : [:]
        let status = response["status"] as! Int
        let created = response["created"] as! String
        
        return Session(id: sessionId, admin: adminId, tokens: tokens, status: status, created: created)
    }
    
    private func savePlayer(response: NSDictionary) {
        let id = response["playerID"] as! String
        let username = response["username"] as! String
        let sessionDictionary = response["session"] as! NSDictionary
        let role = response["role"] as! Int
        let score = response["score"] as! Int
        
        let session: Session = createSession(response: sessionDictionary)
        let player: Player = Player(id: id, username: username, session: session, role: role, score: score)
        
        Aldo.setPlayer(player: player)
    }
    
}
