Skip to content

Instantly share code, notes, and snippets.

@TORISOUP
Last active October 11, 2015 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TORISOUP/43db916e431c7afd3ca8 to your computer and use it in GitHub Desktop.
Save TORISOUP/43db916e431c7afd3ca8 to your computer and use it in GitHub Desktop.
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