Example #1
0
        /// <summary>
        /// Used to return all buckets associated with an account.
        /// </summary>
        /// <param name="type">The bucket type to return.</param>
        /// <returns>A list of buckets, if any are present.</returns>
        public List <Bucket> ListBuckets(BucketType type)
        {
            var body = new Dictionary <string, string>
            {
                { "accountId", Session.Instance.accountSession.AccountId }
            };

            return(ExecuteB2Request <DtoBuckets>(body, Constant.Resouce.ListBuckets).Buckets);
        }
Example #2
0
        /// <summary>
        /// Creates a new bucket.
        /// </summary>
        /// <param name="name">The new name of the bucket. A name must be alphanumeric, at least six characters, and a max of fifty characters.</param>
        /// <param name="type">Only public and private types are valid when creating a bucket.</param>
        /// <returns>The updated bucket.</returns>
        public Bucket CreateBucket(string name, BucketType type)
        {
            Guard.Against.B2NameError(name);
            Guard.Against.B2BucketTypeError(type);
            Guard.Against.NullOrEmpty(name, nameof(name));
            var body = new Dictionary <string, string>
            {
                { "accountId", Session.Instance.accountSession.AccountId },
                { "bucketName", name },
                { "bucketType", HashMap.FromBucketType[type] }
            };

            return(ExecuteB2Request <Bucket>(body, Constant.Resouce.CreateBucket));
        }
Example #3
0
        /// <summary>
        /// Change the bucket to private or public.
        /// </summary>
        /// <param name="name">The new name of the bucket. A name must be alphanumeric, at least six characters, and a max of fifty characters.</param>
        /// <param name="type">Only public and private types are valid when changing a bucket's type.</param>
        public void SetBucketType(string name, BucketType type)
        {
            var body = new Dictionary <string, string>
            {
                { "accountId", Session.Instance.accountSession.AccountId },
                { "bucketType", HashMap.FromBucketType[type] },
                { "bucketId", GetBucketIdFromName(name) }
            };
            var responce = ExecuteB2Request <Bucket>(body, Constant.Resouce.UpdateBucket);

            if (responce.BucketType != HashMap.FromBucketType[type])
            {
                throw new B2Exception($"Bucket {name} failed to update.");
            }
        }