Last active
October 11, 2015 10:57
-
-
Save TORISOUP/43db916e431c7afd3ca8 to your computer and use it in GitHub Desktop.
NCMBのObservable化
This file contains 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
using System; | |
using NCMB; | |
using UniRx; | |
namespace ObservableNCMB | |
{ | |
public static class ObservableUserAuth | |
{ | |
/// <summary> | |
/// ログインする | |
/// </summary> | |
public static IObservable<NCMBUser> LoginAsync(string id, string password) | |
{ | |
return Observable.Create<NCMBUser>(observer => | |
{ | |
NCMBUser.LogInAsync(id, password, (NCMBException e) => | |
{ | |
if (e == null) | |
{ | |
observer.OnNext(NCMBUser.CurrentUser); | |
observer.OnCompleted(); | |
} | |
else | |
{ | |
observer.OnError(e); | |
} | |
}); | |
return Disposable.Create(() => { ; }); | |
}); | |
} | |
/// <summary> | |
/// 会員登録を行う | |
/// </summary> | |
public static IObservable<NCMBUser> SingUpAsync(string id, string password) | |
{ | |
return Observable.Create<NCMBUser>(observer => | |
{ | |
var user = new NCMBUser | |
{ | |
UserName = id, | |
Password = password | |
}; | |
user.SignUpAsync((NCMBException e) => | |
{ | |
if (e == null) | |
{ | |
observer.OnNext(user); | |
observer.OnCompleted(); | |
} | |
else | |
{ | |
observer.OnError(e); | |
} | |
}); | |
return Disposable.Create(() => {; }); | |
}); | |
} | |
/// <summary> | |
/// ログアウトする | |
/// </summary> | |
public static IObservable<Unit> LogoutAsync() | |
{ | |
return Observable.Create<Unit>(observer => | |
{ | |
NCMBUser.LogOutAsync((NCMBException e) => | |
{ | |
if (e == null) | |
{ | |
observer.OnNext(Unit.Default); | |
observer.OnCompleted(); | |
} | |
else | |
{ | |
observer.OnError(e); | |
} | |
}); | |
return Disposable.Create(() => {; }); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment