Esempio n. 1
0
        public async Task <CollectionObject> Get(string collectionName, string ID)
        {
            var request = this._client.BuildAppRequest($"collections/{collectionName}/{ID}/", HttpMethod.GET);

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw StreamException.FromResponse(response);
            }

            return(CollectionObject.FromJSON(JObject.Parse(response.Content)));
        }
Esempio n. 2
0
        public async Task <CollectionObject> Update(string collectionName, string ID, GenericData data)
        {
            var dataJson = new JObject(new JProperty("data", data.ToJObject()));
            var request  = this._client.BuildAppRequest($"collections/{collectionName}/{ID}/", HttpMethod.PUT);

            request.SetJsonBody(dataJson.ToString());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamException.FromResponse(response);
            }

            return(CollectionObject.FromJSON(JObject.Parse(response.Content)));
        }
Esempio n. 3
0
        private static IEnumerable <CollectionObject> GetResults(string json)
        {
            var obj      = JObject.Parse(json);
            var response = obj.Property("response").Value as JObject;
            var data     = response.Property("data").Value as JArray;

            foreach (var result in data)
            {
                var resultObj = result as JObject;

                var foreignID = resultObj.Property("foreign_id").Value.Value <string>();
                var objectID  = foreignID.Split(':')[1];

                var objectData = resultObj.Property("data").Value as JObject;

                var collectionObject = CollectionObject.FromJSON(objectData);
                collectionObject.ID = objectID;

                yield return(collectionObject);
            }
        }
Esempio n. 4
0
        public async Task <CollectionObject> Add(string collectionName, GenericData data, string ID = null, string userID = null)
        {
            var collectionObject = new CollectionObject()
            {
                ID     = ID,
                UserID = userID,
                _data  = data,
            };

            var request = this._client.BuildAppRequest($"collections/{collectionName}/", HttpMethod.POST);

            request.SetJsonBody(collectionObject.ToJson());

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw StreamException.FromResponse(response);
            }

            return(CollectionObject.FromJSON(JObject.Parse(response.Content)));
        }