Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dwimcore's additions plus full comment and tags support #22

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
PATH
remote: .
specs:
nextcloud (1.3.2)
activesupport (>= 5.1, <= 6.1)
nextcloud (1.3.2.1)
activesupport
json (~> 2.1)
net-http-report (~> 0.1)
nokogiri (~> 1.8)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.0)
activesupport (7.0.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.3.0)
concurrent-ruby (1.1.8)
coveralls (0.8.21)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
concurrent-ruby (1.1.9)
coveralls (0.8.23)
json (>= 1.8, < 3)
simplecov (~> 0.14.1)
simplecov (~> 0.16.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.4)
thor (>= 0.19.4, < 2.0)
tins (~> 1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
hashdiff (0.3.7)
i18n (1.8.10)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
docile (1.4.0)
hashdiff (1.0.1)
i18n (1.9.1)
concurrent-ruby (~> 1.0)
json (2.5.1)
mini_portile2 (2.5.0)
minitest (5.14.4)
json (2.6.1)
minitest (5.15.0)
net-http-report (0.2.0)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
nokogiri (1.13.1-x86_64-linux)
racc (~> 1.4)
parallel (1.12.0)
parser (2.4.0.2)
ast (~> 2.3)
powerpack (0.1.1)
public_suffix (3.0.1)
racc (1.5.2)
rainbow (2.2.2)
rake
rake (13.0.1)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
public_suffix (4.0.6)
racc (1.6.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.0)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.51.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (0.93.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
simplecov (0.14.1)
docile (~> 1.1.0)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
term-ansicolor (1.6.0)
sync (0.5.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
thor (0.19.4)
tins (1.15.1)
thor (1.2.1)
tins (1.31.0)
sync
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.3.0)
unicode-display_width (1.8.0)
vcr (3.0.3)
webmock (3.1.1)
addressable (>= 2.3.6)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff
zeitwerk (2.4.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
bundler (~> 1.16)
coveralls
nextcloud!
rake (~> 13.0)
Expand All @@ -104,4 +104,4 @@ DEPENDENCIES
webmock (~> 3.1)

BUNDLED WITH
1.16.0
2.3.6
122 changes: 98 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
[![Gem](https://img.shields.io/gem/v/nextcloud.svg?style=flat-square)](https://rubygems.org/gems/nextcloud) [![Travis](https://img.shields.io/travis/dachinat/nextcloud.svg?style=flat-square)](https://travis-ci.org/dachinat/nextcloud) [![Coveralls github](https://img.shields.io/coveralls/github/dachinat/nextcloud.svg?style=flat-square)](https://coveralls.io/github/dachinat/nextcloud) [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square)](http://rubydoc.info/github/dachinat/nextcloud/master)

# Nextcloud Ruby API

## Fork info

Forked from https://github.com/Dwimcore/nextcloud

Added full file commenting and tagging support. For the latter, used the preliminary implementation as a guide from https://github.com/rahul100885/nextcloud

Added content_type param to `Api#requset` method, so that it can be used directly for APIs that require e.g. JSON request body.

## Purpose

Wrapper gem for Ruby used for communicating with Nextcloud OCS and WebDAV API endpoints.

This gem provides features for User provisioning, Group and App management, control of Shares and Federated Cloud
Expand Down Expand Up @@ -37,7 +45,7 @@ ocs = Nextcloud.ocs(
)
```

An URL has to be a base of your Nextcloud instance. For API requests, it will be parsed to
An URL has to be a base of your Nextcloud instance. For API requests, it will be parsed to
`https://cloud.yourdomain.com/ocs/v2.php/cloud/` or similar.

Once `ocs` is available you can use following methods to initiate specific classes:
Expand Down Expand Up @@ -102,15 +110,15 @@ directory = Nextcloud::Webdav::Directory.new(url: "…", username: "…", passwo
```

> When initializing this way, to work with certain objects some circumstances might force you use `set` method.
> For example if you wish to list members of group admin, using first way you could simply write
> For example if you wish to list members of group admin, using first way you could simply write
`ocs.group('admin').members`, in this case you will need to use `group.set('admin').members`. There is another way to
set object of intereset by putting it into initialize arguments, like so
set object of intereset by putting it into initialize arguments, like so
`Nextcloud::Ocs::Group.new({…credentials}, groupid="admin")` it can be then reset with
`set`. Corresponding parameter names for other classes are `userid` and `appid`.

### *OCS Api usage*

These examples assume you have `Nextcloud.ocs` instance or relevant instance of
These examples assume you have `Nextcloud.ocs` instance or relevant instance of
`Nextcloud::Ocs::{CLASS_NAME}.new` stored in `ocs` variable.

### User actions
Expand All @@ -123,7 +131,7 @@ users = ocs.user.all

last_user = user.last
=> #<Nextcloud::Models::User:0x000001042a2ba0 @id="your_user_2">

response_meta = users.meta
{"status"=>"ok", "statuscode"=>"200", "message"=>"OK"}
```
Expand Down Expand Up @@ -168,8 +176,8 @@ Valid keys include:

* quota
* displayname
* phone
* address
* phone
* address
* website
* twitter
* password
Expand Down Expand Up @@ -214,7 +222,7 @@ meta = ocs.user.resend_welcome("user3").meta
```
groups = ocs.user("user1").groups
# => ["admin"]
meta = groups.meta
meta = groups.meta
# => {"status"=>"ok", "statuscode"=>"200", "message"=>"OK"}
```

Expand Down Expand Up @@ -281,7 +289,7 @@ user.set("user4").group("group1").demote
```
subadmin_groups = ocs.user("user4").subadmin_groups
# => ["group1"]
meta = subadmin_groups.meta
meta = subadmin_groups.meta
# => {"status"=>"ok", "statuscode"=>"200", "message"=>"OK"}
```

Expand Down Expand Up @@ -424,8 +432,8 @@ ocs_fs = Nextcloud::Ocs::FileSharingApi.new(
)
```

An URL has to be a base of your Nextcloud instance. For Sharing API requests, it will be parsed to
`https://cloud.yourdomain.com/ocs/v2.php/apps/files_sharing/api/v1/`
An URL has to be a base of your Nextcloud instance. For Sharing API requests, it will be parsed to
`https://cloud.yourdomain.com/ocs/v2.php/apps/files_sharing/api/v1/`

> You can also initialize with `Nextcloud.ocs(…credentials).file_sharing`

Expand All @@ -443,7 +451,7 @@ meta = all_shares.meta
```
share = ocs_fs.find(11)
# => {"id" => "22", "shareType" => "0", …}
meta = share.meta
meta = share.meta
# => {"status"=>"ok", "statuscode"=>"200", "message"=>"OK"}
```

Expand Down Expand Up @@ -604,7 +612,7 @@ array of results:

```
directory.contents
```
```

#### Query information about file

Expand Down Expand Up @@ -666,6 +674,81 @@ webdav.directory.unfavorite("some_file")
webdav.directory.favorites("/")
```

### Comments API

#### Add comment to file
First you'll need to acquire the required file's ID through the directory API, see above.
```
webdav.comments('files', fileid).add('some comment')
```
or, for short
```
webdav.file_comments(fileid).add('some comment')
```

#### List comments on file

```
webdav.file_comments(fileid).list
```
Will return an array of instances of Comment model with information about the comments. Of most interest
should be the following attributes:
- `id`
- `message`: the comment itself
- `actor_id`: the username of the commenter
- `actor_display_name`
- `creation_datetime`

#### Modify an existing comment

```
webdav.file_comments(fileid).modify(comment_id, 'the new comment message')
```

#### Remove a comment

```
webdav.file_comments(fileid).remove(comment_id)
```

### Tags API

#### List all system tags

```
webdav.tags.list
```
Will return an array of instances of Tag model with information about the tags, with these attributes:
- `id`
- `display_name`
- `user_visible`
- `user_assignable`

#### Create system tag

```
webdav.tags.create('name of the tag', user_visible, user_assignable)
```
where the last two params are true/false

#### Destroy a system tag

```
webdav.tags.destroy(tag_id)
```

#### Add a system tag to a file
First you'll need to acquire the required file's ID through the directory API, and the tag's ID. See above.
```
webdav.tags.file(fileid).add(tag_id)
```

#### Remove a system tag from a file

```
webdav.tags.file(fileid).remove(tag_id)
```

### Group Folder API

#### Initialize with authentication information
Expand Down Expand Up @@ -739,15 +822,6 @@ gf.set_quota(16, 1024*1024*1024*7)
```
gf.rename_folder(16, 'Extern')
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dachinat/nextcloud. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the Nextcloud gem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dachinat/nextcloud/blob/master/CODE_OF_CONDUCT.md).
6 changes: 6 additions & 0 deletions lib/nextcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@

require "nextcloud/webdav_api"
require "nextcloud/webdav/directory"
require "nextcloud/webdav/search"
require "nextcloud/webdav/tags"
require "nextcloud/webdav/tag_relations"
require "nextcloud/webdav/comments"

require "nextcloud/models/user"
require "nextcloud/models/directory"
require "nextcloud/models/tag"
require "nextcloud/models/comment"

# Namespace for Nextcloud OCS API communication
module Nextcloud
Expand Down
Loading