예제 #1
0
        /// <summary>
        /// Set value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
        /// OnSetSuccess action contains the corresponding Firebase and the response Snapshot
        /// OnSetFailed action contains the error exception
        /// </summary>
        /// <param name="val">Set value</param>
        /// <param name="priority">Priority.</param>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        public void SetValue(object val, float priority, FirebaseParam query)
        {
            Dictionary <string, object> tempDict = new Dictionary <string, object>();

            tempDict.Add(".value", val);
            tempDict.Add(".priority", priority);
            root.StartCoroutine(JsonSerializeRoutine(tempDict, query, SetValueJson));
        }
 public CommandLinkedList(Firebase _firebase, FirebaseCommand _command, FirebaseParam firebaseParam, object _obj = null)
 {
     firebase = _firebase;
     command  = _command;
     param    = firebaseParam.Parameter;
     obj      = _obj;
     next     = null;
 }
        /// <summary>
        /// Adds Firebase Delete request to queue.
        /// </summary>
        /// <param name="firebase">Firebase.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueueDelete(Firebase firebase, FirebaseParam param)
        {
            Firebase temp = firebase.Copy(true);

            temp.OnDeleteSuccess += OnSuccess;
            temp.OnDeleteFailed  += OnFailed;
            AddQueue(temp, FirebaseCommand.Delete, param.Parameter);
        }
        /// <summary>
        /// Adds Firebase Push request to queue.
        /// </summary>
        /// <param name="firebase">Firebase.</param>
        /// <param name="val">Value.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueuePush(Firebase firebase, object val, FirebaseParam param)
        {
            Firebase temp = firebase.Copy(true);

            temp.OnPushSuccess += OnSuccess;
            temp.OnPushFailed  += OnFailed;
            AddQueue(temp, FirebaseCommand.Push, param.Parameter, val);
        }
        /// <summary>
        /// Adds Firebase Update request to queue.
        /// </summary>
        /// <param name="firebase">Firebase.</param>
        /// <param name="val">Value.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueueUpdate(Firebase firebase, object val, FirebaseParam param)
        {
            Firebase temp = firebase.Copy(true);

            temp.OnUpdateSuccess += OnSuccess;
            temp.OnUpdateFailed  += OnFailed;
            AddQueue(temp, FirebaseCommand.Update, param.Parameter, val);
        }
        /// <summary>
        /// Adds Firebase Get request to queue.
        /// </summary>
        /// <param name="firebase">Firebase.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueueGet(Firebase firebase, FirebaseParam param)
        {
            Firebase temp = firebase.Copy(true);

            temp.OnGetSuccess += OnSuccess;
            temp.OnGetFailed  += OnFailed;
            AddQueue(temp, FirebaseCommand.Get, param.Parameter);
        }
예제 #7
0
 /// <summary>
 /// Creates an Observer that calls GetValue request at the given refresh rate (in seconds) and checks whether the value has changed.
 /// </summary>
 /// <param name="firebase">Firebase.</param>
 /// <param name="refreshRate">Refresh rate (in seconds).</param>
 /// <param name="getParam">Parameter value for the Get request that will be called periodically.</param>
 public FirebaseObserver(Firebase _firebase, float _refreshRate, FirebaseParam _getParam)
 {
     active       = false;
     lastSnapshot = null;
     firebase     = _firebase;
     refreshRate  = _refreshRate;
     getParam     = _getParam.Parameter;
     target       = _firebase.Copy();
 }
예제 #8
0
        /// <summary>
        /// Adds Firebase Set request to queue.
        /// </summary>
        /// <param name="firebase">Firebase node.</param>
        /// <param name="val">Value.</param>
        /// <param name="priority">Priority.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueueSet(Firebase firebase, object val, float priority, FirebaseParam param)
        {
            Dictionary <string, object> tempDict = new Dictionary <string, object>();

            tempDict.Add(".value", val);
            tempDict.Add(".priority", priority);

            AddQueueSet(firebase, tempDict, param.Parameter);
        }
        /// <summary>
        /// Create new FirebaseQuery
        /// </summary>
        /// <param name="copy">Firebase parameter to copy.</param>
        public FirebaseParam(FirebaseParam copy)
        {
            param  = copy.Parameter;
            header = new Dictionary <string, string>();

            foreach (var kv in header)
            {
                header.Add(kv.Key, kv.Value);
            }
        }
