Ejemplo n.º 1
0
        /* Helpers */

        private async Task <dynamic> _emit(string resource, string action, CumulioQuery query)
        {
            query.key     = apiKey;
            query.token   = apiToken;
            query.version = apiVersion;

            string payload = JsonConvert.SerializeObject(query);
            string url     = this.host + ':' + this.port + '/' + query.version + '/' + resource;
            string result  = null;

            try {
                WebClient request = new WebClient();
                request.Headers.Add("Content-Type", "application/json");
                result = await request.UploadStringTaskAsync(url, action, payload).ConfigureAwait(false);

                return(JsonConvert.DeserializeObject(result));
            }
            catch (WebException e) {
                if (e.Response == null)
                {
                    result = "{error: 'An unexpected error occurred. Please try again later!'}";
                }
                else
                {
                    result = await(new StreamReader(e.Response.GetResponseStream()).ReadToEndAsync());
                }
                throw new CumulioException(JsonConvert.DeserializeObject(result));
            }
        }
Ejemplo n.º 2
0
        public async Task <dynamic> getAsync(string resource, ExpandoObject filter)
        {
            CumulioQuery query = new CumulioQuery();

            query.action = "get";
            query.find   = filter;

            return(await _emit(resource, "SEARCH", query));
        }
Ejemplo n.º 3
0
        public async Task <dynamic> createAsync(string resource, ExpandoObject properties, List <ExpandoObject> associations)
        {
            CumulioQuery query = new CumulioQuery();

            query.action       = "create";
            query.properties   = properties;
            query.associations = associations;
            return(await _emit(resource, "POST", query));
        }
Ejemplo n.º 4
0
        public async Task <dynamic> queryAsync(ExpandoObject filter)
        {
            CumulioQuery query = new CumulioQuery();

            query.action = "get";
            query.find   = filter;

            return(await _emit("data", "SEARCH", query));
        }
Ejemplo n.º 5
0
        public async Task <dynamic> updateAsync(string resource, string id, ExpandoObject properties)
        {
            CumulioQuery query = new CumulioQuery();

            query.action     = "update";
            query.id         = id;
            query.properties = properties;

            return(await _emit(resource, "PATCH", query));
        }
Ejemplo n.º 6
0
        public async Task <dynamic> dissociateAsync(string resource, string id, string associationRole, string associationId)
        {
            dynamic association = new ExpandoObject();

            association.role = associationRole;
            association.id   = associationId;

            CumulioQuery query = new CumulioQuery();

            query.action   = "dissociate";
            query.id       = id;
            query.resource = association;

            return(await _emit(resource, "UNLINK", query));
        }