ocman 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ocman/configuration.rb +5 -0
- data/lib/ocman/dav.rb +61 -0
- data/lib/ocman/folder.rb +23 -0
- data/lib/ocman/item.rb +15 -0
- data/lib/ocman/share.rb +74 -0
- data/lib/ocman/version.rb +3 -0
- data/lib/ocman.rb +51 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43e570f1e9987fce2ad6847a2b71fa7f5ad6cf45
|
4
|
+
data.tar.gz: aa16bd2e8bad86cc4495e04d8099ce9a99022ec0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9cf9dabc7ab4e8976420890202b3e5d4fe8c405f84538b41c83344c4d31728b838d037999b338726066f6b61177dedc850701d6ae15292c1c4b62da1cd2d65b
|
7
|
+
data.tar.gz: 145d7588e48d7e66a55b8d220b17cdd41a72a5ba73a5d6427f45e781630c1954cd1eca8fe29c9b92c18ca37e40a5eda0a34c5fb2aea4ed5285f8848c9c4f3a58
|
data/lib/ocman/dav.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'net/dav'
|
2
|
+
|
3
|
+
module Ocman
|
4
|
+
class Dav
|
5
|
+
attr_writer :connection
|
6
|
+
|
7
|
+
def mkdir(path)
|
8
|
+
connection.mkdir( uri(path) )
|
9
|
+
end
|
10
|
+
|
11
|
+
def ls(path)
|
12
|
+
connection.find( uri(path) ) do |item|
|
13
|
+
yield(item)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def put(file_path, path, options={})
|
18
|
+
filename = options[:filename] || File.basename(file_path)
|
19
|
+
File.open(file_path, 'r') do |stream|
|
20
|
+
connection.put( uri(path, filename) , stream, File.size(file_path))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(path)
|
25
|
+
connection.delete( uri(path) )
|
26
|
+
end
|
27
|
+
|
28
|
+
def move(source_path, destination_path)
|
29
|
+
connection.move( uri(source_path), uri(destination_path) )
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.base_uri
|
33
|
+
Ocman.configuration.dav_base_uri || '/remote.php/webdav/'
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.url(path)
|
37
|
+
Ocman.configuration.base_url + (Ocman::Dav.base_uri + path).gsub(/\/+/, '/')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def item_hash(item)
|
43
|
+
{
|
44
|
+
path: item.uri.path.gsub(Ocman::Dav.base_uri, '/'),
|
45
|
+
type: item.type,
|
46
|
+
size: item.size
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def uri(path, filename=nil)
|
51
|
+
[Ocman::Dav.base_uri, path, filename].compact.join('/').gsub(/\/+/, '/')
|
52
|
+
end
|
53
|
+
|
54
|
+
def connection
|
55
|
+
dav = Net::DAV.new(Ocman.configuration.base_url)
|
56
|
+
dav.verify_server = true
|
57
|
+
dav.credentials(Ocman.configuration.user_name, Ocman.configuration.password)
|
58
|
+
dav
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/ocman/folder.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Ocman
|
4
|
+
class Folder
|
5
|
+
def self.create(path)
|
6
|
+
Ocman::Dav.new.mkdir(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.list(path)
|
10
|
+
accu = []
|
11
|
+
|
12
|
+
Ocman::Dav.new.ls(path) do |item|
|
13
|
+
accu << Hashie::Mash.new({
|
14
|
+
path: item.uri.to_s.gsub(Ocman::Dav.url(path), '').gsub('/', ''),
|
15
|
+
type: item.type.to_s,
|
16
|
+
size: item.size
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
accu
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ocman/item.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Ocman
|
2
|
+
class Item
|
3
|
+
def self.create(file, path, options={})
|
4
|
+
Ocman::Dav.new.put(file, path, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.delete(path)
|
8
|
+
Ocman::Dav.new.delete(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.move(source_path, destination_path)
|
12
|
+
Ocman::Dav.new.move(source_path, destination_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/ocman/share.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Ocman
|
4
|
+
class Share
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def share(user)
|
10
|
+
request_parameter = {
|
11
|
+
payload: {
|
12
|
+
path: @path,
|
13
|
+
shareWith: user,
|
14
|
+
shareType: '0',
|
15
|
+
permissions: '31',
|
16
|
+
},
|
17
|
+
}.merge connection_params('post')
|
18
|
+
|
19
|
+
request = RestClient::Request.new( request_parameter )
|
20
|
+
parse_result( request.execute )
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_share(user)
|
24
|
+
share = find_share(user)
|
25
|
+
request_parameter = connection_params('delete', share.id)
|
26
|
+
request = RestClient::Request.new( request_parameter )
|
27
|
+
parse_result( request.execute )
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_share(user)
|
31
|
+
result = nil
|
32
|
+
shares = share_info.data
|
33
|
+
shares = [shares] unless shares.kind_of?(Array)
|
34
|
+
shares.each do |share|
|
35
|
+
if share.share_with == user
|
36
|
+
result = share
|
37
|
+
end
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def share_info
|
43
|
+
request_parameter = {
|
44
|
+
headers: {
|
45
|
+
params: {
|
46
|
+
path: @path
|
47
|
+
},
|
48
|
+
},
|
49
|
+
}.merge connection_params('get')
|
50
|
+
|
51
|
+
request = RestClient::Request.new( request_parameter )
|
52
|
+
parse_result( request.execute )
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def parse_result(response)
|
57
|
+
response = Hash.from_xml(response)['ocs']
|
58
|
+
result = Hashie::Mash.new
|
59
|
+
result.meta = response['meta']
|
60
|
+
result.data = (response['data']['element'] rescue nil)
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
def connection_params(http_method, id=nil)
|
65
|
+
url = Ocman.configuration.base_url + "/ocs/v1.php/apps/files_sharing/api/v1/shares" + "#{'/' + id if id}"
|
66
|
+
{
|
67
|
+
url: url,
|
68
|
+
method: http_method,
|
69
|
+
user: Ocman.configuration.user_name,
|
70
|
+
password: Ocman.configuration.password,
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/ocman.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'ocman/configuration'
|
2
|
+
require 'ocman/dav'
|
3
|
+
require 'ocman/item'
|
4
|
+
require 'ocman/folder'
|
5
|
+
require 'ocman/version'
|
6
|
+
require 'ocman/share'
|
7
|
+
|
8
|
+
module Ocman
|
9
|
+
class << self
|
10
|
+
attr_writer :configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Ocman::Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
### share
|
22
|
+
def self.share(path, user)
|
23
|
+
Ocman::Share.new(path).share(user)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.delete_share(path, user)
|
27
|
+
Ocman::Share.new(path).delete_share(user)
|
28
|
+
end
|
29
|
+
|
30
|
+
### folder
|
31
|
+
def self.list(path)
|
32
|
+
Ocman::Folder.list(path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.create_folder(path)
|
36
|
+
Ocman::Folder.create(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
### files
|
40
|
+
def self.put(file_path, path, options={})
|
41
|
+
Ocman::Item.create(file_path, path, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.delete(path)
|
45
|
+
Ocman::Item.delete(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.move(source_path, destination_path)
|
49
|
+
Ocman::Item.move(source_path, destination_path)
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ocman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Waldemar Gribele
|
8
|
+
- Stefan Rohde
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net_dav
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.5.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.5.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: hashie
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.4'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rest-client
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.8'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.8'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.4'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.4'
|
70
|
+
description: Ruby gem for file managment and sharing in owncloud
|
71
|
+
email: laboratories@toptranslation.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/ocman.rb
|
77
|
+
- lib/ocman/configuration.rb
|
78
|
+
- lib/ocman/dav.rb
|
79
|
+
- lib/ocman/folder.rb
|
80
|
+
- lib/ocman/item.rb
|
81
|
+
- lib/ocman/share.rb
|
82
|
+
- lib/ocman/version.rb
|
83
|
+
homepage: https://developer.toptranslation.com
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Ocman - Manages files and shares in owncloud
|
107
|
+
test_files: []
|