diff --git a/bin/nextcloud/.gitignore b/bin/nextcloud/.gitignore new file mode 100644 index 0000000..c0ee74f --- /dev/null +++ b/bin/nextcloud/.gitignore @@ -0,0 +1,3 @@ +.env +private* +*.lock diff --git a/bin/nextcloud/01-dotenv.rb b/bin/nextcloud/01-dotenv.rb new file mode 100755 index 0000000..5dce8bc --- /dev/null +++ b/bin/nextcloud/01-dotenv.rb @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "dotenv" + +settings = Dotenv.load +puts settings diff --git a/bin/nextcloud/02-nextcloud.rb b/bin/nextcloud/02-nextcloud.rb new file mode 100755 index 0000000..e53d0aa --- /dev/null +++ b/bin/nextcloud/02-nextcloud.rb @@ -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)}" diff --git a/bin/nextcloud/03-user-info.rb b/bin/nextcloud/03-user-info.rb new file mode 100755 index 0000000..3b47462 --- /dev/null +++ b/bin/nextcloud/03-user-info.rb @@ -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 diff --git a/bin/nextcloud/04-user-info.rb b/bin/nextcloud/04-user-info.rb new file mode 100755 index 0000000..28dfca0 --- /dev/null +++ b/bin/nextcloud/04-user-info.rb @@ -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"} diff --git a/bin/nextcloud/05-filesharing.rb b/bin/nextcloud/05-filesharing.rb new file mode 100755 index 0000000..a472ed9 --- /dev/null +++ b/bin/nextcloud/05-filesharing.rb @@ -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 diff --git a/bin/nextcloud/06-webdav.rb b/bin/nextcloud/06-webdav.rb new file mode 100755 index 0000000..0b3dc2d --- /dev/null +++ b/bin/nextcloud/06-webdav.rb @@ -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 diff --git a/bin/nextcloud/Gemfile b/bin/nextcloud/Gemfile new file mode 100644 index 0000000..b8faa6c --- /dev/null +++ b/bin/nextcloud/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "dotenv" +gem "nextcloud" diff --git a/bin/nextcloud/lib.rb b/bin/nextcloud/lib.rb new file mode 100644 index 0000000..09bf4dc --- /dev/null +++ b/bin/nextcloud/lib.rb @@ -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