Class: CloudStrg::CloudStorage
- Inherits:
-
Object
- Object
- CloudStrg::CloudStorage
- Defined in:
- lib/cloudstrg/cloudstrg.rb
Overview
This class must be inherited by every single driver definition in order to preserve the coherence between them.
Instance Method Summary collapse
-
#check_referer(referer) ⇒ Object
This method check if a referer is valid.
-
#config(params) ⇒ Object
This method performs the previous configuration that the current driver needs to work.
-
#create_file(params) ⇒ Object
This method performs the creation of a file.
-
#create_generic_file(params) ⇒ Object
This method performs the creation of a file.
- #delete_remoteobject(ro_id) ⇒ Object
-
#get_file(params) ⇒ Object
This method performs the request to obtain a desired file content.
- #get_remoteobject(ro_id) ⇒ Object
-
#list_files ⇒ Object
This method returns a list of the available files created by the application.
-
#remove_file(params) ⇒ Object
This method performs the remove of a file.
- #save_remoteobject(user, filename, filecontent, file_remote_id) ⇒ Object
-
#share_file(params) ⇒ Object
This method allows a user to share a file with other users.
-
#share_public_file(params) ⇒ Object
This method allows a user to share a file with anyone.
-
#unshare_file(params) ⇒ Object
This method allows a user to revoke a file’s permission to other users.
-
#update_file(params) ⇒ Object
This method performs the update of a file.
Instance Method Details
#check_referer(referer) ⇒ Object
This method check if a referer is valid
Params:
referer: a string containing the request referer
189 190 191 |
# File 'lib/cloudstrg/cloudstrg.rb', line 189 def check_referer referer raise NotImplementedError end |
#config(params) ⇒ Object
This method performs the previous configuration that the current driver needs to work.
Params: the “params” variable must contain the following fields
redirect: url that we want the application to redirect us before accepting the selected cloud engine terms,
user: the current user,
session: the session hash.
Returns:
This method returns two parameters:
session: the session variable with the new parameters added,
uri: the uri where the user will allow the application to use the desired service,
or false if the configuration was completed successfully.
49 50 51 |
# File 'lib/cloudstrg/cloudstrg.rb', line 49 def config params raise NotImplementedError end |
#create_file(params) ⇒ Object
This method performs the creation of a file.
Params: the “params” variable must contain the following fields
filename: the name of the file to create,
file_content: the content of the file.
Returns:
This method returns the local id of the remote object if the operation success, otherwise it returns false.
63 64 65 |
# File 'lib/cloudstrg/cloudstrg.rb', line 63 def create_file params raise NotImplementedError end |
#create_generic_file(params) ⇒ Object
This method performs the creation of a file.
Params: the “params” variable must contain the following fields
filename: the name of the file to create,
file: the file to upload.
mimetype: the mimetype of the file,
Returns:
This method returns the local id of the remote object if the operation success, otherwise it returns false.
78 79 80 |
# File 'lib/cloudstrg/cloudstrg.rb', line 78 def create_generic_file params raise NotImplementedError end |
#delete_remoteobject(ro_id) ⇒ Object
213 214 215 |
# File 'lib/cloudstrg/cloudstrg.rb', line 213 def delete_remoteobject(ro_id) return Cloudstrg::Remoteobject.find(ro_id).destroy end |
#get_file(params) ⇒ Object
This method performs the request to obtain a desired file content
Params: the “params” variable must contain the following fields
fileid: the id of the selected file.
Returns:
This method returns three parameters:
filename: the name of the file,
fileid: the id of the file,
file_content: the content of the file.
98 99 100 |
# File 'lib/cloudstrg/cloudstrg.rb', line 98 def get_file params raise NotImplementedError end |
#get_remoteobject(ro_id) ⇒ Object
209 210 211 |
# File 'lib/cloudstrg/cloudstrg.rb', line 209 def get_remoteobject(ro_id) return Cloudstrg::Remoteobject.find(ro_id) end |
#list_files ⇒ Object
This method returns a list of the available files created by the application.
Returns:
This method returns a list of tuples, containing: [[filename, fileid], ...]
133 134 135 |
# File 'lib/cloudstrg/cloudstrg.rb', line 133 def list_files raise NotImplementedError end |
#remove_file(params) ⇒ Object
This method performs the remove of a file.
Params: the “params” variable must contain the following fields
fileid: the id of the file.
123 124 125 |
# File 'lib/cloudstrg/cloudstrg.rb', line 123 def remove_file params raise NotImplementedError end |
#save_remoteobject(user, filename, filecontent, file_remote_id) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cloudstrg/cloudstrg.rb', line 193 def save_remoteobject(user, filename, filecontent, file_remote_id) plugin_name = self.class.to_s.split('Strg')[0].downcase puts plugin_name plugin = Cloudstrg::Cloudstrgplugin.find_by_plugin_name(plugin_name) file = Cloudstrg::Remoteobject.where(:user_id => user.id, :cloudstrgplugin_id => plugin.id, :file_remote_id => file_remote_id) if not file.empty? file = file[0] file.filehash = filecontent.hash.to_s else file = plugin.remotes.build(:user_id => user.id, :filename => filename, :filehash => filecontent.hash.to_s, :file_remote_id => file_remote_id) end file.save return file end |
#share_file(params) ⇒ Object
This method allows a user to share a file with other users.
Params: the “params” variable must contain the following fields
share_user: the username which we want the file shared with,
file_id: the id of the file,
local_file_id: the local id of the file,
user_id: the id of the user we want to grant.
Returns:
This method returns non-nil data if success.
149 150 151 |
# File 'lib/cloudstrg/cloudstrg.rb', line 149 def share_file params raise NotImplementedError end |
#share_public_file(params) ⇒ Object
This method allows a user to share a file with anyone.
Params: the “params” variable must contain the following fields
file_id: the id of the file,
local_file_id: the local id of the file,
user_id: the id of the user we want to grant.
Returns:
This method returns non-nil data if success.
164 165 166 |
# File 'lib/cloudstrg/cloudstrg.rb', line 164 def share_public_file params raise NotImplementedError end |
#unshare_file(params) ⇒ Object
This method allows a user to revoke a file’s permission to other users.
Params: the “params” variable must contain the following fields
file_id: the id of the file,
local_file_id: the local id of the file,
user_id: the id of the target user.
Returns:
This method returns non-nil data if success.
179 180 181 |
# File 'lib/cloudstrg/cloudstrg.rb', line 179 def unshare_file params raise NotImplementedError end |
#update_file(params) ⇒ Object
This method performs the update of a file.
Params: the “params” variable must contain the following fields
filename: the name of the file to edit,
fileid: the id of the file,
file_content: the content of the file.
Returns:
This method returns the local id of the remote object if the operation success, otherwise it returns false.
113 114 115 |
# File 'lib/cloudstrg/cloudstrg.rb', line 113 def update_file params raise NotImplementedError end |