main
David Vargas 2022-12-01 14:22:21 +00:00
parent 3f512bf9cf
commit 69d79262d9
9 changed files with 133 additions and 0 deletions

3
bin/nextcloud/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.env
private*
*.lock

5
bin/nextcloud/01-dotenv.rb Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require "dotenv"
settings = Dotenv.load
puts settings

17
bin/nextcloud/02-nextcloud.rb Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require "debug"
require "dotenv"
require "nextcloud"
settings = Dotenv.load
nextcloud = Nextcloud.new(
url: settings["URL"],
username: settings["USERNAME"],
password: settings["PASSWORD"]
)
ocs = nextcloud.ocs
puts "* ocs.webdav.directory: #{ocs.webdav.directory}"
webdav = nextcloud.webdav
puts "* webdav.directory(@path): #{webdav.directory.instance_variable_get(:@path)}"

22
bin/nextcloud/03-user-info.rb Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require "debug"
require "dotenv"
require "nextcloud"
settings = Dotenv.load
nextcloud = Nextcloud.new(
url: settings["URL"],
username: settings["USERNAME"],
password: settings["PASSWORD"]
)
ocs = nextcloud.ocs
user = ocs.user.find("dvarrui")
tags = %i(enabled id quota email displayname phone address website twitter groups language meta)
tags.each do |tag|
label = "user.#{tag}"
puts "#{label.rjust(16)} = #{user.send(tag)}"
end

22
bin/nextcloud/04-user-info.rb Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require_relative "lib"
nextcloud = get_nextcloud_object()
ocs = nextcloud.ocs
user = ocs.user.find("dvarrui")
tags = %i(enabled id quota email displayname phone address website twitter groups language meta)
puts "User:"
tags.each do |tag|
value = user.send(tag)
puts "#{tag.to_s.rjust(12)} = #{value.to_s}"
end
puts "\nAdmin:"
groups = ocs.group.all
puts " groups : #{groups}"
# => ["admin", "group1", "group2"]
meta = groups.meta
puts " meta : #{meta}"
# => {"status"=>"ok", "statuscode"=>"200", "message"=>"OK"}

18
bin/nextcloud/05-filesharing.rb Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require_relative "lib"
fs = get_filesharing_object()
puts "Retrieve all shares of an (authenticated) user"
all_shares = fs.all
meta = all_shares.meta
puts all_shares
puts meta
puts "Retrieve a single share"
share = fs.find(11)
meta = share.meta
puts share
puts meta

18
bin/nextcloud/06-webdav.rb Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require_relative "lib"
nextcloud = get_nextcloud_object()
webdav = nextcloud.webdav
ocs = nextcloud.ocs
puts "* ocs.webdav.directory: #{ocs.webdav.directory}"
webdav = nextcloud.webdav
path = webdav.directory.instance_variable_get(:@path)
puts "* webdav.directory(@path): #{path}"
dir = "files_from_git"
result = webdav.directory.create(dir)
puts result
dir = webdav.directory.find
puts dir.contents

6
bin/nextcloud/Gemfile Normal file
View File

@ -0,0 +1,6 @@
# frozen_string_literal: true
source "https://rubygems.org"
gem "dotenv"
gem "nextcloud"

22
bin/nextcloud/lib.rb Normal file
View File

@ -0,0 +1,22 @@
require "dotenv"
require "nextcloud"
def get_nextcloud_object
settings = Dotenv.load
nextcloud = Nextcloud.new(
url: settings["URL"],
username: settings["USERNAME"],
password: settings["PASSWORD"]
)
return nextcloud
end
def get_filesharing_object
settings = Dotenv.load
fs = Nextcloud::Ocs::FileSharingApi.new(
url: settings["URL"],
username: settings["USERNAME"],
password: settings["PASSWORD"]
)
return fs
end