module BucketClient::BucketMethods
Public Instance Methods
Creates a bucket Fails if bucket already exist
result = client.create_bucket “folder” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> the bucket instance
@param [String] key the bucket name or id @return [OperationResult]
# File lib/bucket_client/client.rb, line 26 def create_bucket(key) raise NotImplementedError key end
Creates a bucket Fails if bucket already exist
Raises exception if the operation failed
bucket = client.create_bucket!(“folder_name”) bucket #=> Bucket
Instance
@param [String] key the bucket name or id @return [Bucket]
# File lib/bucket_client/client.rb, line 40 def create_bucket!(key) result = create_bucket key raise BucketOperationException.new(result) unless result.success result.value end
Deletes a bucket Fails if the bucket does not exist
result = client.delete_bucket “folder” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> nil
@param [String] key the bucket name or id @return [OperationResult]
# File lib/bucket_client/client.rb, line 57 def delete_bucket(key) raise NotImplementedError key end
Deletes a bucket Fails if the bucket does not exist Raises error if it operation fails
client.delete_bucket! “folder”
@param [String] key the bucket name or id
# File lib/bucket_client/client.rb, line 68 def delete_bucket!(key) result = delete_bucket key raise BucketOperationException.new(result) unless result.success end
Delete the bucket if it exist
result = client.delete_bucket_if_exist “folder” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed bucket.value #=> nil
@param [String] key the bucket name or id @return [OperationResult]
# File lib/bucket_client/client.rb, line 177 def delete_bucket_if_exist(key) raise NotImplementedError key end
Delete the bucket if it exist
Raises exception if operations fails
client.delete_bucket_if_exist! “folder”
@param [String] key the bucket name or id
# File lib/bucket_client/client.rb, line 188 def delete_bucket_if_exist!(key) result = delete_bucket key raise BucketOperationException.new(result) unless result.success end
Check if bucket exist Throws exception if the HTTP request fails
exist = client.exist_bucket(“folder”) # => true (if bucket exist) exist = client.exist_bucket(“folder”) #=> false (if bucket does not exist)
@param [String] key the bucket name or id @return [Boolean]
# File lib/bucket_client/client.rb, line 11 def exist_bucket(key) raise NotImplementedError key end
Gets the instance of the bucket.
Checks whether the bucket exist and returns a Bucket
Instance to interact with the bucket if it does.
Raises exception if bucket does not exist
bucket = client.get_bucket “folder” #=> Gets bucket instance of it exist
@param [String] key the bucket name or id @return [Bucket]
# File lib/bucket_client/client.rb, line 204 def get_bucket(key) exist = exist_bucket key result = OperationResult.new(false, "Bucket does not exist", nil, 404) raise BucketOperationException.new(result) unless exist get_bucket! key end
Gets the instance of the bucket Does not check whether the bucket exist or not. Simply generates a bucket instance optimistically. This operation is non-block as compared to get_bucket
as it does not send out a HTTP request to check if the bucket exist.
However, the bucket will not work (raise exception) if the bucket does not exist when you use the instance. Use this method only when you are sure that the bucket exist.
bucket = client.get_bucket! “folder”
@param [String] key the bucket name or id @return [Bucket]
# File lib/bucket_client/client.rb, line 224 def get_bucket!(key) raise NotImplementedError key end
Creates the bucket if it does not exist
result = client.put_bucket “folder” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> bucket instance
@param [String] key the bucket name or id @return [OperationResult]
# File lib/bucket_client/client.rb, line 149 def put_bucket(key) raise NotImplementedError key end
Creates the bucket if it does not exist
Raises exception if the operation fails
bucket = client.put_bucket “folder”! #=> Bucket
if succeeds
@param [String] key the bucket name or id @return [Bucket]
# File lib/bucket_client/client.rb, line 161 def put_bucket!(key) result = put_bucket key raise BucketOperationException.new(result) unless result.success result.value end
Sets the GET CORS for the bucket Fails if bucket does not exist
result = client.set_get_cors “folder”, [“domain2.net”,“domain1.net”] result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> nil
@param [String] key the bucket name or id @param [Array<String>] cors Array of CORS to allow GET requests @return [OperationResult]
# File lib/bucket_client/client.rb, line 121 def set_get_cors(key, cors) throw new NotImplementedError key + cors.to_s end
Sets the GET CORS for the bucket Fails if bucket does not exist
Raises exception if operation fails
client.set_get_cors! “folder”, [“domain2.net”,“domain1.net”]
@param [String] key the bucket name or id @param [Array<String>] cors Array of CORS to allow GET requests
# File lib/bucket_client/client.rb, line 134 def set_get_cors!(key, cors) result = set_get_cors key, cors raise BucketOperationException.new(result) unless result.success end
Sets the read policy of the bucket Fails if bucket does not exist
Raises exception if neither :public nor :private is provided.
result = client.set_read_policy :public #=> Sets read policy to public result_2 = client.set_read_policy :private #=> Sets read policy to private
result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> nil
@param [String] key the bucket name or id @param [Symbol] access :public or :private @return [OperationResult]
# File lib/bucket_client/client.rb, line 89 def set_read_policy(key, access) raise NotImplementedError key + access end
Sets the read policy of the bucket Fails if bucket does not exist
Raises exception if neither :public nor :private is provided. Raises exception if the operation fails
client.set_read_policy! :public #=> Sets read policy to public client.set_read_policy! :private #=> Sets read policy to private
@param [String] key the bucket name or id @param [Symbol] access :public or :private
# File lib/bucket_client/client.rb, line 104 def set_read_policy!(key, access) result = set_read_policy key, access raise BucketOperationException.new(result) unless result.success end