示例#1
0
        /// <summary>
        /// Fetches the list of libraries in the database. Does nothing if there is
        /// already a request under way. Note this returns an incomplete list giving
        /// only library ids and names.
        /// </summary>
        /// <param name="callback">Callback function for data handling.</param>
        public void GetLibraryList(GetLibraryListCallback callback)
        {
            if (getLibraryListCoroutine != null)
            {
                return;
            }

            getLibraryListCoroutine = StartCoroutine(GetLibraryListLoop(callback));
        }
示例#2
0
        IEnumerator GetLibraryListLoop(GetLibraryListCallback callback)
        {
            WWWForm form = new WWWForm();

            form.AddField("request", "get_library_list");

            // Create a download object
            WWW request = new WWW(apiUrl, form);

            // Wait until the download is done
            yield return(request);

            if (!string.IsNullOrEmpty(request.error))
            {
                Debug.Log("Unable to fetch library list: " + request.error);
                callback(false, null);
            }
            else
            {
                JSONNode root = JSON.Parse(request.text);

                if (root["success"])
                {
                    // Parse the library list here.
                    List <Library> libList = new List <Library>();

                    foreach (JSONNode node in root["data"].AsArray)
                    {
                        Library lib = new Library();
                        lib.FromJSON(node);
                        libList.Add(lib);
                    }

                    callback(true, libList);
                }
                else
                {
                    callback(false, null);
                }
            }

            getLibraryListCoroutine = null;
        }