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 - integer - Part if uploading a part.
parts - integer - How many parts to fetch?
ref - string -
restart - integer - File byte offset to restart from.
with_rename - boolean - Allow file rename instead of overwrite?


108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/files.com/models/file_action.rb', line 108

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/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
  FilePartUpload.new(response.data, options)
end

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

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/files.com/models/file_action.rb', line 71

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/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
  response.data
end

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

Move file/folder

Parameters:

destination (required) - string - Move destination path.


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/files.com/models/file_action.rb', line 87

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/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
  response.data
end

Instance Method Details

#begin_upload(params = {}) ⇒ Object

Begin file upload

Parameters:

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


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/files.com/models/file_action.rb', line 53

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/#{Addressable::URI.encode_component(params[:path])}", :post, params, @options)
end

#copy(params = {}) ⇒ Object

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/files.com/models/file_action.rb', line 16

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/#{Addressable::URI.encode_component(params[:path])}", :post, params, @options)
end

#move(params = {}) ⇒ Object

Move file/folder

Parameters:

destination (required) - string - Move destination path.


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/files.com/models/file_action.rb', line 32

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/#{Addressable::URI.encode_component(params[:path])}", :post, params, @options)
end