コード例 #1
0
        /// <summary>
        /// Retrieves an existing record from the Spark service by ID.
        /// </summary>
        /// <returns>The record's data.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="type">SparkType being retrieved.</param>
        /// <param name="error">Error.</param>
        /// <param name="result">Result.</param>
        public IEnumerator GetRecord(string id, SparkType type, Action <SparkMessage> error, Action <Dictionary <string, object> > result)
        {
            var url  = string.Format("{0}/{1}", type.GetEndpoint(), id);
            var send = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, result);

            yield return(StartCoroutine(send));
        }
コード例 #2
0
 /// <summary>
 /// Creates the record.
 /// </summary>
 /// <returns>The record.</returns>
 /// <param name="data">Data.</param>
 /// <param name="type">Type.</param>
 /// <param name="error">Error.</param>
 /// <param name="result">Result.</param>
 public IEnumerator CreateRecord(Dictionary<string, object> data, SparkType type, Action<SparkMessage> error, Action<Dictionary<string, object>> result)
 {
     // Create request.
     var recordDetails = System.Text.Encoding.UTF8.GetBytes(Json.Serialize(data));
     var url = type.GetEndpoint();
     var send = SendRequest(url, UnityWebRequest.kHttpVerbPOST, recordDetails, error, result);
     yield return StartCoroutine(send);
 }
コード例 #3
0
        /// <summary>
        /// Updates the record.
        /// </summary>
        /// <returns>The record.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="data">Data.</param>
        /// <param name="type">Type.</param>
        /// <param name="error">Error.</param>
        /// <param name="result">Result.</param>
        public IEnumerator UpdateRecord(string id, Dictionary <string, object> data, SparkType type, Action <SparkMessage> error, Action <Dictionary <string, object> > result)
        {
            // Update Record.
            var recordDetails = System.Text.Encoding.UTF8.GetBytes(Json.Serialize(data));
            var url           = type.GetEndpoint() + "/" + id;
            var send          = SendRequest(url, UnityWebRequest.kHttpVerbPUT, recordDetails, error, result);

            yield return(StartCoroutine(send));
        }
コード例 #4
0
 /// <summary>
 /// Deletes the record from Spark.
 /// </summary>
 /// <returns>The record.</returns>
 /// <param name="id">Identifier.</param>
 /// <param name="type">Type.</param>
 /// <param name="error">Error.</param>
 /// <param name="success">Success.</param>
 public IEnumerator DeleteRecord(string id, SparkType type, Action<SparkMessage> error, Action<bool> success)
 {
     // Create Request.
     var url = type.GetEndpoint() + "/" + id;
     var send = SendRequest(url, UnityWebRequest.kHttpVerbDELETE, null, error, result =>
     {
         success(true);
     });
     yield return StartCoroutine(send);
 }
コード例 #5
0
        /// <summary>
        /// Deletes the record from Spark.
        /// </summary>
        /// <returns>The record.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="type">Type.</param>
        /// <param name="error">Error.</param>
        /// <param name="success">Success.</param>
        public IEnumerator DeleteRecord(string id, SparkType type, Action <SparkMessage> error, Action <bool> success)
        {
            // Create Request.
            var url  = type.GetEndpoint() + "/" + id;
            var send = SendRequest(url, UnityWebRequest.kHttpVerbDELETE, null, error, result =>
            {
                success(true);
            });

            yield return(StartCoroutine(send));
        }
コード例 #6
0
        /// <summary>
        /// Retrieves multiple records from the Spark service.
        /// </summary>
        /// <param name="constraints">Any constraints on the results returned. See ApiConstrains.json for SparkType specific options.</param>
        /// <param name="type">The SparkType to retrieve.</param>
        /// <param name="error">Error from Spark, if any.</param>
        /// <param name="result">List of de-serialised results as dictionaries.</param>
        public IEnumerator ListRecords(Dictionary <string, string> constraints, SparkType type, Action <SparkMessage> error, Action <List <object> > result)
        {
            string queryString = System.Text.Encoding.UTF8.GetString(UnityWebRequest.SerializeSimpleForm(constraints));
            string url         = string.Format("{0}?{1}", type.GetEndpoint(), queryString);
            var    operation   = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, data =>
            {
                var items = data["items"] as List <object>;
                result(items);
            });

            yield return(StartCoroutine(operation));
        }
コード例 #7
0
 /// <summary>
 /// Retrieves multiple records from the Spark service.
 /// </summary>
 /// <param name="constraints">Any constraints on the results returned. See ApiConstrains.json for SparkType specific options.</param>
 /// <param name="type">The SparkType to retrieve.</param>
 /// <param name="error">Error from Spark, if any.</param>
 /// <param name="result">List of de-serialised results as dictionaries.</param>
 public IEnumerator ListRecords(Dictionary<string, string> constraints, SparkType type, Action<SparkMessage> error, Action<List<object>> result)
 {
     string queryString = System.Text.Encoding.UTF8.GetString(UnityWebRequest.SerializeSimpleForm(constraints));
     string url = string.Format("{0}?{1}", type.GetEndpoint(), queryString);
     var operation = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, data =>
     {
         var items = data["items"] as List<object>;
         result(items);
     });
     yield return StartCoroutine(operation);
 }
コード例 #8
0
 /// <summary>
 /// Retrieves an existing record from the Spark service by ID.
 /// </summary>
 /// <returns>The record's data.</returns>
 /// <param name="id">Identifier.</param>
 /// <param name="type">SparkType being retrieved.</param>
 /// <param name="error">Error.</param>
 /// <param name="result">Result.</param>
 public IEnumerator GetRecord(string id, SparkType type, Action<SparkMessage> error, Action<Dictionary<string, object>> result)
 {
     var url = string.Format("{0}/{1}", type.GetEndpoint(), id);
     var send = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, result);
     yield return StartCoroutine(send);
 }