Module: BucketClient::BucketMethods
- Included in:
- Client
- Defined in:
- lib/bucket_client/client.rb
Instance Method Summary collapse
-
#create_bucket(key) ⇒ OperationResult
Creates a bucket Fails if bucket already exist.
-
#create_bucket!(key) ⇒ Bucket
Creates a bucket Fails if bucket already exist.
-
#delete_bucket(key) ⇒ OperationResult
Deletes a bucket Fails if the bucket does not exist.
-
#delete_bucket!(key) ⇒ Object
Deletes a bucket Fails if the bucket does not exist Raises error if it operation fails.
-
#delete_bucket_if_exist(key) ⇒ OperationResult
Delete the bucket if it exist.
-
#delete_bucket_if_exist!(key) ⇒ Object
Delete the bucket if it exist.
-
#exist_bucket(key) ⇒ Boolean
Check if bucket exist Throws exception if the HTTP request fails.
-
#get_bucket(key) ⇒ Bucket
Gets the instance of the bucket.
-
#get_bucket!(key) ⇒ Bucket
Gets the instance of the bucket Does not check whether the bucket exist or not.
-
#put_bucket(key) ⇒ OperationResult
Creates the bucket if it does not exist.
-
#put_bucket!(key) ⇒ Bucket
Creates the bucket if it does not exist.
-
#set_get_cors(key, cors) ⇒ OperationResult
Sets the GET CORS for the bucket Fails if bucket does not exist.
-
#set_get_cors!(key, cors) ⇒ Object
Sets the GET CORS for the bucket Fails if bucket does not exist.
-
#set_read_policy(key, access) ⇒ OperationResult
Sets the read policy of the bucket Fails if bucket does not exist.
-
#set_read_policy!(key, access) ⇒ Object
Sets the read policy of the bucket Fails if bucket does not exist.
Instance Method Details
#create_bucket(key) ⇒ OperationResult
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
26 27 28 |
# File 'lib/bucket_client/client.rb', line 26 def create_bucket(key) raise NotImplementedError key end |
#create_bucket!(key) ⇒ Bucket
Creates a bucket Fails if bucket already exist
Raises exception if the operation failed
bucket = client.create_bucket!(“folder_name”) bucket #=> Bucket Instance
40 41 42 43 44 |
# 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 |
#delete_bucket(key) ⇒ OperationResult
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
57 58 59 |
# File 'lib/bucket_client/client.rb', line 57 def delete_bucket(key) raise NotImplementedError key end |
#delete_bucket!(key) ⇒ Object
Deletes a bucket Fails if the bucket does not exist Raises error if it operation fails
client.delete_bucket! “folder”
68 69 70 71 |
# 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_bucket_if_exist(key) ⇒ OperationResult
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
177 178 179 |
# File 'lib/bucket_client/client.rb', line 177 def delete_bucket_if_exist(key) raise NotImplementedError key end |
#delete_bucket_if_exist!(key) ⇒ Object
Delete the bucket if it exist
Raises exception if operations fails
client.delete_bucket_if_exist! “folder”
188 189 190 191 |
# 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 |
#exist_bucket(key) ⇒ Boolean
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)
11 12 13 |
# File 'lib/bucket_client/client.rb', line 11 def exist_bucket(key) raise NotImplementedError key end |
#get_bucket(key) ⇒ Bucket
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
204 205 206 207 208 209 |
# 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 |
#get_bucket!(key) ⇒ Bucket
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”
224 225 226 |
# File 'lib/bucket_client/client.rb', line 224 def get_bucket!(key) raise NotImplementedError key end |
#put_bucket(key) ⇒ OperationResult
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
149 150 151 |
# File 'lib/bucket_client/client.rb', line 149 def put_bucket(key) raise NotImplementedError key end |
#put_bucket!(key) ⇒ Bucket
Creates the bucket if it does not exist
Raises exception if the operation fails
bucket = client.put_bucket “folder”! #=> Bucket if succeeds
161 162 163 164 165 |
# 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 |
#set_get_cors(key, cors) ⇒ OperationResult
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
121 122 123 |
# File 'lib/bucket_client/client.rb', line 121 def set_get_cors(key, cors) throw new NotImplementedError key + cors.to_s end |
#set_get_cors!(key, cors) ⇒ Object
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”]
134 135 136 137 |
# 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 |
#set_read_policy(key, access) ⇒ OperationResult
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
89 90 91 |
# File 'lib/bucket_client/client.rb', line 89 def set_read_policy(key, access) raise NotImplementedError key + access end |
#set_read_policy!(key, access) ⇒ Object
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
104 105 106 107 |
# 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 |