Ejemplo n.º 1
0
        /// <summary>
        /// Creates a resource
        /// </summary>
        /// <param name="resourceDescriptor"></param>
        /// <param name="resource"></param>
        /// <returns></returns>
        public async Task <Resource> Create(ResourceDescriptor resourceDescriptor, Resource resource)
        {
            var resp = await HttpClient.PostAsync(resourceDescriptor.Url, new JsonContent(ResourceSerializer.Serialize(resource)));

            resp.EnsureSuccessStatusCode();

            return(await ResourceSerializer.DeserializeResponseBodyToResource(resource.GetType(), resp));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a resource by its ID
        /// </summary>
        /// <param name="resourceDescriptor"></param>
        /// <returns></returns>
        public async Task <Resource> Get(ResourceDescriptor resourceDescriptor)
        {
            var resp = await HttpClient.GetAsync(resourceDescriptor.Url);

            resp.EnsureSuccessStatusCode();

            return(await ResourceSerializer.DeserializeResponseBodyToResource(resourceDescriptor.Type, resp));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a resource of type <see cref="T"/> by its ID
        /// </summary>
        /// <param name="resourceDescriptor"></param>
        /// <returns></returns>
        public async Task <T> Get <T>(ResourceDescriptor resourceDescriptor) where T : Resource, new()
        {
            var resp = await HttpClient.GetAsync(resourceDescriptor.Url);

            resp.EnsureSuccessStatusCode();

            return(await ResourceSerializer.DeserializeResponseBodyToResource <T>(resp));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a resource of type <see cref="T"/> by its ID
        /// </summary>
        /// <param name="resourceDescriptor"></param>
        /// <param name="resource"></param>
        /// <returns></returns>
        public virtual async Task <T> Update <T>(ResourceDescriptor resourceDescriptor, T resource) where T : Resource, new()
        {
            var resp = await HttpClient.PutAsync(resourceDescriptor.Url, new JsonContent(ResourceSerializer.Serialize(resource)));

            resp.EnsureSuccessStatusCode();

            return(await ResourceSerializer.DeserializeResponseBodyToResource <T>(resp));
        }