Module: FilestackCommon
- Includes:
- UploadUtils
- Included in:
- FilestackFilelink
- Defined in:
- lib/filestack/mixins/filestack_common.rb
Overview
Module is mixin for common functionalities that all Filestack objects can call.
Instance Method Summary collapse
-
#send_delete(handle, apikey, security) ⇒ Typhoeus::Response
Send the delete api request to delete a filelink.
-
#send_download(filepath) ⇒ Int
Get the content of a filehandle.
-
#send_get_content(url, parameters: nil) ⇒ Bytes
Get the contents of a Filestack handle.
- #send_metadata(handle, security = nil, params) ⇒ Object
-
#send_overwrite(filepath, handle, apikey, security) ⇒ Typhoeus::Response
Send the overwrite api request to update a filelink.
-
#send_tags(task, handle, security) ⇒ Hash
Get tags or sfw content from a filelink.
Methods included from UploadUtils
#get_url, #make_call, #send_upload
Instance Method Details
#send_delete(handle, apikey, security) ⇒ Typhoeus::Response
Send the delete api request to delete a filelink
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/filestack/mixins/filestack_common.rb', line 37 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 |
#send_download(filepath) ⇒ Int
Get the content of a filehandle
26 27 28 29 |
# File 'lib/filestack/mixins/filestack_common.rb', line 26 def send_download(filepath) content = send_get_content(url) File.write(filepath, content.body) end |
#send_get_content(url, parameters: nil) ⇒ Bytes
Get the contents of a Filestack handle
17 18 19 |
# File 'lib/filestack/mixins/filestack_common.rb', line 17 def send_get_content(url, parameters: nil) UploadUtils.make_call(url, 'get', parameters: parameters) end |
#send_metadata(handle, security = nil, params) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/filestack/mixins/filestack_common.rb', line 94 def (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 response.body end raise response.body end |
#send_overwrite(filepath, handle, apikey, security) ⇒ Typhoeus::Response
Send the overwrite api request to update a filelink
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/filestack/mixins/filestack_common.rb', line 56 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 |
#send_tags(task, handle, security) ⇒ Hash
Get tags or sfw content from a filelink
84 85 86 87 88 89 90 91 92 |
# File 'lib/filestack/mixins/filestack_common.rb', line 84 def (task, handle, security) raise 'You must use security for tags' if security.nil? policy = security.policy signature = security.signature url = "#{FilestackConfig::CDN_URL}/#{task}/"\ "security=signature:#{signature},policy:#{policy}/#{handle}" UploadUtils.make_call(url, 'get').body[task] end |