30 lines
699 B
Ruby
30 lines
699 B
Ruby
# 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)
|
|
"#{base_url}/#{entry.stripped_md5}.#{entry.filetype}"
|
|
end
|
|
end
|
|
end
|