class Netdocuments::Folder
Attributes
id[R]
name[R]
parent[R]
query[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/netdocuments/folder.rb, line 6 def initialize(opts = {}) validate_config! @id = URI::encode(opts[:id]) if opts[:id] @name = opts[:name] if opts[:name] @query = opts[:query] if opts[:query] @parent = opts[:parent] if opts[:parent] end
Public Instance Methods
ancestry()
click to toggle source
# File lib/netdocuments/folder.rb, line 77 def ancestry response = get(url: "/v1/Folder/#{@id}/ancestry",headers: headers) end
cabinet_id()
click to toggle source
# File lib/netdocuments/folder.rb, line 14 def cabinet_id Netdocuments.configuration.cabinet_id end
create()
click to toggle source
# File lib/netdocuments/folder.rb, line 18 def create post(url: '/v1/Folder', body: { name: @name, parent: @parent }, headers: headers) end
find_subfolders_and_update_nodes()
click to toggle source
udpating nodes via sidekiq worker
# File lib/netdocuments/folder.rb, line 88 def find_subfolders_and_update_nodes stats = {nodes_count: 0,folder_name: name} puts "---- Starting subfolders collection for - #{name} ---- " nodes = [] ids = [{id: @id, parent: "#{Netdocuments.configuration.cabinet_name}/#{name}"}] loop do r = ids.collect do |id| folder_extraction(id) end.flatten! nodes << r stats[:nodes_count] = stats[:nodes_count] + nodes.flatten.count nodes.flatten.each do |node| puts "---- Pushing: #{node.folder_path} in node queue ----" NodeWorker.perform_async(node.id,node.extension,node.folder_path) end nodes = [] folders = r.select {|i| i.extension == 'ndfld'} ids = folders.collect {|o| {id: o.id,parent: "#{o.parent}/#{o.name}"}} break if ids.count == 0 end stats end
folder_content()
click to toggle source
# File lib/netdocuments/folder.rb, line 32 def folder_content begin response = get(url: "/v1/Folder/#{id}", query: {'$select' => 'standardAttributes'}, headers: headers) response["ndList"]["standardList"].nil? ? [] : [response["ndList"]["standardList"]["ndProfile.DocumentStat"]].flatten rescue Exception => e #puts "********* #{id} ********* #{e.message}" #puts e.backtrace.join("\n") [] end end
folder_extraction(opts = {})
click to toggle source
# File lib/netdocuments/folder.rb, line 47 def folder_extraction(opts = {}) contents = Netdocuments::Folder.new(id: opts[:id]).folder_content.compact col = contents.collect do |folder| obj = Netdocuments::Node.new(name: folder['name'], id: folder['id'], extension: folder['extension'], parent: opts[:parent], folder_path: "#{opts[:parent]}/#{folder['name']}") obj end end
headers()
click to toggle source
# File lib/netdocuments/folder.rb, line 112 def headers {'Authorization' => "Bearer #{client.access_token.token}"} end
info()
click to toggle source
# File lib/netdocuments/folder.rb, line 27 def info get(url: "/v1/Folder/#{@id}/info", headers: headers) end
subfolders()
click to toggle source
# File lib/netdocuments/folder.rb, line 60 def subfolders Netdocuments.logger.info "Starting subfolders collection for: #{name}" nodes = [] ids = [{id: @id, parent: "#{Netdocuments.configuration.cabinet_name}/#{name}"}] loop do r = ids.collect do |id| folder_extraction(id) end.flatten! nodes << r folders = r.select {|i| i.extension == 'ndfld'} ids = folders.collect {|o| {id: o.id,parent: "#{o.parent}/#{o.name}"}} break if ids.count == 0 end nodes.flatten! end
update_info(opts = {})
click to toggle source
# File lib/netdocuments/folder.rb, line 81 def update_info(opts = {}) response = put(url: "/v1/Folder/#{@id}/info", query: opts[:query], headers: headers.merge({'Content-Type' => 'application/json'})) end