Class: BucketClient::GCPBucket

Inherits:
Bucket
  • Object
show all
Defined in:
lib/bucket_client/gcp/gcp_bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from KeyMethod

#create_blob!, #delete_blob!, #delete_blob_if_exist!, #get_blob!, #put_blob!, #update_blob!

Methods included from UriMethod

#delete_blob_if_exist_with_uri!, #delete_blob_with_uri!, #get_blob_with_uri!, #put_blob_with_uri!, #update_blob_with_uri!

Constructor Details

#initialize(parent, key) ⇒ GCPBucket

Returns a new instance of GCPBucket.

Parameters:



9
10
11
12
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 9

def initialize(parent, key)
	@bucket_client = parent
	@key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 5

def key
  @key
end

Instance Method Details

#create_blob(payload, key) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 59

def create_blob(payload, key)
	exist = exist_blob key
	if exist
		OperationResult.new false, "Blob already exist", nil, 400
	else
		put_blob payload, key
	end
end

#delete_blob(key) ⇒ Object



72
73
74
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 72

def delete_blob(key)
	delete_blob_with_uri(get_uri key)
end

#delete_blob_if_exist(key) ⇒ Object



76
77
78
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 76

def delete_blob_if_exist(key)
	delete_blob_if_exist_with_uri(get_uri key)
end

#delete_blob_if_exist_with_uri(uri) ⇒ Object



43
44
45
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 43

def delete_blob_if_exist_with_uri(uri)
	@bucket_client.delete_blob_if_exist(uri)
end

#delete_blob_with_uri(uri) ⇒ Object



39
40
41
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 39

def delete_blob_with_uri(uri)
	@bucket_client.delete_blob(uri)
end

#exist_blob(key) ⇒ Object



51
52
53
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 51

def exist_blob(key)
	exist_blob_with_uri(get_uri key)
end

#exist_blob_with_uri(uri) ⇒ Object



22
23
24
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 22

def exist_blob_with_uri(uri)
	@bucket_client.exist_blob(uri)
end

#get_blob(key) ⇒ Object



47
48
49
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 47

def get_blob(key)
	get_blob_with_uri(get_uri key)
end

#get_blob_with_uri(uri) ⇒ Object



18
19
20
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 18

def get_blob_with_uri(uri)
	@bucket_client.get_blob uri
end

#get_uri(key) ⇒ Object



14
15
16
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 14

def get_uri(key)
	"https://storage.googleapis.com/#{@key}/#{key}"
end

#put_blob(payload, key) ⇒ Object



55
56
57
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 55

def put_blob(payload, key)
	put_blob_with_uri(payload, get_uri(key))
end

#put_blob_with_uri(payload, uri) ⇒ Object



26
27
28
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 26

def put_blob_with_uri(payload, uri)
	@bucket_client.put_blob payload, uri
end

#update_blob(payload, key) ⇒ Object



68
69
70
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 68

def update_blob(payload, key)
	update_blob_with_uri(payload, get_uri(key))
end

#update_blob_with_uri(payload, uri) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/bucket_client/gcp/gcp_bucket.rb', line 30

def update_blob_with_uri(payload, uri)
	exist = exist_blob_with_uri uri
	if exist
		put_blob_with_uri payload, uri
	else
		OperationResult.new false, "Blob does not exist", nil, 400
	end
end