Exemple #1
0
        /// <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")));
        }
Exemple #2
0
        /// <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"))));
        }
Exemple #3
0
        /// <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));
            }
        }
Exemple #4
0
        /// <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"))));
        }
Exemple #5
0
        /// <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));
            }
        }
Exemple #6
0
        /// <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));
            }
        }
Exemple #7
0
        /// <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));
            }
        }
Exemple #8
0
        /// <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);
                }
            }
        }