Class: GroupDocs::Storage::Folder

Inherits:
Api::Entity show all
Extended by:
Extensions::Lookup
Includes:
Api::Helpers::AccessMode
Defined in:
lib/groupdocs/storage/folder.rb

Constant Summary

Constants included from Api::Helpers::AccessMode

Api::Helpers::AccessMode::MODES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::Lookup

find!, find_all!

Methods inherited from Api::Entity

#initialize, #inspect, #to_hash

Constructor Details

This class inherits a constructor from GroupDocs::Api::Entity

Instance Attribute Details

#accessSymbol

Converts access mode to human-readable format.

Returns:

  • (Symbol)


93
94
95
# File 'lib/groupdocs/storage/folder.rb', line 93

def access
  @access
end

#created_onTime

Converts timestamp which is return by API server to Time object.

Returns:

  • (Time)


79
80
81
# File 'lib/groupdocs/storage/folder.rb', line 79

def created_on
  @created_on
end

#file_countObject



77
78
79
# File 'lib/groupdocs/storage/folder.rb', line 77

def file_count
  @file_count
end

#folder_countObject



75
76
77
# File 'lib/groupdocs/storage/folder.rb', line 75

def folder_count
  @folder_count
end

#idObject



71
72
73
# File 'lib/groupdocs/storage/folder.rb', line 71

def id
  @id
end

#modified_onTime

Converts timestamp which is return by API server to Time object.

Returns:

  • (Time)


81
82
83
# File 'lib/groupdocs/storage/folder.rb', line 81

def modified_on
  @modified_on
end

#nameObject



85
86
87
# File 'lib/groupdocs/storage/folder.rb', line 85

def name
  @name
end

#pathObject



87
88
89
# File 'lib/groupdocs/storage/folder.rb', line 87

def path
  @path
end

#sizeObject



73
74
75
# File 'lib/groupdocs/storage/folder.rb', line 73

def size
  @size
end

#typeObject



91
92
93
# File 'lib/groupdocs/storage/folder.rb', line 91

def type
  @type
end

#urlObject



83
84
85
# File 'lib/groupdocs/storage/folder.rb', line 83

def url
  @url
end

#versionObject



89
90
91
# File 'lib/groupdocs/storage/folder.rb', line 89

def version
  @version
end

Class Method Details

.all!(path = '/', access = {}) ⇒ Array<GroupDocs::Storage::Folder>

Returns an array of all folders on server starting with given path.

Parameters:

  • path (String) (defaults to: '/')

    Starting path to look for folders

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/groupdocs/storage/folder.rb', line 38

def self.all!(path = '/', access = {})
  folders = Array.new
  folder = GroupDocs::Storage::Folder.new(path: path)
  folder.list!({}, access).each do |entity|
    if entity.is_a?(GroupDocs::Storage::Folder)
      folders << entity
      folders += all!("#{path}/#{entity.name}", access)
    end
  end

  folders
end

.create!(path, access = {}) ⇒ GroupDocs::Storage::Folder

Creates folder on server.

Parameters:

  • path (String)

    Path of folder to create starting with “/”

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/groupdocs/storage/folder.rb', line 17

def self.create!(path, access = {})
  Api::Helpers::Path.verify_starts_with_root(path)

  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/storage/{{client_id}}/paths#{path}"
  end.execute!

  Storage::Folder.new(json)
end

.list!(path = '/', options = {}, access = {}) ⇒ Array<GroupDocs::Storage::Folder, GroupDocs::Storage::File>

Returns a list of all directories and files in the path.

Parameters:

  • path (String) (defaults to: '/')

    Path of directory to list starting from root (‘/’)

  • options (Hash) (defaults to: {})

    Hash of options

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :page (Integer)

    Page to start with

  • :count (Integer)

    How many items to list

  • :order_by (String)

    Field name to sort by

  • :order_asc (Boolean)

    Set to true to return in ascending order

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



65
66
67
68
# File 'lib/groupdocs/storage/folder.rb', line 65

