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.
- #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.
-
#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
142 143 144 |
# File 'lib/cloudstrg/cloudstrg.rb', line 142 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 |
#delete_remoteobject(ro_id) ⇒ Object
166 167 168 |
# File 'lib/cloudstrg/cloudstrg.rb', line 166 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.
83 84 85 |
# File 'lib/cloudstrg/cloudstrg.rb', line 83 def get_file params raise NotImplementedError end |
#get_remoteobject(ro_id) ⇒ Object
162 163 164 |
# File 'lib/cloudstrg/cloudstrg.rb', line 162 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], ...]
118 119 120 |
# File 'lib/cloudstrg/cloudstrg.rb', line 118 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.
108 109 110 |
# File 'lib/cloudstrg/cloudstrg.rb', line 108 def remove_file params raise NotImplementedError end |
#save_remoteobject(user, filename, filecontent, file_remote_id) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cloudstrg/cloudstrg.rb', line 146 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, :cloudstrgplugin_id => plugin, :filename => filename) if not file.empty? file = file[0] file.filehash = filecontent.hash.to_s else file = plugin.remotes.build(:user_id => user, :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.
Returns:
This method returns non-nil data if success.
132 133 134 |
# File 'lib/cloudstrg/cloudstrg.rb', line 132 def share_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.
98 99 100 |
# File 'lib/cloudstrg/cloudstrg.rb', line 98 def update_file params raise NotImplementedError end |