Last active
February 13, 2016 17:24
-
-
Save MariuszWisniewski/c042f41ce0c8106c7d67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let syncano = Syncano(apiKey: "API-KEY", instanceName: "INSTANCE-NAME") | |
func printError(error: NSError?) { | |
guard let error = error else { | |
return | |
} | |
let userInfo = error.userInfo | |
let syncanoError = userInfo[kSyncanoResponseErrorKey] | |
let detail = syncanoError?["detail"] | |
print("Error: \(detail)") | |
} | |
func register_logout_loginWrong_loginOk() { | |
let username = String(NSDate()) | |
let password = String(NSDate()) | |
let register = {(block: ()->()) -> () in | |
print("\n\nregister\n\n") | |
MyUser.registerWithUsername(username, password: password, inSyncano: self.syncano) { error in | |
let user = MyUser.currentUser() | |
let profile = user.myProfile | |
self.printError(error) | |
print("username = \(username) ==? user.username = \(user.username)") | |
print("User.ID = \(user.userId) == profile.owner == \(profile?.owner)") | |
block() | |
} | |
} | |
let logout = {(block: ()->()) -> () in | |
print("\n\nlogout\n\n") | |
MyUser.currentUser()?.logout() | |
block() | |
} | |
let loginWrong = {(block: ()->()) -> () in | |
print("\n\nlogin wrong\n\n") | |
MyUser.loginWithUsername(username, password: "wrongPassword", toSyncano: self.syncano, completion: { error in | |
let user : MyUser? = MyUser.currentUser() | |
let profile = user?.myProfile | |
self.printError(error) | |
print("username = \(username) ==? user.username = \(user?.username)") | |
print("User ID = \(user?.userId) == profile owner id == \(profile?.owner)") | |
block() | |
}) | |
} | |
let loginOk = {(block: ()->()) -> () in | |
print("\n\nlogin ok\n\n") | |
MyUser.loginWithUsername(username, password: password, toSyncano: self.syncano, completion: { error in | |
let user = MyUser.currentUser() | |
let profile = user.myProfile | |
self.printError(error) | |
print("username = \(username) ==? user.username = \(user.username)") | |
print("User ID = \(user.userId) == profile owner id == \(profile?.owner)") | |
block() | |
}) | |
} | |
logout(){ | |
register(){ | |
logout(){ | |
loginWrong(){ | |
loginOk(){} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment