Esempio n. 1
0
        public async Task <JSON_ListBuckets> ListBuckets(string AccountID, BucketTypesEnum BucketType = BucketTypesEnum.all)
        {
            var parameters = new Dictionary <object, object>()
            {
                { "accountId", AccountID }, { "bucketTypes", new List <string>()
                                              {
                                                  { BucketType.ToString() }
                                              } }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var HtpReqMessage = new HtpRequestMessage(HttpMethod.Post, new pUri("b2_list_buckets"))
                {
                    Content = SerializeDictionary(parameters)
                };
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    return(response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <JSON_ListBuckets>(result, JSONhandler) : throw ShowError(result, (int)response.StatusCode));
                }
            }
        }
Esempio n. 2
0
        public async Task <JSON_BucketMetadata> UpdateBucket(string AccountID, string DestinationBucketID, BucketTypesEnum BucketType)
        {
            var parameters = new Dictionary <object, object>()
            {
                { "accountId", AccountID }, { "bucketId", DestinationBucketID }, { "bucketType", BucketType.ToString() }
            };

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                var HtpReqMessage = new HtpRequestMessage(HttpMethod.Post, new Uri(APIbase + "b2_update_bucket"))
                {
                    Content = SerializeDictionary(parameters)
                };
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    return(response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <JSON_BucketMetadata>(result, JSONhandler) : throw ShowError(result, (int)response.StatusCode));
                }
            }
        }