Class: CloudStrg::CloudStorage

Inherits:
Object
  • Object
show all
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

Instance Method Details

#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.

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/cloudstrg/cloudstrg.rb', line 63

def create_file params
  raise NotImplementedError
end

#delete_remoteobject(ro_id) ⇒ Object



140
141
142
# File 'lib/cloudstrg/cloudstrg.rb', line 140

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.

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/cloudstrg/cloudstrg.rb', line 83

def get_file params
  raise NotImplementedError
end

#get_remoteobject(ro_id) ⇒ Object



136
137
138
# File 'lib/cloudstrg/cloudstrg.rb', line 136

def get_remoteobject(ro_id)
  return Cloudstrg::Remoteobject.find(ro_id)
end

#list_filesObject

This method returns a list of the available files created by the application.

Returns:

This method returns a list of tuples, containing: [[filename, fileid], ...]

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cloudstrg/cloudstrg.rb', line 122

def save_remoteobject(user, filename, filecontent, file_remote_id)
  #plugin_name = self.class.to_s.split('Strg')[0].downcase
  
  file = Cloudstrg::Remoteobject.where(:user_id => user, :cloudstrgplugin_id => user.cloudstrgconfig.cloudstrgplugin, :filename => filename)
  if not file.empty?
    file = file[0]
    file.filehash = filecontent.hash.to_s
  else
    file = user.cloudstrgconfig.cloudstrgplugin.remotes.build(:user_id => user, :filename => filename, :filehash => filecontent.hash.to_s, :file_remote_id => file_remote_id)
  end
  file.save
  return file
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.

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/cloudstrg/cloudstrg.rb', line 98

def update_file params
  raise NotImplementedError
end