Class: Supabase::Storage::BucketApi
- Inherits:
-
Object
- Object
- Supabase::Storage::BucketApi
- Includes:
- Request
- Defined in:
- lib/supabase/storage/bucket_api.rb
Overview
The bucket-management half of the storage client — list / get / create / update / empty / delete on bucket records. Mirrors storage3’s SyncStorageBucketAPI.
Client inherits from this; callers don’t construct BucketApi directly.
Direct Known Subclasses
Instance Method Summary collapse
-
#create_bucket(id, name: nil, public: nil, file_size_limit: nil, allowed_mime_types: nil) ⇒ Hash
The raw response body.
- #delete_bucket(id) ⇒ Object
- #empty_bucket(id) ⇒ Object
- #get_bucket(id) ⇒ Object
-
#initialize(session, base_url, headers) ⇒ BucketApi
constructor
A new instance of BucketApi.
- #list_buckets ⇒ Object
- #update_bucket(id, public: nil, file_size_limit: nil, allowed_mime_types: nil) ⇒ Object
Constructor Details
#initialize(session, base_url, headers) ⇒ BucketApi
Returns a new instance of BucketApi.
19 20 21 22 23 |
# File 'lib/supabase/storage/bucket_api.rb', line 19 def initialize(session, base_url, headers) @session = session @base_url = base_url.end_with?("/") ? base_url : "#{base_url}/" @headers = headers end |
Instance Method Details
#create_bucket(id, name: nil, public: nil, file_size_limit: nil, allowed_mime_types: nil) ⇒ Hash
Returns the raw response body.
40 41 42 43 44 45 46 |
# File 'lib/supabase/storage/bucket_api.rb', line 40 def create_bucket(id, name: nil, public: nil, file_size_limit: nil, allowed_mime_types: nil) json = { "id" => id, "name" => name || id } json["public"] = public unless public.nil? json["file_size_limit"] = file_size_limit unless file_size_limit.nil? json["allowed_mime_types"] = allowed_mime_types unless allowed_mime_types.nil? _request(:post, ["bucket"], json: json) end |
#delete_bucket(id) ⇒ Object
60 61 62 |
# File 'lib/supabase/storage/bucket_api.rb', line 60 def delete_bucket(id) _request(:delete, ["bucket", id], json: {}) end |
#empty_bucket(id) ⇒ Object
56 57 58 |
# File 'lib/supabase/storage/bucket_api.rb', line 56 def empty_bucket(id) _request(:post, ["bucket", id, "empty"], json: {}) end |
#get_bucket(id) ⇒ Object
30 31 32 |
# File 'lib/supabase/storage/bucket_api.rb', line 30 def get_bucket(id) Types::Bucket.from_hash(_request(:get, ["bucket", id])) end |
#list_buckets ⇒ Object
25 26 27 28 |
# File 'lib/supabase/storage/bucket_api.rb', line 25 def list_buckets body = _request(:get, ["bucket"]) Array(body).map { |b| Types::Bucket.from_hash(b) } end |
#update_bucket(id, public: nil, file_size_limit: nil, allowed_mime_types: nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/supabase/storage/bucket_api.rb', line 48 def update_bucket(id, public: nil, file_size_limit: nil, allowed_mime_types: nil) json = { "id" => id, "name" => id } json["public"] = public unless public.nil? json["file_size_limit"] = file_size_limit unless file_size_limit.nil? json["allowed_mime_types"] = allowed_mime_types unless allowed_mime_types.nil? _request(:put, ["bucket", id], json: json) end |