/// <summary> /// 指定IDのオブジェクトを取得を行います。<br/> /// 通信結果を受け取るために必ずコールバックを設定を行います。 /// </summary> /// <param name="objectId"> オブジェクトID</param> /// <param name="callback"> コールバック</param> public void GetAsync(string objectId, NCMBGetCallback <T> callback) { if (callback == null) { throw new ArgumentException("It is necessary to always set a callback."); } new AsyncDelegate(delegate { string url = _getSearchUrl(this._className); //クラス毎のURL作成 //オブジェクト取得API url += "/" + objectId; ConnectType type = ConnectType.GET; //メソッドタイプの設定 //通信処理 NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { Dictionary <string, object> resultObj; NCMBObject objectData = null; try { if (error == null) { resultObj = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; objectData = _convertGetResponse(resultObj); } } catch (Exception e) { error = new NCMBException(e); } //引数はリスト(中身NCMBObject)とエラーをユーザーに返す Platform.RunOnMainThread(delegate { callback((T)objectData, error); }); return; }); }).BeginInvoke((IAsyncResult r) => { }, null); }
/// <summary> /// 非同期処理でファイルのダウンロードを行います。<br/> /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。 /// </summary> /// <param name="callback">コールバック</param> public void FetchAsync(NCMBGetFileCallback callback) { // fileName必須 if ((this.FileName == null)) { throw new NCMBException("fileName must not be null."); } new AsyncDelegate(delegate { // 通信処理 NCMBConnection con = new NCMBConnection(_getBaseUrl(), ConnectType.GET, null, NCMBUser._getCurrentSessionToken(), this); con.Connect(delegate(int statusCode, byte[] responseData, NCMBException error) { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); this.estimatedData ["fileData"] = responseData; if (callback != null) { Platform.RunOnMainThread(delegate { callback(responseData, error); }); } return; }); }).BeginInvoke((IAsyncResult r) => { }, null); }
/// <summary> /// 非同期処理で指定したメールアドレスに対して、<br/> /// 会員登録を行うためのメールを送信するよう要求します。<br/> /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。 /// </summary> /// <param name="email">メールアドレス</param> /// <param name="callback">コールバック</param> public static void RequestAuthenticationMailAsync(string email, NCMBCallback callback) { //URL string url = _getmailAddressUserEntryUrl(); //URL //コンテント NCMBUser user = new NCMBUser(); user.Email = email; string content = user._toJSONObjectForSaving(user.StartSave()); //Type ConnectType type = ConnectType.POST; NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (callback != null) { callback(error); } return; }); }
internal static void _logOut(NCMBCallback callback) { string url = _getLogOutUrl(); //URL作成 ConnectType type = ConnectType.GET; string content = null; //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); //通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage); } else { _logOutEvent(); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { Platform.RunOnMainThread(delegate { callback(error); }); } return; }); }
private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback) { string url = _getLogInUrl(); ConnectType type = ConnectType.GET; Dictionary <string, object> paramDic = new Dictionary <string, object>(); paramDic["password"] = password; //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー if (name != null) { paramDic["userName"] = name; } else if (email != null) { paramDic["mailAddress"] = email; } else { throw new NCMBException(new ArgumentException("UserName or Email can not be null.")); } url = _makeParamUrl(url + "?", paramDic); //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type); //通信処理 NCMBConnection con = new NCMBConnection(url, type, null, null); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage); } else { Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; //save Current user NCMBUser logInUser = new NCMBUser(); logInUser._handleFetchResult(true, responseDic); _saveCurrentUser(logInUser); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { callback(error); } return; }); }
private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback) { string url = _getLogInUrl(); //URL作成 ConnectType type = ConnectType.GET; //set username, password NCMBUser logInUser = new NCMBUser(); logInUser.Password = password; //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー if (name != null) { logInUser.UserName = name; } else if (email != null) { logInUser.Email = email; } else { throw new NCMBException(new ArgumentException("UserName or Email can not be null.")); } string content = logInUser._toJSONObjectForSaving(logInUser.StartSave()); Dictionary <string, object> paramDic = (Dictionary <string, object>)MiniJSON.Json.Deserialize(content); url = _makeParamUrl(url + "?", paramDic); //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); //通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage); } else { Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; logInUser._handleFetchResult(true, responseDic); //save Current user _saveCurrentUser(logInUser); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { Platform.RunOnMainThread(delegate { callback(error); }); } return; }); }
internal static void TrackAppOpened(string _pushId) //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics { //ネイティブから取得したpushIdからリクエストヘッダを作成 if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics) { string deviceType = ""; if (SystemInfo.operatingSystem.IndexOf("Android") != -1) { deviceType = "android"; } else if (SystemInfo.operatingSystem.IndexOf("iPhone") != -1) { deviceType = "ios"; } //RESTリクエストデータ生成 Dictionary <string, object> requestData = new Dictionary <string, object> { { "pushId", _pushId }, { "deviceToken", NCMBManager._token }, { "deviceType", deviceType } }; var json = Json.Serialize(requestData); string url = CommonConstant.DOMAIN_URL + "/" + CommonConstant.API_VERSION + "/push/" + _pushId + "/openNumber"; ConnectType type = ConnectType.POST; string content = json.ToString(); NCMBDebug.Log("content:" + content); //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); // 通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); } catch (Exception e) { error = new NCMBException(e); } return; }); #if UNITY_IOS #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 NotificationServices.ClearRemoteNotifications(); #else UnityEngine.iOS.NotificationServices.ClearRemoteNotifications(); #endif #endif } }
/// <summary> /// 非同期処理でファイルの保存を行います。<br/> /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。 /// </summary> /// <param name="callback">コールバック</param> public override void SaveAsync(NCMBCallback callback) { if ((this.FileName == null)) { throw new NCMBException("fileName must not be null."); } new AsyncDelegate(delegate { ConnectType type; if (this.CreateDate != null) { type = ConnectType.PUT; } else { type = ConnectType.POST; } IDictionary <string, INCMBFieldOperation> currentOperations = null; currentOperations = this.StartSave(); string content = _toJSONObjectForSaving(currentOperations); NCMBConnection con = new NCMBConnection(_getBaseUrl(), type, content, NCMBUser._getCurrentSessionToken(), this); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { // 失敗 this._handleSaveResult(false, null, currentOperations); } else { Dictionary <string, object> responseDic = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; this._handleSaveResult(true, responseDic, currentOperations); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { Platform.RunOnMainThread(delegate { callback(error); }); } return; }); }).BeginInvoke((IAsyncResult r) => { }, null); }
/// <summary> /// クエリにマッチするオブジェクト数の取得を行います。<br/> /// 通信結果を受け取るために必ずコールバックの設定を行います。 /// </summary> /// <param name="callback"> コールバック</param> public void CountAsync(NCMBCountCallback callback) { if (callback == null) { throw new ArgumentException("It is necessary to always set a callback."); } new AsyncDelegate(delegate { string url = _getSearchUrl(this._className); //クラス毎のURL作成 url += WHERE_URL; //「?」をつける Dictionary <string, object> beforeJsonData = _getFindParams(); //パラメータDictionaryの作成 beforeJsonData ["count"] = 1; // カウント条件を追加する url = _makeWhereUrl(url, beforeJsonData); //urlにパラメータDictionaryを変換して結合 ConnectType type = ConnectType.GET; //メソッドタイプの設定 //通信処理 NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { Dictionary <string, object> resultObj; int count = 0; if (error == null) { try { resultObj = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; object objectCount = null; if (resultObj.TryGetValue("count", out objectCount)) { count = Convert.ToInt32(objectCount); //キーcountの値は必ず同じ型なので型チェック時の変換チェックは無し } } catch (Exception e) { error = new NCMBException(e); } } //引数は検索条件のカウント数とエラーをユーザーに返す Platform.RunOnMainThread(delegate { callback(count, error); }); return; }); }).BeginInvoke((IAsyncResult r) => { }, null); }
internal static void TrackAppOpened(string _pushId) //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics { //ネイティブから取得したpushIdからリクエストヘッダを作成 if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics) { string deviceType = ""; #if UNITY_ANDROID deviceType = "android"; #elif UNITY_IOS deviceType = "ios"; #endif //RESTリクエストデータ生成 Dictionary <string, object> requestData = new Dictionary <string, object> { { "pushId", _pushId }, { "deviceToken", NCMBManager._token }, { "deviceType", deviceType } }; var json = Json.Serialize(requestData); string url = NCMBAnalytics._getBaseUrl(_pushId); ConnectType type = ConnectType.POST; string content = json.ToString(); //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); // 通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); } catch (Exception e) { error = new NCMBException(e); } return; }); /* #if UNITY_IOS * UnityEngine.iOS.NotificationServices.ClearRemoteNotifications (); #endif */ } }
/// <summary> /// 同期用の検索メソッド。FindeAsyncで呼び出される。またNCMBObjecとのFetchAllAsyncで扱う。 /// </summary> internal void Find(NCMBQueryCallback <T> callback) { string url = _getSearchUrl(this._className); //クラス毎のURL作成 url += WHERE_URL; //「?」を末尾に追加する。 //条件データの作成 Dictionary <string, object> beforeJsonData = _getFindParams(); url = _makeWhereUrl(url, beforeJsonData); //URLの結合 ConnectType type = ConnectType.GET; //メソッドタイプの設定 NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type); //通信処理 NCMBConnection con = new NCMBConnection(url, type, null, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); Dictionary <string, object> resultObj; List <T> resultList = new List <T> (); ArrayList convertResultList = null; //中でエラー処理いるかも try { if (error == null) { resultObj = MiniJSON.Json.Deserialize(responseData) as Dictionary <string, object>; convertResultList = _convertFindResponse(resultObj); foreach (T obj in convertResultList) { resultList.Add(obj); } } } catch (Exception e) { error = new NCMBException(e); } Platform.RunOnMainThread(delegate { callback(resultList, error); }); return; }); }
internal static void _logOut(NCMBCallback callback) { string url = _getLogOutUrl(); //URL作成 ConnectType type = ConnectType.GET; string content = null; //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); //通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage); } else { _logOutEvent(); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { //If the system get ErrorCode is E401001 when LogOutAsync, We will return null. if (error != null && NCMBException.INCORRECT_HEADER.Equals(error.ErrorCode)) { callback(null); } else { callback(error); } } return; }); }
internal static void _requestPasswordReset(string email, NCMBCallback callback) { string url = _getRequestPasswordResetUrl(); //URL ConnectType type = ConnectType.POST; //set username, password NCMBUser pwresetUser = new NCMBUser(); pwresetUser.Email = email; string content = pwresetUser._toJSONObjectForSaving(pwresetUser.StartSave()); //ログを確認(通信前) NCMBDebug.Log("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content); //通信処理 NCMBConnection con = new NCMBConnection(url, type, content, NCMBUser._getCurrentSessionToken()); con.Connect(delegate(int statusCode, string responseData, NCMBException error) { try { NCMBDebug.Log("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData); if (error != null) { NCMBDebug.Log("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage); } else { NCMBDebug.Log("[DEBUG AFTER CONNECT] Successful: "); } } catch (Exception e) { error = new NCMBException(e); } if (callback != null) { Platform.RunOnMainThread(delegate { callback(error); }); } return; }); }