예제 #10
0
        /*** SET ***/

        /// <summary>
        /// Set value of a key on Firebase. Calls OnSetSuccess on success, OnSetFailed on failed.
        /// OnSetSuccess action contains the corresponding Firebase and the response Snapshot
        /// OnSetFailed action contains the error exception
        /// </summary>
        /// <param name="valJson">Set value in json format</param>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        void SetValueJson(string valJson, FirebaseParam query)
        {
            try
            {
                if (Credential != "")
                {
                    query = new FirebaseParam(query).Auth(Credential);
                }

                string url = Endpoint;

#pragma warning disable CS0618 // Type or member is obsolete
                string param = WWW.EscapeURL(query.Parameter);
#pragma warning restore CS0618 // Type or member is obsolete

                if (param != "")
                {
                    url += "?" + param;
                }


                Dictionary <string, string> headers = new Dictionary <string, string>();

                foreach (var kv in query.HttpHeader)
                {
                    headers.Add(kv.Key, kv.Value);
                }

                headers.Add("Content-Type", "application/json");

                if (!headers.ContainsKey("X-HTTP-Method-Override"))
                {
                    headers.Add("X-HTTP-Method-Override", "PUT");
                }

                //UTF8Encoding encoding = new UTF8Encoding();
                byte[] bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(valJson);

                root.StartCoroutine(RequestCoroutine(url, bytes, headers, OnSetSuccess, OnSetFailed));
            }
            catch (WebException webEx)
            {
                if (OnSetFailed != null)
                {
                    OnSetFailed(this, FirebaseError.Create(webEx));
                }
            }
            catch (Exception ex)
            {
                if (OnSetFailed != null)
                {
                    OnSetFailed(this, new FirebaseError(ex.Message));
                }
            }
        }
예제 #11
0
 /// <summary>
 /// Push a value (with random new key) on a key in Firebase. Calls OnPushSuccess on success, OnPushFailed on failed.
 /// OnPushSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnPushFailed action contains the error exception
 /// </summary>
 /// <param name="json">String</param>
 /// <param name="isJson">True if string is json (necessary to differentiate with the other overloading)</param>
 /// <param name="param">REST call parameters on a string. Example: "auth=ASDF123"</param>
 /// <returns></returns>
 public void Push(string json, bool isJson, FirebaseParam query)
 {
     if (!isJson)
     {
         Push(json, query.Parameter);
     }
     else
     {
         Push(Json.Deserialize(json), query.Parameter);
     }
 }
예제 #12
0
 /// <summary>
 /// Update value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
 /// OnUpdateSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnUpdateFailed action contains the error exception
 /// </summary>
 /// <param name="json">String</param>
 /// <param name="isJson">True if string is json (necessary to differentiate the other overloading)</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void UpdateValue(string json, bool isJson, FirebaseParam query)
 {
     if (!isJson)
     {
         UpdateValue(json, query.Parameter);
     }
     else
     {
         UpdateValue(Json.Deserialize(json), query.Parameter);
     }
 }
예제 #13
0
 /// <summary>
 /// Set value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
 /// OnSetSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnSetFailed action contains the error exception
 /// </summary>
 /// <param name="val">Set value</param>
 /// <param name="isJson">True if string is an object parsed in a json string.</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void SetValue(string val, bool isJson, FirebaseParam query)
 {
     if (isJson)
     {
         SetValueJson(val, query);
     }
     else
     {
         root.StartCoroutine(JsonSerializeRoutine(val, query, SetValueJson));
     }
 }
예제 #14
0
 /// <summary>
 /// Push a value (with random new key) on a key in Firebase. Calls OnPushSuccess on success, OnPushFailed on failed.
 /// OnPushSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnPushFailed action contains the error exception
 /// </summary>
 /// <param name="val">Push value</param>
 /// <param name="isJson">True if string is an object parsed in a json string.</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void Push(string val, bool isJson, FirebaseParam query)
 {
     if (isJson)
     {
         PushJson(val, query);
     }
     else
     {
         root.StartCoroutine(JsonSerializeRoutine(val, query, PushJson));
     }
 }
