/// <summary> /// DELETE /bundles/{bundleId} /// </summary> /// <param name="bundleId"></param> /// <returns></returns> public async Task DeleteBundleAsync(Guid bundleId) { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); await http.DeleteAsync(ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N"))); }
/// <summary> /// GET /bundles/{bundleId} /// </summary> /// <param name="bundleId"></param> /// <returns></returns> public async Task <Bundle> GetBundleAsync(Guid bundleId) { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); return(await GetHalObjectAsync <Bundle>(HttpMethod.Get, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")))); }
/// <summary> /// POST /bundles /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <BundleRef> PostBundleAsync(BundlePostRequest request) { Contract.Requires <ArgumentNullException>(request != null); using (var message = new HttpRequestMessage(HttpMethod.Post, ApiUriV1 .Combine("bundles"))) { message.Content = new FormUrlEncodedContent(ToKeyValuePairs(JObject.FromObject(request))); return(await GetHalObjectAsync <BundleRef>(message)); } }
/// <summary> /// GET /bundles/{bundleId}/insights/{insightId} /// </summary> /// <typeparam name="TInsight"></typeparam> /// <param name="bundleId"></param> /// <param name="insightId"></param> /// <returns></returns> public async Task <TInsight> GetBundleInsightAsync <TInsight>(Guid bundleId, Guid insightId) where TInsight : Insight { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); Contract.Requires <ArgumentOutOfRangeException>(insightId != Guid.Empty); return(await GetHalObjectAsync <TInsight>(HttpMethod.Get, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")) .Combine("insights") .Combine(insightId.ToString("N")))); }
/// <summary> /// PUT /bundles/{bundleId} /// </summary> /// <param name="bundleId"></param> /// <param name="request"></param> /// <returns></returns> public async Task <BundleRef> PutBundleAsync(Guid bundleId, BundlePutRequest request) { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); Contract.Requires <ArgumentNullException>(request != null); using (var req = new HttpRequestMessage(HttpMethod.Put, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")))) { req.Content = new FormUrlEncodedContent(ToKeyValuePairs(JObject.FromObject(request))); return(await GetHalObjectAsync <BundleRef>(req)); } }
/// <summary> /// PUT /bundles/{bundleId}/metadata /// </summary> /// <param name="bundleId"></param> /// <param name="insight"></param> /// <returns></returns> public async Task <MetadataRef> PutBundleMetadataAsync(Guid bundleId, Dictionary <string, object> data, int?version = null) { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); Contract.Requires <ArgumentNullException>(data != null); using (var req = new HttpRequestMessage(HttpMethod.Put, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")) .Combine("metadata"))) { var map = new Dictionary <string, object>(); map["data"] = data; map["version"] = version; req.Content = new FormUrlEncodedContent(ToKeyValuePairs(JObject.FromObject(map))); return(await GetHalObjectAsync <MetadataRef>(req)); } }
/// <summary> /// POST /bundles/{bundleId}/insights /// </summary> /// <param name="bundleId"></param> /// <param name="insight"></param> /// <returns></returns> public async Task <TInsight> PostBundleInsightAsync <TInsight>(Guid bundleId, string insight) where TInsight : Insight { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); Contract.Requires <ArgumentNullException>(insight != null); using (var request = new HttpRequestMessage(HttpMethod.Post, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")) .Combine("insights"))) { request.Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "insight", insight } }); return(await GetHalObjectAsync <TInsight>(request)); } }
/// <summary> /// GET /bundles/{bundleId}/tracks/{trackId} /// </summary> /// <param name="bundleId"></param> /// <param name="trackId"></param> /// <returns></returns> public async Task <Track> GetBundleTrackAsync(Guid bundleId, Guid trackId) { Contract.Requires <ArgumentOutOfRangeException>(bundleId != Guid.Empty); Contract.Requires <ArgumentOutOfRangeException>(trackId != Guid.Empty); using (var req = new HttpRequestMessage(HttpMethod.Get, ApiUriV1 .Combine("bundles") .Combine(bundleId.ToString("N")) .Combine("tracks") .Combine(trackId.ToString("N")))) { using (var res = await http.SendAsync(req)) { res.EnsureSuccessStatusCode(); var str = await res.Content.ReadAsStringAsync(); var obj = JsonConvert.DeserializeObject <Track>(str); return(obj); } } }