/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }