Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
NCMBのObservable化
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