Class: Backlex::Storage
- Inherits:
-
Object
- Object
- Backlex::Storage
- Defined in:
- lib/backlex/storage.rb
Overview
File operations against /api/storage.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Remove the object at
key. -
#download(key) ⇒ Object
Fetch the raw bytes for
key. -
#initialize(client) ⇒ Storage
constructor
A new instance of Storage.
-
#list(prefix = nil) ⇒ Object
List stored objects, optionally filtered by key prefix.
-
#put(key, body, content_type: nil, folder_id: nil) ⇒ Object
Upload bytes under
key.
Constructor Details
#initialize(client) ⇒ Storage
Returns a new instance of Storage.
8 9 10 |
# File 'lib/backlex/storage.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#delete(key) ⇒ Object
Remove the object at key.
32 33 34 |
# File 'lib/backlex/storage.rb', line 32 def delete(key) @client.request("DELETE", "/api/storage/#{URI.encode_www_form_component(key)}") end |
#download(key) ⇒ Object
Fetch the raw bytes for key.
27 28 29 |
# File 'lib/backlex/storage.rb', line 27 def download(key) @client.get_raw("/api/storage/#{URI.encode_www_form_component(key)}") end |
#list(prefix = nil) ⇒ Object
List stored objects, optionally filtered by key prefix.
13 14 15 16 17 |
# File 'lib/backlex/storage.rb', line 13 def list(prefix = nil) path = "/api/storage" path += "?prefix=#{URI.encode_www_form_component(prefix)}" if prefix && !prefix.empty? @client.request("GET", path)["data"] end |
#put(key, body, content_type: nil, folder_id: nil) ⇒ Object
Upload bytes under key. Pass content_type/folder_id nil to omit them.
20 21 22 23 24 |
# File 'lib/backlex/storage.rb', line 20 def put(key, body, content_type: nil, folder_id: nil) path = "/api/storage/#{URI.encode_www_form_component(key)}" path += "?folderId=#{URI.encode_www_form_component(folder_id)}" if folder_id @client.put_raw(path, body, content_type) end |