Class: Files::FileAction

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/file_action.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ FileAction

Returns a new instance of FileAction.



7
8
9
10
# File 'lib/files.com/models/file_action.rb', line 7

def initialize(attributes = {}, options = {})
  @attributes = attributes || {}
  @options = options || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/file_action.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/file_action.rb', line 5

def options
  @options
end

Class Method Details

.begin_upload(path, params = {}, options = {}) ⇒ Object

Begin file upload

Parameters:

mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
with_rename - boolean - Allow file rename instead of overwrite?


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/files.com/models/file_action.rb', line 120

def self.begin_upload(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params.dig(:part) and !params.dig(:part).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params.dig(:parts) and !params.dig(:parts).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: ref must be an String") if params.dig(:ref) and !params.dig(:ref).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params.dig(:restart) and !params.dig(:restart).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

  response, options = Api.send_request("/file_actions/begin_upload/#{params[:path]}", :post, params, options)
  response.data.map do |entity_data|
    FileUploadPart.new(entity_data, options)
  end
end

.copy(path, params = {}, options = {}) ⇒ Object

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/files.com/models/file_action.rb', line 83

def self.copy(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params.dig(:destination) and !params.dig(:destination).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)

  response, options = Api.send_request("/file_actions/copy/#{params[:path]}", :post, params, options)
  FileAction.new(response.data, options)
end

.move(path, params = {}, options = {}) ⇒ Object

Move file/folder

Parameters:

destination (required) - string - Move destination path.


99
100
101
102
103
104
105
106
107
108
109
# File 'lib/files.com/models/file_action.rb', line 99

def self.move(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params.dig(:destination) and !params.dig(:destination).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)

  response, options = Api.send_request("/file_actions/move/#{params[:path]}", :post, params, options)
  FileAction.new(response.data, options)
end

Instance Method Details

#begin_upload(params = {}) ⇒ Object

Begin file upload

Parameters:

mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
with_rename - boolean - Allow file rename instead of overwrite?


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/files.com/models/file_action.rb', line 64

def begin_upload(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params.dig(:part) and !params.dig(:part).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params.dig(:parts) and !params.dig(:parts).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: ref must be an String") if params.dig(:ref) and !params.dig(:ref).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params.dig(:restart) and !params.dig(:restart).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

  Api.send_request("/file_actions/begin_upload/#{@attributes[:path]}", :post, params, @options)
end

#copy(params = {}) ⇒ Object

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/files.com/models/file_action.rb', line 27

def copy(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params.dig(:destination) and !params.dig(:destination).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)

  Api.send_request("/file_actions/copy/#{@attributes[:path]}", :post, params, @options)
end

#file_migration_idObject

int64 - If status is enqueued, this is the id of the FileMigration to check for status updates.



18
19
20
# File 'lib/files.com/models/file_action.rb', line 18

def file_migration_id
  @attributes[:file_migration_id]
end

#move(params = {}) ⇒ Object

Move file/folder

Parameters:

destination (required) - string - Move destination path.


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/files.com/models/file_action.rb', line 43

def move(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params.dig(:destination) and !params.dig(:destination).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)

  Api.send_request("/file_actions/move/#{@attributes[:path]}", :post, params, @options)
end

#statusObject

string - Status of file operation. Possible values: completed, enqueued.



13
14
15
# File 'lib/files.com/models/file_action.rb', line 13

def status
  @attributes[:status]
end