Ejemplo n.º 1
0
        internal static EnrichableField FromJSON(JToken token)
        {
            var result = new EnrichableField();

            if (token.Type == JTokenType.String)
            {
                result._data = token.Value <string>();
            }
            else if (token.Type == JTokenType.Object)
            {
                var data = new GenericData();
                var obj  = token as JObject;
                obj.Properties().ForEach(prop => data.SetData(prop.Name, prop.Value));
                result._data = data;
            }
            return(result);
        }
Ejemplo n.º 2
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)));
        }
Ejemplo n.º 3
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)));
        }
Ejemplo n.º 4
0
        public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable <string> unset = null)
        {
            if (id == null && foreignIDTime == null)
            {
                throw new ArgumentException("one the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes");
            }
            if (id != null && foreignIDTime != null)
            {
                throw new ArgumentException("at most one of the parameters ids or foreignIdTimes must be provided", "ids, foreignIDTimes");
            }

            var update = new ActivityPartialUpdateRequestObject
            {
                ID            = id,
                ForeignIDTime = foreignIDTime,
                Set           = set,
                Unset         = unset,
            };

            await this.Batch.ActivitiesPartialUpdate(new ActivityPartialUpdateRequestObject[] { update });
        }
Ejemplo n.º 5
0
        public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable <string> unset = null)
        {
            if (id == null && foreignIDTime == null)
            {
                throw new ArgumentException("one the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes");
            }
            if (id != null && foreignIDTime != null)
            {
                throw new ArgumentException("at most one of the parameters ids or foreignIdTimes must be provided", "ids, foreignIDTimes");
            }

            var request = this.BuildJWTAppRequest("activity/", HttpMethod.POST);

            var requestJSON = new JObject();

            if (id != null)
            {
                requestJSON.Add(new JProperty("id", id));
            }
            else
            {
                requestJSON.Add(new JProperty("foreign_id", foreignIDTime.ForeignID));
                requestJSON.Add(new JProperty("time", foreignIDTime.Time.ToString("s", System.Globalization.CultureInfo.InvariantCulture)));
            }

            var setObj = new JObject();

            if (set != null)
            {
                set.AddToJObject(ref setObj);
            }
            requestJSON.Add("set", setObj);

            requestJSON.Add(new JProperty("unset", unset != null ? unset : new string[] { }));

            request.SetJsonBody(requestJSON.ToString());
            var response = await this.MakeRequest(request);

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