nextcloud 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ module Nextcloud
2
+ class OcsApi < Api
3
+ # Initiates User class
4
+ #
5
+ # @param userid [Ingteger,nil] Nextcloud user userid
6
+ # @return [Object] User instance
7
+ def user(userid = nil)
8
+ Ocs::User.new(self, userid)
9
+ end
10
+
11
+ # Initiates Group class
12
+ #
13
+ # @param groupid [Ingteger,nil] Nextcloud group groupid
14
+ # @return [Object] Group instance
15
+ def group(groupid = nil)
16
+ Ocs::Group.new(self, groupid)
17
+ end
18
+
19
+ # Initiates App class
20
+ #
21
+ # @param appid [Ingteger,nil] Nextcloud app appid
22
+ # @return [Object] Application instance
23
+ def app(appid = nil)
24
+ Ocs::App.new(self, appid)
25
+ end
26
+
27
+ # Initiates File Sharing class
28
+ #
29
+ # @return [Object] File Sharing instance
30
+ def file_sharing
31
+ Ocs::FileSharingApi.new(url: @url, username: @username, password: @password)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Nextcloud
2
+ module Version
3
+ VERSION = "1.3.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,174 @@
1
+ require "net-http-report"
2
+
3
+ module Nextcloud
4
+ module Webdav
5
+ # WebDAV class for communicating with File/directory mgmt. service
6
+ #
7
+ # @!attribute [rw] directory
8
+ # @return [Array] Used to store model instances when querying with find or favorites
9
+ class Directory < WebdavApi
10
+ include Helpers
11
+ include Properties
12
+
13
+ attr_accessor :directory
14
+
15
+ # Class initializer
16
+ # Can be initialized with WebdavApi's directory method or with Nextcloud::Webdav::Directory.new(...credentials...)
17
+ #
18
+ # @param args [Object,Hash] Can be instance of Api or credentials list (url, username, password)
19
+ def initialize(args)
20
+ if args.class == Nextcloud::WebdavApi
21
+ @api = args
22
+ else
23
+ super
24
+ @api = self
25
+ end
26
+
27
+ @path = "/files/#{@api.username}"
28
+ end
29
+
30
+ # Query a file, find contents of directory (including information about directory)
31
+ #
32
+ # @param path [String] Path of file or directory to search in
33
+ # @return [Object,Hash] Hash of error or instance of Directory model class
34
+ def find(path = "/")
35
+ response = @api.request(:propfind, "#{@path}/#{path}", nil, RESOURCE)
36
+ (has_dav_errors(response)) ? has_dav_errors(response) : directory(response)
37
+ end
38
+
39
+ # Create a directory
40
+ #
41
+ # @param path [String] Path of new directory relative to base
42
+ # @return [Hash] Returns status
43
+ def create(path)
44
+ response = @api.request(:mkcol, "#{@path}/#{path}")
45
+ parse_dav_response(response)
46
+ end
47
+
48
+ # Create a directory
49
+ #
50
+ # @param path [String] Path of new directory relative to base
51
+ # @return [Hash] Returns status
52
+ def destroy(path)
53
+ response = @api.request(:delete, "#{@path}/#{path}")
54
+ parse_dav_response(response)
55
+ end
56
+
57
+ # Download a file
58
+ #
59
+ # @param path [String] Path of file to download
60
+ # @return [String] Returns file contents
61
+ def download(path)
62
+ @api.request(:get, "#{@path}/#{path}", nil, nil, nil, nil, true)
63
+ end
64
+
65
+ # Upload a file
66
+ #
67
+ # @param path [String] Path of new upload
68
+ # @return contents [Hash] Returns status
69
+ def upload(path, contents)
70
+ response = @api.request(:put, "#{@path}/#{path}", nil, contents)
71
+ parse_dav_response(response)
72
+ end
73
+
74
+ # Move a file
75
+ #
76
+ # @param source [String] Source path relative to base
77
+ # @param destination [String] Destination path relative to base
78
+ # @return [Hash] Returns status
79
+ def move(source, destination)
80
+ response = @api.request(:move, "#{@path}/#{source}", nil, nil, nil,
81
+ destination = "#{@api.url}#{@path}/#{destination}")
82
+ parse_dav_response(response)
83
+ end
84
+
85
+ # Copy a file
86
+ #
87
+ # @param source [String] Source path relative to base
88
+ # @param destination [String] Destination path relative to base
89
+ # @return [Hash] Returns status
90
+ def copy(source, destination)
91
+ response = @api.request(:copy, "#{@path}/#{source}", nil, nil, nil,
92
+ destination = "#{@api.url}#{@path}/#{destination}")
93
+ parse_dav_response(response)
94
+ end
95
+
96
+ # Make file/directory a favorite
97
+ #
98
+ # @param path [String] Path of file/directory (relative)
99
+ # @return [Hash] Returns status
100
+ def favorite(path)
101
+ response = @api.request(:proppatch, "#{@path}/#{path}", nil, MAKE_FAVORITE)
102
+ parse_dav_response(response)
103
+ end
104
+
105
+ # Unfavorite a file/directory
106
+ #
107
+ # @param path [String] Path of file/directory (relative)
108
+ # @return [Hash] Returns status
109
+ def unfavorite(path)
110
+ response = @api.request(:proppatch, "#{@path}/#{path}", nil, UNFAVORITE)
111
+ parse_dav_response(response)
112
+ end
113
+
114
+ # Shows favorite files/directories in given location
115
+ #
116
+ # @param path [String] Location to list favorites from
117
+ # @return [Hash] Hash of error or array of Directory model classes
118
+ def favorites(path = "/")
119
+ response = @api.request(:REPORT, "#{@path}/#{path}", nil, FAVORITE)
120
+ (has_dav_errors(response)) ? has_dav_errors(response) : directory(response, false)
121
+ end
122
+
123
+ private
124
+
125
+ # Parses as turns file/directory response to model object
126
+ #
127
+ # @param response [Object] Nokogiri::XML::Document
128
+ # @param skip_first [Boolean] Skip or not first element
129
+ # @return [Object,Array] Returns Object if first element not skipped, array otherwise
130
+ def directory(response, skip_first = true)
131
+ response = doc_to_hash(response).try(:[], "multistatus").try(:[], "response")
132
+ response = [response] if response.is_a? Hash
133
+
134
+ return [] if response.nil?
135
+
136
+ response.each_with_index do |h, index|
137
+
138
+ prop = h["propstat"].try(:[], 0).try(:[], "prop") || h["propstat"]["prop"]
139
+
140
+ params = {
141
+ href: h["href"],
142
+ lastmodified: prop["getlastmodified"],
143
+ tag: prop["getetag"],
144
+ resourcetype: prop["resourcetype"].nil? ? "file" : "collection",
145
+ id: prop["id"],
146
+ fileid: prop["fileid"],
147
+ permissions: prop["permissions"],
148
+ size: prop["size"],
149
+ has_preview: prop["has_preview"] == "false" ? false : true,
150
+ favorite: prop["favorite"] == "0" ? false : true,
151
+ comments_href: prop["comments_href"],
152
+ comments_count: prop["comments_count"],
153
+ comments_unread: prop["comments_unread"],
154
+ owner_id: prop["owner_id"],
155
+ owner_display_name: prop["owner_display_name"],
156
+ share_types: prop["share_types"]
157
+ }
158
+
159
+ if skip_first
160
+ if index == 0
161
+ @directory = Models::Directory.new(params)
162
+ else
163
+ @directory.add(params)
164
+ end
165
+ else
166
+ @directory = [] if @directory.nil?
167
+ @directory << Models::Directory.new(params.merge(skip_contents: true))
168
+ end
169
+ end
170
+ @directory
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,21 @@
1
+ module Nextcloud
2
+ class WebdavApi < Api
3
+ # Remote end of WebDAV API
4
+ DAV_URL = "remote.php/dav".freeze
5
+
6
+ # Initializes a WebDAV API
7
+ #
8
+ # @params args [Hash] Hash with url, username and password
9
+ def initialize(args)
10
+ super
11
+ @url = URI(@url.scheme + "://" + @url.host + "/" + DAV_URL)
12
+ end
13
+
14
+ # Initiates WebDAV Directory class
15
+ #
16
+ # @return [Object] WebDAV Directory instance
17
+ def directory
18
+ Webdav::Directory.new(self)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "nextcloud/version/nextcloud"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nextcloud"
7
+ spec.version = Nextcloud::Version::VERSION
8
+ spec.authors = ["Dachi Natsvlishvili"]
9
+ spec.email = ["dachinat@gmail.com"]
10
+ spec.summary = "Nextcloud API in Ruby"
11
+ spec.description = "Nextcloud OCS and WebDAV API endpoints wrapper in Ruby for user provisioning, file and directory
12
+ management, sharing (including Federated Cloud Sharing), group and application operations."
13
+ spec.homepage = "https://github.com/dachinat/nextcloud"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ spec.metadata["yard.run"] = "yri"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency "activesupport", "~> 5.1"
35
+ spec.add_runtime_dependency "json", "~> 2.1"
36
+ spec.add_runtime_dependency "nokogiri", "~> 1.8"
37
+ spec.add_runtime_dependency "net-http-report", "~> 0.1"
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "rubocop", "~> 0.51"
43
+ spec.add_development_dependency "vcr", "~> 3.0"
44
+ spec.add_development_dependency "webmock", "~> 3.1"
45
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nextcloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Dachi Natsvlishvili
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-http-report
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.51'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.51'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.1'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.1'
153
+ description: |-
154
+ Nextcloud OCS and WebDAV API endpoints wrapper in Ruby for user provisioning, file and directory
155
+ management, sharing (including Federated Cloud Sharing), group and application operations.
156
+ email:
157
+ - dachinat@gmail.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - ".gitignore"
163
+ - ".rubocop.yml"
164
+ - ".travis.yml"
165
+ - CODE_OF_CONDUCT.md
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bin/console
172
+ - bin/setup
173
+ - lib/nextcloud.rb
174
+ - lib/nextcloud/api.rb
175
+ - lib/nextcloud/errors/nextcloud.rb
176
+ - lib/nextcloud/helpers/nextcloud.rb
177
+ - lib/nextcloud/helpers/properties.rb
178
+ - lib/nextcloud/models/directory.rb
179
+ - lib/nextcloud/models/user.rb
180
+ - lib/nextcloud/ocs/app.rb
181
+ - lib/nextcloud/ocs/file_sharing_api.rb
182
+ - lib/nextcloud/ocs/group.rb
183
+ - lib/nextcloud/ocs/user.rb
184
+ - lib/nextcloud/ocs_api.rb
185
+ - lib/nextcloud/version/nextcloud.rb
186
+ - lib/nextcloud/webdav/directory.rb
187
+ - lib/nextcloud/webdav_api.rb
188
+ - nextcloud.gemspec
189
+ homepage: https://github.com/dachinat/nextcloud
190
+ licenses:
191
+ - MIT
192
+ metadata:
193
+ allowed_push_host: https://rubygems.org
194
+ yard.run: yri
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.6.13
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Nextcloud API in Ruby
215
+ test_files: []