Example #1
0
        /// <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;
            });
        }
Example #2
0
        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;
            });
        }
Example #3
0
        /// <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);
        }
Example #4
0
        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;
            });
        }
Example #5
0
        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;
            });
        }
Example #6
0
        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
            }
        }
Example #7
0
        /// <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);
        }
Example #8
0
        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
                 */
            }
        }
Example #9
0
        /// <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;
            });
        }
Example #10
0
        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;
            });
        }
Example #11
0
        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;
            });
        }
Example #12
0
        /// <summary>
        /// _whereに検索条件($neなど)の追加。
        /// </summary>
        private void _addCondition(string key, string condition, object value)
        {
            Dictionary <string, object> whereValue = null;

            value = NCMBUtility._maybeEncodeJSONObject(value, true);
            if (_where.ContainsKey(key))
            {
                //キーの前回条件がWhereEqualToだった場合はint型 それ以外はDictionary型が入る
                object existingValue = _where [key];
                if (existingValue is IDictionary)
                {
                    whereValue = (Dictionary <string, object>)existingValue;
                }
            }
            //初回またはキーの前回条件がWhereEqualToだった場合
            if (whereValue == null)
            {
                whereValue = new Dictionary <string, object> ();
            }
            whereValue [condition] = value;
            this._where [key]      = whereValue;
            NCMBDebug.Log("【_addCondition】where : " + Json.Serialize(this._where));
        }
Example #13
0
        /// <summary>
        /// URLに結合する(where以降)データの作成。<br/>
        /// URLと結合するときにJSON化を行う。
        /// </summary>
        private Dictionary <string, object> _getFindParams()
        {
            Dictionary <string, object> beforeJsonData = new Dictionary <string, object> ();
            Dictionary <string, object> whereData      = new Dictionary <string, object> ();

            beforeJsonData ["className"] = this._className;

            //$or検索も出来るようにする
            foreach (string key in this._where.Keys)
            {
                if (key.Equals("$or"))
                {
                    List <NCMBQuery <T> > queries = (List <NCMBQuery <T> >) this._where [key];

                    List <object> array = new List <object> ();
                    foreach (NCMBQuery <T> query in queries)
                    {
                        if (query._limit >= 0)
                        {
                            throw new ArgumentException("Cannot have limits in sub queries of an 'OR' query");
                        }
                        if (query._skip > 0)
                        {
                            throw new ArgumentException("Cannot have skips in sub queries of an 'OR' query");
                        }
                        if (query._order.Count > 0)
                        {
                            throw new ArgumentException("Cannot have an order in sub queries of an 'OR' query");
                        }
                        if (query._include.Count > 0)
                        {
                            throw new ArgumentException("Cannot have an include in sub queries of an 'OR' query");
                        }
                        Dictionary <string, object> dic = query._getFindParams();
                        if (dic ["where"] != null)
                        {
                            //where=有
                            array.Add(dic ["where"]);
                        }
                        else
                        {
                            //where=無
                            array.Add(new Dictionary <string, object> ());
                        }
                    }
                    whereData [key] = array;
                }
                else
                {
                    object value = _encodeSubQueries(this._where [key]);
                    whereData [key] = NCMBUtility._maybeEncodeJSONObject(value, true);                     //※valueの値に注意
                }
            }
            beforeJsonData ["where"] = whereData;
            //各オプション毎の設定

            if (this._limit >= 0)
            {
                beforeJsonData ["limit"] = this._limit;
            }

            if (this._skip > 0)
            {
                beforeJsonData ["skip"] = this._skip;
            }

            if (this._order.Count > 0)
            {
                beforeJsonData ["order"] = _join(this._order, ",");
            }

            if (this._include.Count > 0)
            {
                beforeJsonData ["include"] = _join(this._include, ",");
            }

            NCMBDebug.Log("【_getFindParams】beforeJsonData : " + Json.Serialize(beforeJsonData));
            return(beforeJsonData);
        }