2024-05-03 03:04:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module StorageManager
|
|
|
|
class Bunny
|
|
|
|
attr_reader :base_url, :access_key, :storage_zone_name
|
|
|
|
|
|
|
|
def initialize(base_url:, access_key:, storage_zone_name:)
|
|
|
|
@base_url = base_url
|
|
|
|
@access_key = access_key
|
|
|
|
@storage_zone_name = storage_zone_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
|
|
|
Requests::Bunny.new(access_key: access_key, storage_zone_name: storage_zone_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
delegate :delete, :exists?, :get, :put, to: :request
|
|
|
|
|
|
|
|
def upload(path, body)
|
|
|
|
r = put(path, body)
|
|
|
|
return nil unless r.success?
|
|
|
|
"#{base_url}/#{path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def url_for(entry)
|
2024-05-06 07:47:53 +00:00
|
|
|
"#{base_url}#{entry.path}"
|
2024-05-03 03:04:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|