def self.list!(path = '/', options = {}, access = {})
  Api::Helpers::Path.verify_starts_with_root(path)
  new(path: path).list!(options, access)
end

Instance Method Details

#copy!(path, access = {}) ⇒ String

Copies folder contents to a destination path.

Parameters:

  • path (String)

    Path of directory to copy to starting from root (‘/’)

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (String)

    Copied to folder path



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/groupdocs/storage/folder.rb', line 166

def copy!(path, access = {})
  Api::Helpers::Path.verify_starts_with_root(path)

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:headers] = { :'Groupdocs-Copy' => name }
    request[:path] = "/storage/{{client_id}}/folders#{path}"
  end.execute!

  path
end

#create!(access = {}) ⇒ Object

Creates folder on server.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


222
223
224
# File 'lib/groupdocs/storage/folder.rb', line 222

def create!(access = {})
  self.class.create!("/#{name}", access)
end

#delete!(access = {}) ⇒ Object

Deletes folder from server.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


233
234
235
236
237
238
239
# File 'lib/groupdocs/storage/folder.rb', line 233

def delete!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/storage/{{client_id}}/folders/#{name}"
  end.execute!
end

#list!(options = {}, access = {}) ⇒ Array<GroupDocs::Storage::Folder, GroupDocs::Storage::File>

Returns an array of files and folders.

Parameters:

  • options (Hash) (defaults to: {})

    Hash of options

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :page (Integer)

    Page to start with

  • :count (Integer)

    How many items to list

  • :order_by (String)

    Field name to sort by

  • :order_asc (Boolean)

    Set to true to return in ascending order

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/groupdocs/storage/folder.rb', line 192

def list!(options = {}, access = {})
  options[:order_by].capitalize! if options[:order_by]

  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/storage/{{client_id}}/folders#{path}/#{name}"
  end
  api.add_params(options)
  json = api.execute!

  folders = json[:folders].map do |folder|
    folder.merge!(path: path)
    Storage::Folder.new(folder)
  end
  files = json[:files].map do |file|
    file.merge!(path: path)
    Storage::File.new(file)
  end

  folders + files
end

#move!(path, access = {}) ⇒ String

Moves folder contents to given path.

Parameters:

  • path (String)

    Destination to move contents to

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (String)

    Moved to folder path



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/groupdocs/storage/folder.rb', line 131

def move!(path, access = {})
  Api::Helpers::Path.verify_starts_with_root(path)

  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:headers] = { :'Groupdocs-Move' => name }
    request[:path] = "/storage/{{client_id}}/folders#{path}"
  end.execute!

  path
end

#rename!(name, access = {}) ⇒ String

Renames folder to new one.

Parameters:

  • name (String)

    New name

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (String)

    New name



153
154
155
# File 'lib/groupdocs/storage/folder.rb', line 153

def rename!(name, access = {})
  move!("/#{name}", access).sub(/^\//, '')
end

#sharers!(access = {}) ⇒ Array<GroupDocs::User>

Returns an array of users a folder is shared with.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/groupdocs/storage/folder.rb', line 249

def sharers!(access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
  end.execute!

  json[:shared_users].map do |user|
    User.new(user)
  end
end

#sharers_clear!(access = {}) ⇒ Object

Clears sharers list.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • nil



297
298
299
300
301
302
303
# File 'lib/groupdocs/storage/folder.rb', line 297

def sharers_clear!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
  end.execute![:shared_users]
end

#sharers_set!(emails, access = {}) ⇒ Array<GroupDocs::User>

Sets folder sharers to given emails.

If empty array or nil passed, clears sharers.

Parameters:

  • emails (Array)

    List of email addresses to share with

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/groupdocs/storage/folder.rb', line 272

def sharers_set!(emails, access = {})
  if emails.nil? || emails.empty?
    sharers_clear!(access)
  else
    json = Api::Request.new do |request|
      request[:access] = access
      request[:method] = :PUT
      request[:path] = "/doc/{{client_id}}/folders/#{id}/sharers"
      request[:request_body] = emails
    end.execute!

    json[:shared_users].map do |user|
      User.new(user)
    end
  end
end