class Base::Endpoints::Files
This endpoint contains methods for uploading and managing files.
Public Class Methods
new(access_token:, url:)
click to toggle source
Initializes this endpoint.
Calls superclass method
Base::Endpoint::new
# File lib/base/endpoints/files.rb, line 8 def initialize(access_token:, url:) @path = 'files' super end
Public Instance Methods
create(path:, type:, filename:)
click to toggle source
Uploads the given file and returns its metadata.
# File lib/base/endpoints/files.rb, line 24 def create(path:, type:, filename:) request do io = Faraday::UploadIO.new(path, type, filename) response = connection.post('', 'file' => io) parse(response.body) end end
delete(id)
click to toggle source
Deletes the file with the given ID.
# File lib/base/endpoints/files.rb, line 64 def delete(id) request do response = connection.delete id parse(response.body) end end
download(id)
click to toggle source
Downloads the file with the given ID into an IO.
# File lib/base/endpoints/files.rb, line 43 def download(id) response = Faraday.new(download_url(id)) do |conn| conn.use RaiseError conn.use Faraday::Adapter::NetHttp end.get io(response.body) end
download_url(id)
click to toggle source
Returns the publicly accessible download URL of the file with the given ID.
# File lib/base/endpoints/files.rb, line 38 def download_url(id) "#{connection.url_prefix}#{id}/download" end
get(id)
click to toggle source
Returns the metadata of the file with the given ID.
# File lib/base/endpoints/files.rb, line 54 def get(id) request do response = connection.get id parse(response.body) end end
list(page: 1, per_page: 10)
click to toggle source
Lists the files of a project
# File lib/base/endpoints/files.rb, line 14 def list(page: 1, per_page: 10) request do response = connection.get('', per_page: per_page, page: page) parse(response.body) end end