Module: BucketClient::KeyMethod

Included in:
Bucket
Defined in:
lib/bucket_client/bucket.rb

Instance Method Summary collapse

Instance Method Details

#create_blob(payload, key) ⇒ OperationResult

Create blob with payload Fails if blob already exist

img = IO.binread “image.png” result = bucket.create_blob img, “image.png” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> URI of the blob

Parameters:

  • payload (Array<Byte>)

    the payload to create blob with

  • key (String)

    the blob id or name

Returns:



58
59
60
# File 'lib/bucket_client/bucket.rb', line 58

def create_blob(payload, key)
	raise NotImplementedError payload.to_s, key
end

#create_blob!(payload, key) ⇒ String

Creates blob with payload Fails if blob already exist

Raises exception if operation fails

img = IO.binread “image.png” uri = bucket.create_blob! img, “image.png” #=> URI of the created blob

Parameters:

  • payload (Array<Byte>)

    the payload to create blob with

  • key (String)

    the blob id or name

Returns:

  • (String)

Raises:



73
74
75
76
77
# File 'lib/bucket_client/bucket.rb', line 73

def create_blob!(payload, key)
	result = create_blob payload, key
	raise BucketOperationException.new(result) unless result.success
	result.value
end

#delete_blob(key) ⇒ OperationResult

Deletes a blob Fails if the blob does not exist. To prevent this behaviour, use delete_blob_if_exist method

result = bucket.delete_blob “image.png” result.success #=> whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> nil

Parameters:

  • key (String)

    the blob id or name

Returns:



158
159
160
# File 'lib/bucket_client/bucket.rb', line 158

def delete_blob(key)
	raise NotImplementedError key
end

#delete_blob!(key) ⇒ Object

Deletes a blob Fails if the blob does not exist. To prevent this behaviour, use delete_blob_if_exist method

Raises exception if the operation fails

bucket.delete_blob! “image.png”

Parameters:

  • key (String)

    the blob id or name

Raises:



170
171
172
173
# File 'lib/bucket_client/bucket.rb', line 170

def delete_blob!(key)
	result = delete_blob key
	raise BucketOperationException.new(result) unless result.success
end

#delete_blob_if_exist(key) ⇒ OperationResult

Deletes a blob if it exist

result = bucket.delete_blob_if_exist “image.png” result.success #=> whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> nil

Parameters:

  • key (String)

    the blob id or name

Returns:



185
186
187
# File 'lib/bucket_client/bucket.rb', line 185

def delete_blob_if_exist(key)
	raise NotImplementedError key
end

#delete_blob_if_exist!(key) ⇒ Object

Deletes a blob if it exist Raises exception if operation fails

bucket.delete_blob_if_exist! “image.png”

Parameters:

  • key (String)

    the blob id or name

Raises:



195
196
197
198
# File 'lib/bucket_client/bucket.rb', line 195

def delete_blob_if_exist!(key)
	result = delete_blob_if_exist key
	raise BucketOperationException.new(result) unless result.success
end

#exist_blob(key) ⇒ Boolean

Check if the blob exist

Raises exception if operation fails

exist = bucket.exist_blob “image.png” #=> true if exist, false if not

Parameters:

  • key (String)

    the blob id or name

Returns:

  • (Boolean)


41
42
43
# File 'lib/bucket_client/bucket.rb', line 41

def exist_blob(key)
	raise NotImplementedError key
end

#get_blob(key) ⇒ OperationResult

Get blob as byte array

result = bucket.get_blob “image.png” result.success #=> Whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> the byte array of the blob

Parameters:

  • key (String)

    the blob id or name

Returns:



15
16
17
# File 'lib/bucket_client/bucket.rb', line 15

def get_blob(key)
	raise NotImplementedError key
end

#get_blob!(key) ⇒ Array<Byte>

Get blob as byte array

Raises exception if the operation fails.

img = bucket.get_blob! “image.png”

Parameters:

  • key (String)

    the blob id or name

Returns:

  • (Array<Byte>)

Raises:



27
28
29
30
31
# File 'lib/bucket_client/bucket.rb', line 27

def get_blob!(key)
	result = get_blob key
	raise BucketOperationException.new(result) unless result.success
	result.value
end

#put_blob(payload, key) ⇒ OperationResult

Creates a new blob with payload if blob does not exist Updates blob with new payload if blob exist

img = IO.binread “image.png” result = bucket.put_blob(img, “image.png”) result.success #=> whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> URI of the blob

Parameters:

  • payload (Array<Byte>)

    the payload to put

  • key (String)

    the blob id or name

Returns:



125
126
127
# File 'lib/bucket_client/bucket.rb', line 125

def put_blob(payload, key)
	raise NotImplementedError payload.to_s, key
end

#put_blob!(payload, key) ⇒ String

Creates a new blob with payload if blob does not exist Updates blob with new payload if blob exist

Raises exception if operation fails

img = IO.binread “image.png” uri = bucket.put_blob! img, “image.png” #=> uri of the blob

Parameters:

  • payload (Array<Byte>)

    the payload to put

  • key (String)

    the blob id or name

Returns:

  • (String)

Raises:



140
141
142
143
144
# File 'lib/bucket_client/bucket.rb', line 140

def put_blob!(payload, key)
	result = put_blob payload, key
	raise BucketOperationException.new(result) unless result.success
	result.value
end

#update_blob(payload, key) ⇒ OperationResult

Updates the blob with new payload Fails if blob does not exist

img = IO.binread “image.png” result = bucket.update_blob img, “image.png” result.success #=> whether the operation succeeded result.code #=> Status Code of the operation result.message #=> Error message if it failed result.value #=> URI of the blob

Parameters:

  • payload (Array<Byte>)

    the payload to update

  • key (String)

    the blob id or name

Returns:



92
93
94
# File 'lib/bucket_client/bucket.rb', line 92

def update_blob(payload, key)
	raise NotImplementedError payload.to_s, key
end

#update_blob!(payload, key) ⇒ String

Updates the blob with new payload Fails if blob does not exist Raises exception if operation fails

img = IO.binread “image.png” result = bucket.update_blob!(img, “image.png”) #=> URI of updated blob

Parameters:

  • payload (Array<Byte>)

    the payload to update

  • key (String)

    the blob id or name

Returns:

  • (String)

Raises:



106
107
108
109
110
# File 'lib/bucket_client/bucket.rb', line 106

def update_blob!(payload, key)
	result = update_blob payload, key
	raise BucketOperationException.new(result) unless result.success
	result.value
end