예제 #15
0
        /*** DELETE ***/

        /// <summary>
        /// Delete a key in Firebase. Calls OnDeleteSuccess on success, OnDeleteFailed on failed.
        /// OnDeleteSuccess action contains the corresponding Firebase and the response Snapshot
        /// OnDeleteFailed action contains the error exception
        /// </summary>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        public void Delete(FirebaseParam query)
        {
            try
            {
                if (Credential != "")
                {
                    query = new FirebaseParam(query).Auth(Credential);
                }

                string url = Endpoint;

                string param = WWW.EscapeURL(query.Parameter);

                if (param != string.Empty)
                {
                    url += "?" + param;
                }

                Dictionary <string, string> headers = new Dictionary <string, string>();

                foreach (var kv in query.HttpHeader)
                {
                    headers.Add(kv.Key, kv.Value);
                }

                headers.Add("Content-Type", "application/json");

                if (!headers.ContainsKey("X-HTTP-Method-Override"))
                {
                    headers.Add("X-HTTP-Method-Override", "DELETE");
                }

                //UTF8Encoding encoding = new UTF8Encoding();
                byte[] bytes = Encoding.GetEncoding("iso-8859-1").GetBytes("{ \"dummy\" : \"dummies\"}");

                root.StartCoroutine(RequestCoroutine(url, bytes, headers, OnDeleteSuccess, OnDeleteFailed));
            }
            catch (WebException webEx)
            {
                if (OnDeleteFailed != null)
                {
                    OnDeleteFailed(this, FirebaseError.Create(webEx));
                }
            }
            catch (Exception ex)
            {
                if (OnDeleteFailed != null)
                {
                    OnDeleteFailed(this, new FirebaseError(ex.Message));
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Update value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
        /// OnUpdateSuccess action contains the corresponding Firebase and the response Snapshot
        /// OnUpdateFailed action contains the error exception
        /// </summary>
        /// <param name="val">Update value</param>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        internal void UpdateValueObject(object val, FirebaseParam query)
        {
            if (!(val is Dictionary <string, object>))
            {
                if (OnUpdateFailed != null)
                {
                    OnUpdateFailed(this, new FirebaseError((HttpStatusCode)400, "Invalid data; couldn't parse JSON object. Are you sending a JSON object with valid key names?"));
                }

                return;
            }

            root.StartCoroutine(JsonSerializeRoutine(val, query, UpdateValue));
        }
예제 #17
0
        IEnumerator JsonSerializeRoutine(object sourceObj, FirebaseParam query, Action <string, FirebaseParam> onCompleted)
        {
            ParserObjToJson parser = new ParserObjToJson(sourceObj);

            while (!parser.isDone)
            {
                yield return(null);
            }

            if (onCompleted != null)
            {
                onCompleted(parser.json, query);
            }
        }
        /// <summary>
        /// Adds Firebase Push request to queue.
        /// </summary>
        /// <param name="firebase">Firebase.</param>
        /// <param name="json">Json.</param>
        /// <param name="isJson">If set to <c>true</c> is json.</param>
        /// <param name="param">Parameter.</param>
        public void AddQueuePush(Firebase firebase, string json, bool isJson, FirebaseParam param)
        {
            Firebase temp = firebase.Copy(true);

            temp.OnPushSuccess += OnSuccess;
            temp.OnPushFailed  += OnFailed;
            if (!isJson)
            {
                AddQueue(temp, FirebaseCommand.Push, param.Parameter, json);
            }
            else
            {
                AddQueue(temp, FirebaseCommand.Push, param.Parameter, Json.Deserialize(json));
            }
        }
예제 #19
0
        /*** PUSH ***/

        /// <summary>
        /// Push a value (with random new key) on a key in Firebase. Calls OnPushSuccess on success, OnPushFailed on failed.
        /// OnPushSuccess action contains the corresponding Firebase and the response Snapshot
        /// OnPushFailed action contains the error exception
        /// </summary>
        /// <param name="valJson">Push value in json format</param>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        void PushJson(string valJson, FirebaseParam query)
        {
            try
            {
                if (Credential != "")
                {
                    query = new FirebaseParam(query).Auth(Credential);
                }

                string url = Endpoint;

#pragma warning disable CS0618 // Type or member is obsolete
                string param = WWW.EscapeURL(query.Parameter);
#pragma warning restore CS0618 // Type or member is obsolete

                if (param != string.Empty)
                {
                    url += "?" + param;
                }

                //UTF8Encoding encoding = new UTF8Encoding();
                byte[] bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(valJson);

                root.StartCoroutine(RequestCoroutine(url, bytes, query.HttpHeader, OnPushSuccess, OnPushFailed));
            }
            catch (WebException webEx)
            {
                if (OnPushFailed != null)
                {
                    OnPushFailed(this, FirebaseError.Create(webEx));
                }
            }
            catch (Exception ex)
            {
                if (OnPushFailed != null)
                {
                    OnPushFailed(this, new FirebaseError(ex.Message));
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Fetch data from Firebase. Calls OnGetSuccess on success, OnGetFailed on failed.
        /// OnGetSuccess action contains the corresponding Firebase and the fetched Snapshot
        /// OnGetFailed action contains the error exception
        /// </summary>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        /// <returns></returns>
        public void GetValue(FirebaseParam query)
        {
            try
            {
                if (Credential != "")
                {
                    query = new FirebaseParam(query).Auth(Credential);
                }

                string url = Endpoint;

#pragma warning disable CS0618 // Type or member is obsolete
                string param = WWW.EscapeURL(query.Parameter);
#pragma warning restore CS0618 // Type or member is obsolete

                if (param != "")
                {
                    url += "?" + param;
                }

                root.StartCoroutine(RequestCoroutine(url, null, query.HttpHeader, OnGetSuccess, OnGetFailed));
            }
            catch (WebException webEx)
            {
                if (OnGetFailed != null)
                {
                    OnGetFailed(this, FirebaseError.Create(webEx));
                }
            }
            catch (Exception ex)
            {
                if (OnGetFailed != null)
                {
                    OnGetFailed(this, new FirebaseError(ex.Message));
                }
            }
        }
예제 #21
0
 /// <summary>
 /// Adds Firebase Push request to queue.
 /// </summary>
 /// <param name="firebase">Firebase node.</param>
 /// <param name="val">Value.</param>
 /// <param name="param">Parameter.</param>
 public void AddQueuePush(Firebase firebase, object val, FirebaseParam param)
 {
     AddQueuePush(firebase, val, param.Parameter);
 }
예제 #22
0
 /// <summary>
 /// Adds Firebase Update request to queue.
 /// </summary>
 /// <param name="firebase">Firebase node.</param>
 /// <param name="valJson">Value in json format.</param>
 /// <param name="param">Parameter.</param>
 public void AddQueueUpdate(Firebase firebase, string valJson, FirebaseParam param)
 {
     AddQueueUpdate(firebase, valJson, param.Parameter);
 }
예제 #23
0
 /// <summary>
 /// Adds Firebase Update request to queue.
 /// </summary>
 /// <param name="firebase">Firebase node.</param>
 /// <param name="val">Value.</param>
 /// <param name="param">Parameter.</param>
 public void AddQueueUpdate(Firebase firebase, Dictionary <string, object> val, FirebaseParam param)
 {
     AddQueueUpdate(firebase, val, param.Parameter);
 }
예제 #24
0
        /// <summary>
        /// Sets the priority of the node.
        /// </summary>
        /// <param name="OnSuccess">On success callback.</param>
        /// <param name="OnFailed">On failed callback.</param>
        /// <param name="priority">Priority.</param>
        /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
        public void SetPriority(Action <Firebase, DataSnapshot> OnSuccess, Action <Firebase, FirebaseError> OnFailed, float priority, FirebaseParam query)
        {
            Firebase temp = Copy(false);

            temp.OnSetSuccess += OnSuccess;
            temp.OnSetFailed  += OnFailed;
            temp.Child(".priority").SetValue(priority, query);
        }
예제 #25
0
 /// <summary>
 /// Sets the priority of the node.
 /// </summary>
 /// <param name="priority">Priority.</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 public void SetPriority(float priority, FirebaseParam query)
 {
     Copy(false).Child(".priority").SetValue(priority, query);
 }
예제 #26
0
 /// <summary>
 /// Push a value (with random new key) on a key in Firebase. Calls OnPushSuccess on success, OnPushFailed on failed.
 /// OnPushSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnPushFailed action contains the error exception
 /// </summary>
 /// <param name="val">Push value</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void Push(object val, FirebaseParam query)
 {
     root.StartCoroutine(JsonSerializeRoutine(val, query, PushJson));
 }
예제 #27
0
 /// <summary>
 /// Update value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
 /// OnUpdateSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnUpdateFailed action contains the error exception
 /// </summary>
 /// <param name="val">Update value</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void UpdateValue(Dictionary <string, object> val, FirebaseParam query)
 {
     root.StartCoroutine(JsonSerializeRoutine(val, query, UpdateValue));
 }
예제 #28
0
 /// <summary>
 /// Adds Firebase Push request to queue.
 /// </summary>
 /// <param name="firebase">Firebase node.</param>
 /// <param name="val">Value.</param>
 /// <param name="isJson">True if string is an object parsed in a json string.</param>
 /// <param name="param">Parameter.</param>
 public void AddQueuePush(Firebase firebase, string val, bool isJson, FirebaseParam param)
 {
     AddQueuePush(firebase, val, isJson, param.Parameter);
 }
예제 #29
0
 /// <summary>
 /// Adds Firebase Delete request to queue.
 /// </summary>
 /// <param name="firebase">Firebase node.</param>
 /// <param name="param">Parameter.</param>
 public void AddQueueDelete(Firebase firebase, FirebaseParam param)
 {
     AddQueueDelete(firebase, param.Parameter);
 }
예제 #30
0
 /// <summary>
 /// Set value of a key on Firebase. Calls OnUpdateSuccess on success, OnUpdateFailed on failed.
 /// OnSetSuccess action contains the corresponding Firebase and the response Snapshot
 /// OnSetFailed action contains the error exception
 /// </summary>
 /// <param name="val">Set value</param>
 /// <param name="query">REST call parameters wrapped in FirebaseQuery class</param>
 /// <returns></returns>
 public void SetValue(object val, FirebaseParam query)
 {
     root.StartCoroutine(JsonSerializeRoutine(val, query, SetValueJson));
 }