module FilestackCommon
Module is mixin for common functionalities that all Filestack
objects can call.
Public Instance Methods
Send the delete api request to delete a filelink
@param [String] url The url of the Filehandle
to be deleted (includes security)
@return [Typhoeus::Response]
# File lib/filestack/mixins/filestack_common.rb, line 38 def send_delete(handle, apikey, security) return 'Delete requires security' if security.nil? signature = security.signature policy = security.policy base = "#{FilestackConfig::API_URL}/file" UploadUtils.make_call( "#{base}/#{handle}?key=#{apikey}&signature=#{signature}&policy=#{policy}", 'delete' ) end
Get the content of a filehandle
@param [String] filepath Local path of file to be written
@return [Int] Size of file written
# File lib/filestack/mixins/filestack_common.rb, line 27 def send_download(url, filepath) content = send_get_content(url) File.write(filepath, content.body) end
Get the contents of a Filestack
handle
@param [String] file_handle The Filelink handle @param [FilestackSecurity] security Optional Filestack
security object
if security is enabled
@return [Bytes]
# File lib/filestack/mixins/filestack_common.rb, line 18 def send_get_content(url, parameters: nil) UploadUtils.make_call(url, 'get', parameters: parameters) end
# File lib/filestack/mixins/filestack_common.rb, line 96 def send_metadata(handle, security = nil, params) if security policy = security.policy signature = security.signature url = "#{FilestackConfig::CDN_URL}/#{handle}/metadata?signature=#{signature}&policy=#{policy}" else url = "#{FilestackConfig::CDN_URL}/#{handle}/metadata" end response = UploadUtils.make_call(url, 'get', parameters: params) if response.code == 200 return JSON.parse(response.body) end raise response.body end
Send the overwrite api request to update a filelink
@param [String] filepath Filepath of file to upload @param [String] handle The Filelink handle @param [String] apikey Filestack
API Key @param [FilestackSecurity] security Filestack
security object
@return [Typhoeus::Response]
# File lib/filestack/mixins/filestack_common.rb, line 57 def send_overwrite(filepath, handle, apikey, security) return 'Overwrite requires security' if security.nil? file = File.open(filepath, 'r') mimetype = MiniMime.lookup_by_filename(file).content_type content = file.read signature = security.signature policy = security.policy headers = { 'Content-Type' => mimetype } base = "#{FilestackConfig::API_URL}/file" UploadUtils.make_call( "#{base}/#{handle}?key=#{apikey}&signature=#{signature}&policy=#{policy}", 'put', headers: headers, parameters: content ) end