Ejemplo n.º 1
0
        public byte[] ExecuteDownload(string resource, Guid id)
        {
            var request = new Servicem8.API.Serializers.RestRequest(resource, Method.GET);

            request.AddUrlSegment("id", id.ToString());
            request.RequestFormat = DataFormat.Json;

            return(ExecuteFileRequest(request));
        }
Ejemplo n.º 2
0
        public Task <List <T> > ExecuteList <T>(string resource, object parameters = null)
        {
            var request = new Servicem8.API.Serializers.RestRequest(resource, Method.GET);

            request.AddParameters(parameters);
            request.RequestFormat = DataFormat.Json;

            return(ExecuteRequest <List <T> >(request));
        }
Ejemplo n.º 3
0
        public Task <T> ExecuteSingle <T>(string resource, Guid id) where T : new()
        {
            var request = new Servicem8.API.Serializers.RestRequest(resource, Method.GET);

            request.AddUrlSegment("id", id.ToString());
            request.RequestFormat = DataFormat.Json;

            //Because the way ServiceM8 does it filtering, need to get the first one from the array in the response.
            return(ExecuteRequest <List <T> >(request).ContinueWith <T>(x => x.Result.FirstOrDefault()));
        }
Ejemplo n.º 4
0
        public Task ExecuteDelete(string resource, Guid id)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentNullException("model");
            }

            var request = new Servicem8.API.Serializers.RestRequest(resource, Method.DELETE);

            request.AddUrlSegment("id", id.ToString());

            return(ExecuteRequest(request));
        }
Ejemplo n.º 5
0
        public Task ExecutePayload <T>(string resource, T model, Guid?id = null) where T : class, IKey, new()
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }


            var request = new Servicem8.API.Serializers.RestRequest(resource, Method.POST);

            if (id.HasValue)
            {
                request.AddUrlSegment("id", id.ToString());
            }

            var requestBody = request.JsonSerializer.Serialize(model);

            request.AddParameter("application/json", requestBody, ParameterType.RequestBody);

            return(ExecuteRequest(request));
        }