Beispiel #1
0
        /// <summary>
        /// 指定されたSNSのauthDataを取得します。
        /// </summary>
        /// <param name="provider">SNS名</param>
        /// <returns>指定されたSNSのauthData</returns>
        public Dictionary <string, object> GetAuthDataForProvider(string provider)
        {
            List <string> providerList = new List <string> ()
            {
                "facebook", "twitter", "apple", "anonymous"
            };

            if (string.IsNullOrEmpty(provider) || !providerList.Contains(provider))
            {
                throw new NCMBException(new ArgumentException("Provider must be facebook or twitter or apple or anonymous"));
            }

            Dictionary <string, object> authData = new Dictionary <string, object> ();

            switch (provider)
            {
            case "facebook":
                var facebookAuthData = (Dictionary <string, object>) this ["authData"];
                var facebookParam    = (Dictionary <string, object>)facebookAuthData ["facebook"];
                authData.Add("id", facebookParam ["id"]);
                authData.Add("access_token", facebookParam ["access_token"]);
                authData.Add("expiration_date", NCMBUtility.encodeDate((DateTime)facebookParam ["expiration_date"]));
                break;

            case "twitter":
                var twitterAuthData = (Dictionary <string, object>) this ["authData"];
                var twitterParam    = (Dictionary <string, object>)twitterAuthData ["twitter"];
                authData.Add("id", twitterParam ["id"]);
                authData.Add("screen_name", twitterParam ["screen_name"]);
                authData.Add("oauth_consumer_key", twitterParam ["oauth_consumer_key"]);
                authData.Add("consumer_secret", twitterParam ["consumer_secret"]);
                authData.Add("oauth_token", twitterParam ["oauth_token"]);
                authData.Add("oauth_token_secret", twitterParam ["oauth_token_secret"]);
                break;

            case "apple":
                var appleAuthData = (Dictionary <string, object>) this["authData"];
                var appleParam    = (Dictionary <string, object>)appleAuthData["apple"];
                authData.Add("id", appleParam["id"]);
                authData.Add("access_token", appleParam["access_token"]);
                authData.Add("client_id", appleParam["client_id"]);
                break;

            case "anonymous":
                var anonymousAuthData = (Dictionary <string, object>) this ["authData"];
                var anonymousParam    = (Dictionary <string, object>)anonymousAuthData ["anonymous"];
                authData.Add("id", anonymousParam ["id"]);
                break;
            }

            return(authData);
        }
Beispiel #2
0
		/// <summary>
		/// コンストラクター。
		/// </summary>	
		public NCMBFacebookParameters(string userId, string accessToken, DateTime expirationDate)
		{
			if (string.IsNullOrEmpty (userId) ||
				string.IsNullOrEmpty (accessToken) ||
				string.IsNullOrEmpty (NCMBUtility.encodeDate (expirationDate))
			) 
			{
				throw new NCMBException (new ArgumentException ("userId or accessToken or expirationDate must not be null."));
			}

			Dictionary<string, object> objDate = new Dictionary<string, object> () {
				{"__type", "Date"},
				{"iso", NCMBUtility.encodeDate (expirationDate)}
			};
			Dictionary<string, object> facebookParam = new Dictionary<string, object> () {
				{"id", userId},
				{"access_token", accessToken},
				{"expiration_date", objDate}
			};

			param.Add ("facebook", facebookParam);
		}
Beispiel #3
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));
        }
Beispiel #4
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);
        }
Beispiel #5
0
 /// <summary>
 /// 一致する。
 /// </summary>
 /// <param name="key"> 条件指定するフィールド名</param>
 /// <param name="value">  値</param>
 /// <returns> クエリ</returns>
 public NCMBQuery <T> WhereEqualTo(string key, object value)
 {
     value        = NCMBUtility._maybeEncodeJSONObject(value, true);
     _where [key] = value;
     return(this);
 }
Beispiel #6
0
 internal NCMBQuery <T> _whereRelatedTo(NCMBObject parent, String key)
 {
     this._addCondition("$relatedTo", "object", NCMBUtility._maybeEncodeJSONObject(parent, true));
     this._addCondition("$relatedTo", "key", key);
     return(this);
 }
Beispiel #7
0
 public object Encode()
 {
     //エンコードを行う
     return(NCMBUtility._maybeEncodeJSONObject(this.Value, true));
 }
Beispiel #8
0
        /// <summary>
        /// 非同期処理でスクリプトの実行を行います。
        /// </summary>
        /// <param name="header">リクエストヘッダー.</param>
        /// <param name="body">リクエストボディ</param>
        /// <param name="query">クエリパラメーター</param>
        /// <param name="callback">コールバック</param>
        public void ExecuteAsync(IDictionary <string, object> header, IDictionary <string, object> body, IDictionary <string, object> query, NCMBExecuteScriptCallback callback)
        {
            //URL作成
            String endpoint  = DEFAULT_SCRIPT_ENDPOINT;
            String scriptUrl = DEFAULT_SCRIPT_ENDPOINT + "/" + DEFAULT_SCRIPT_API_VERSION + "/" + SERVICE_PATH + "/" + this._scriptName;

            if (this._baseUrl == null || this._baseUrl.Length == 0)
            {
                throw new ArgumentException("Invalid baseUrl.");
            }
            else if (!this._baseUrl.Equals(DEFAULT_SCRIPT_ENDPOINT))
            {
                //ユーザー設定時
                endpoint  = _baseUrl;
                scriptUrl = this._baseUrl + "/" + this._scriptName;
            }

            //メソッド作成
            ConnectType type;

            switch (_method)
            {
            case MethodType.POST:
                type = ConnectType.POST;
                break;

            case MethodType.PUT:
                type = ConnectType.PUT;
                break;

            case MethodType.GET:
                type = ConnectType.GET;
                break;

            case MethodType.DELETE:
                type = ConnectType.DELETE;
                break;

            default:
                throw new ArgumentException("Invalid methodType.");
            }

            //コンテント作成
            String content = null;

            if (body != null)
            {
                content = Json.Serialize(body);
            }

            //クエリ文字列作成
            String queryVal    = "";
            String queryString = "?";

            if (query != null && query.Count > 0)
            {
                int count = query.Count;
                foreach (KeyValuePair <string, object> pair in query)
                {
                    if (pair.Value is IList || pair.Value is IDictionary)
                    {
                        //value形式:array,ILis,IDictionaryの場合
                        queryVal = SimpleJSON.Json.Serialize(pair.Value);
                    }
                    else if (pair.Value is DateTime)
                    {
                        //value形式:DateTimeの場合
                        queryVal = NCMBUtility.encodeDate((DateTime)pair.Value);
                    }
                    else
                    {
                        //value形式:上の以外場合
                        queryVal = pair.Value.ToString();
                    }

                    queryString += pair.Key + "=" + Uri.EscapeDataString(queryVal);

                    if (count > 1)
                    {
                        queryString += "&";
                        --count;
                    }
                }

                scriptUrl += queryString;
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate {
                return(true);
            };

            //コネクション作成
            NCMBConnection connection = new NCMBConnection(scriptUrl, type, content, NCMBUser._getCurrentSessionToken(), null, endpoint);

            //オリジナルヘッダー設定
            if (header != null && header.Count > 0)
            {
                foreach (KeyValuePair <string, object> pair in header)
                {
                    connection._request.SetRequestHeader(pair.Key, pair.Value.ToString());
                }
            }

            //通信
            Connect(connection, callback);
        }