brick_ftp 0.8.4 → 1.0.0.beta
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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -5
- data/.rubocop.yml +2 -1
- data/.yardopts +1 -0
- data/CHANGELOG.md +16 -12
- data/Gemfile +2 -0
- data/README.md +24 -43
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/brick_ftp.gemspec +10 -9
- data/exe/brick_ftp +1 -0
- data/lib/brick_ftp.rb +5 -78
- data/lib/brick_ftp/client.rb +35 -411
- data/lib/brick_ftp/core_ext.rb +8 -0
- data/lib/brick_ftp/core_ext/hash.rb +13 -0
- data/lib/brick_ftp/core_ext/hash/compact.rb +13 -0
- data/lib/brick_ftp/core_ext/struct.rb +13 -0
- data/lib/brick_ftp/core_ext/struct/new.rb +16 -0
- data/lib/brick_ftp/restful_api.rb +82 -0
- data/lib/brick_ftp/restful_api/add_group_member.rb +44 -0
- data/lib/brick_ftp/restful_api/client.rb +179 -0
- data/lib/brick_ftp/restful_api/command.rb +21 -0
- data/lib/brick_ftp/restful_api/complete_upload.rb +46 -0
- data/lib/brick_ftp/restful_api/continue_upload.rb +50 -0
- data/lib/brick_ftp/restful_api/copy_folder.rb +46 -0
- data/lib/brick_ftp/restful_api/count_folder_contents.rb +36 -0
- data/lib/brick_ftp/restful_api/count_users.rb +22 -0
- data/lib/brick_ftp/restful_api/create_api_key.rb +46 -0
- data/lib/brick_ftp/restful_api/create_behavior.rb +42 -0
- data/lib/brick_ftp/restful_api/create_bundle.rb +40 -0
- data/lib/brick_ftp/restful_api/create_folder.rb +25 -0
- data/lib/brick_ftp/restful_api/create_group.rb +42 -0
- data/lib/brick_ftp/restful_api/create_notification.rb +44 -0
- data/lib/brick_ftp/restful_api/create_permission.rb +48 -0
- data/lib/brick_ftp/restful_api/create_public_key.rb +42 -0
- data/lib/brick_ftp/restful_api/create_user.rb +90 -0
- data/lib/brick_ftp/restful_api/create_user_in_group.rb +60 -0
- data/lib/brick_ftp/restful_api/delete_api_key.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_behavior.rb +22 -0
- data/lib/brick_ftp/restful_api/delete_bundle.rb +22 -0
- data/lib/brick_ftp/restful_api/delete_folder.rb +32 -0
- data/lib/brick_ftp/restful_api/delete_group.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_notification.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_permission.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_public_key.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_user.rb +25 -0
- data/lib/brick_ftp/restful_api/download_file.rb +44 -0
- data/lib/brick_ftp/restful_api/get_api_key.rb +25 -0
- data/lib/brick_ftp/restful_api/get_behavior.rb +25 -0
- data/lib/brick_ftp/restful_api/get_bundle.rb +25 -0
- data/lib/brick_ftp/restful_api/get_bundle_zip.rb +48 -0
- data/lib/brick_ftp/restful_api/get_file_in_bundle.rb +49 -0
- data/lib/brick_ftp/restful_api/get_folder_size.rb +25 -0
- data/lib/brick_ftp/restful_api/get_group.rb +26 -0
- data/lib/brick_ftp/restful_api/get_public_key.rb +25 -0
- data/lib/brick_ftp/restful_api/get_site_usage.rb +19 -0
- data/lib/brick_ftp/restful_api/get_user.rb +26 -0
- data/lib/brick_ftp/restful_api/list_api_keys.rb +25 -0
- data/lib/brick_ftp/restful_api/list_behaviors.rb +23 -0
- data/lib/brick_ftp/restful_api/list_bundle_contents.rb +58 -0
- data/lib/brick_ftp/restful_api/list_bundles.rb +23 -0
- data/lib/brick_ftp/restful_api/list_folder_behaviors.rb +39 -0
- data/lib/brick_ftp/restful_api/list_folders.rb +108 -0
- data/lib/brick_ftp/restful_api/list_groups.rb +23 -0
- data/lib/brick_ftp/restful_api/list_notifications.rb +23 -0
- data/lib/brick_ftp/restful_api/list_permissions.rb +41 -0
- data/lib/brick_ftp/restful_api/list_public_keys.rb +25 -0
- data/lib/brick_ftp/restful_api/list_users.rb +60 -0
- data/lib/brick_ftp/restful_api/move_folder.rb +41 -0
- data/lib/brick_ftp/restful_api/remove_group_member.rb +23 -0
- data/lib/brick_ftp/restful_api/retrieve_file_history.rb +41 -0
- data/lib/brick_ftp/restful_api/retrieve_folder_history.rb +41 -0
- data/lib/brick_ftp/restful_api/retrieve_history.rb +54 -0
- data/lib/brick_ftp/restful_api/retrieve_login_history.rb +38 -0
- data/lib/brick_ftp/restful_api/retrieve_site_history.rb +38 -0
- data/lib/brick_ftp/restful_api/retrieve_user_history.rb +40 -0
- data/lib/brick_ftp/restful_api/search_user.rb +28 -0
- data/lib/brick_ftp/restful_api/start_upload.rb +27 -0
- data/lib/brick_ftp/restful_api/unlock_user.rb +25 -0
- data/lib/brick_ftp/restful_api/update_behavior.rb +39 -0
- data/lib/brick_ftp/restful_api/update_group.rb +44 -0
- data/lib/brick_ftp/restful_api/update_group_member.rb +40 -0
- data/lib/brick_ftp/restful_api/update_user.rb +101 -0
- data/lib/brick_ftp/restful_api/upload_file.rb +65 -0
- data/lib/brick_ftp/types.rb +23 -0
- data/lib/brick_ftp/types/behavior.rb +27 -0
- data/lib/brick_ftp/types/bundle.rb +34 -0
- data/lib/brick_ftp/types/bundle_content.rb +25 -0
- data/lib/brick_ftp/types/bundle_zip.rb +19 -0
- data/lib/brick_ftp/types/file.rb +45 -0
- data/lib/brick_ftp/types/file_in_bundle.rb +25 -0
- data/lib/brick_ftp/types/folder_contents_count.rb +24 -0
- data/lib/brick_ftp/types/group.rb +31 -0
- data/lib/brick_ftp/types/group_membership.rb +27 -0
- data/lib/brick_ftp/types/history.rb +43 -0
- data/lib/brick_ftp/types/notification.rb +31 -0
- data/lib/brick_ftp/types/permission.rb +35 -0
- data/lib/brick_ftp/types/site_usage.rb +23 -0
- data/lib/brick_ftp/types/upload.rb +45 -0
- data/lib/brick_ftp/types/user.rb +79 -0
- data/lib/brick_ftp/types/user_api_key.rb +33 -0
- data/lib/brick_ftp/types/user_public_key.rb +28 -0
- data/lib/brick_ftp/utils.rb +2 -0
- data/lib/brick_ftp/utils/chunk_io.rb +5 -4
- data/lib/brick_ftp/version.rb +3 -1
- metadata +123 -86
- data/lib/brick_ftp/api.rb +0 -9
- data/lib/brick_ftp/api/authentication.rb +0 -28
- data/lib/brick_ftp/api/authentication/session.rb +0 -25
- data/lib/brick_ftp/api/base.rb +0 -119
- data/lib/brick_ftp/api/behavior.rb +0 -19
- data/lib/brick_ftp/api/bundle.rb +0 -17
- data/lib/brick_ftp/api/bundle_content.rb +0 -18
- data/lib/brick_ftp/api/bundle_download.rb +0 -18
- data/lib/brick_ftp/api/file.rb +0 -20
- data/lib/brick_ftp/api/file_operation.rb +0 -6
- data/lib/brick_ftp/api/file_operation/copy.rb +0 -10
- data/lib/brick_ftp/api/file_operation/move.rb +0 -10
- data/lib/brick_ftp/api/file_operation/upload.rb +0 -66
- data/lib/brick_ftp/api/file_operation/uploading_result.rb +0 -22
- data/lib/brick_ftp/api/file_operation/uploading_session.rb +0 -95
- data/lib/brick_ftp/api/folder.rb +0 -22
- data/lib/brick_ftp/api/folder_behavior.rb +0 -12
- data/lib/brick_ftp/api/group.rb +0 -16
- data/lib/brick_ftp/api/history.rb +0 -6
- data/lib/brick_ftp/api/history/file.rb +0 -23
- data/lib/brick_ftp/api/history/folder.rb +0 -23
- data/lib/brick_ftp/api/history/login.rb +0 -23
- data/lib/brick_ftp/api/history/site.rb +0 -23
- data/lib/brick_ftp/api/history/user.rb +0 -23
- data/lib/brick_ftp/api/notification.rb +0 -14
- data/lib/brick_ftp/api/permission.rb +0 -17
- data/lib/brick_ftp/api/public_key.rb +0 -15
- data/lib/brick_ftp/api/site_usage.rb +0 -21
- data/lib/brick_ftp/api/user.rb +0 -36
- data/lib/brick_ftp/api_component.rb +0 -81
- data/lib/brick_ftp/api_definition.rb +0 -65
- data/lib/brick_ftp/cli.rb +0 -7
- data/lib/brick_ftp/cli/config.rb +0 -20
- data/lib/brick_ftp/cli/main.rb +0 -26
- data/lib/brick_ftp/cli/site.rb +0 -10
- data/lib/brick_ftp/configuration.rb +0 -121
- data/lib/brick_ftp/http_client.rb +0 -130
- data/lib/brick_ftp/log_formatter.rb +0 -15
- data/lib/brick_ftp/webhook.rb +0 -4
- data/lib/brick_ftp/webhook/request.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c4ed28b9f5dcc9a24e2e0a8d5bb2193c96a8f4f37073389189c2355fcfdd311
|
|
4
|
+
data.tar.gz: 7ab0283efcb065f113cced95502211d2c42428369bf895d2feb3291da46dced4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c11b1d4bbfbaedd952bcac92db8178b9238bd33fc2e294d0164b092abcb3efb35188c688ae9a2b8ac2b060f3a76628297348b50a16646585f067912c2c79cdb
|
|
7
|
+
data.tar.gz: 3541067fd5484dd587967665bbdba46770ef94f7e087353b247cb3ebf19b4f89de8bc121a52fbc4a22efbdb5cab918f1e41e46ed4076bef6c1951eb42db2f72c
|
data/.circleci/config.yml
CHANGED
|
@@ -21,10 +21,6 @@ jobs:
|
|
|
21
21
|
- store_artifacts:
|
|
22
22
|
path: coverage
|
|
23
23
|
destination: coverage
|
|
24
|
-
ruby-2.2:
|
|
25
|
-
<<: *build
|
|
26
|
-
docker:
|
|
27
|
-
- image: circleci/ruby:2.2
|
|
28
24
|
ruby-2.3:
|
|
29
25
|
<<: *build
|
|
30
26
|
docker:
|
|
@@ -42,7 +38,6 @@ workflows:
|
|
|
42
38
|
version: 2
|
|
43
39
|
build-using-multi-rubies:
|
|
44
40
|
jobs:
|
|
45
|
-
- ruby-2.2
|
|
46
41
|
- ruby-2.3
|
|
47
42
|
- ruby-2.4
|
|
48
43
|
- ruby-2.5
|
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
|
3
3
|
AllCops:
|
|
4
|
-
TargetRubyVersion: 2.
|
|
4
|
+
TargetRubyVersion: 2.3
|
|
5
5
|
|
|
6
6
|
Style/EmptyCaseCondition:
|
|
7
7
|
Enabled: false
|
|
@@ -24,6 +24,7 @@ Metrics/LineLength:
|
|
|
24
24
|
URISchemes:
|
|
25
25
|
- http
|
|
26
26
|
- https
|
|
27
|
+
IgnoredPatterns: ['\A(?:\s)*?#']
|
|
27
28
|
|
|
28
29
|
Metrics/BlockLength:
|
|
29
30
|
Exclude:
|
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-m markdown -M redcarpet
|
data/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,10 @@ Changelog
|
|
|
2
2
|
====
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[unreleased](https://github.com/koshigoe/brick_ftp/compare/v1.0.0.beta...master)
|
|
6
6
|
----
|
|
7
7
|
|
|
8
|
-
[Full Changelog](https://github.com/koshigoe/brick_ftp/compare/
|
|
8
|
+
[Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v1.0.0.beta...master)
|
|
9
9
|
|
|
10
10
|
### Enhancements:
|
|
11
11
|
|
|
@@ -13,26 +13,30 @@ Changelog
|
|
|
13
13
|
|
|
14
14
|
### Breaking Changes:
|
|
15
15
|
|
|
16
|
-
### Others
|
|
17
|
-
|
|
18
|
-
- [#129](https://github.com/koshigoe/brick_ftp/pull/129) Update thor to 0.20 (by [cherbst-2112](https://github.com/cherbst-2112))
|
|
19
|
-
|
|
20
16
|
|
|
21
|
-
[0.
|
|
17
|
+
[v1.0.0.beta](https://github.com/koshigoe/brick_ftp/compare/v0.8.2...v1.0.0.beta)
|
|
22
18
|
----
|
|
23
19
|
|
|
24
|
-
[Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v0.8.2...
|
|
20
|
+
[Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v0.8.2...v1.0.0.beta)
|
|
25
21
|
|
|
26
22
|
### Enhancements:
|
|
27
23
|
|
|
28
|
-
- [#114](https://github.com/koshigoe/brick_ftp/pull/114) Allow to upload file using `StringIO`
|
|
29
|
-
|
|
30
24
|
### Fixed Bugs:
|
|
31
25
|
|
|
32
26
|
### Breaking Changes:
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
**CAUTION: There are huge breaking changes!!**
|
|
29
|
+
|
|
30
|
+
- [Dropping support for Ruby 2.2](https://github.com/koshigoe/brick_ftp/pull/104)
|
|
31
|
+
- Set `frozen_string_literal: true`
|
|
32
|
+
- [#105](https://github.com/koshigoe/brick_ftp/pull/105) Re-design (huge change!)
|
|
33
|
+
- Change to RPC like interface
|
|
34
|
+
- Only support token authentication
|
|
35
|
+
- Remove unuseful implementations
|
|
36
|
+
- Remove CLI
|
|
37
|
+
- Remove Webhook
|
|
38
|
+
- Remove Configuration
|
|
39
|
+
- etc.
|
|
36
40
|
|
|
37
41
|
[0.8.2](https://github.com/koshigoe/brick_ftp/compare/v0.8.1...v0.8.2)
|
|
38
42
|
----
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
[](https://codecov.io/gh/koshigoe/brick_ftp)
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
BrickFTP
|
|
6
|
+
====
|
|
6
7
|
|
|
7
|
-
This is a [BrickFTP](https://brickftp.com/)'s _unofficial_ [
|
|
8
|
+
This is a [BrickFTP](https://brickftp.com/)'s _unofficial_ [RESTful API](https://developers.brickftp.com/) Client.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
Installation
|
|
12
|
+
----
|
|
10
13
|
|
|
11
14
|
Add this line to your application's Gemfile:
|
|
12
15
|
|
|
@@ -22,62 +25,40 @@ Or install it yourself as:
|
|
|
22
25
|
|
|
23
26
|
$ gem install brick_ftp
|
|
24
27
|
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
### Configuration
|
|
28
|
-
|
|
29
|
-
```ruby
|
|
30
|
-
BrickFTP.configure do |c|
|
|
31
|
-
c.subdomain = 'koshigoe' # Used by build API URL(e.g. https://{subdomain}.brickftp.com/api/rest/v1/...)
|
|
32
|
-
c.api_key = 'xxxxx' # Used by set REST API key.
|
|
33
|
-
c.logger = Logger.new(STDOUT) # Used by logging.
|
|
34
|
-
end
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
- Environment value `BRICK_FTP_SUBDOMAIN` is set to `subdomain`.
|
|
38
|
-
- Environment value `BRICK_FTP_API_KEY` is set to `api_key`.
|
|
39
|
-
|
|
40
|
-
### Authentication
|
|
41
|
-
|
|
42
|
-
If you authenticate by API key, you set API key to configuration.
|
|
43
|
-
If you authenticate by session cookie, you must authenticate by API.
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
BrickFTP::API::Authentication.login('koshigoe', 'password')
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Other APIs
|
|
51
|
-
|
|
52
|
-
see [API document](http://www.rubydoc.info/github/koshigoe/brick_ftp/master) or source code.
|
|
53
|
-
|
|
54
|
-
### CLI (experimental)
|
|
55
|
-
|
|
56
|
-
#### Configuration
|
|
29
|
+
Usage
|
|
30
|
+
----
|
|
57
31
|
|
|
58
32
|
```
|
|
59
|
-
$
|
|
60
|
-
|
|
33
|
+
$ bin/console
|
|
34
|
+
> client = BrickFTP::Client.new
|
|
35
|
+
> client.list_users
|
|
61
36
|
```
|
|
62
37
|
|
|
63
|
-
#### e.g. Get site usage (disk usage)
|
|
64
|
-
|
|
65
38
|
```
|
|
66
|
-
$
|
|
39
|
+
$ bin/console
|
|
40
|
+
> api_client = BrickFTP::RESTfulAPI::Client.new(ENV['BRICK_FTP_SUBDOMAIN'], ENV['BRICK_FTP_API_KEY'])
|
|
41
|
+
> BrickFTP::RESTfulAPI::ListUsers.new(api_client).call
|
|
67
42
|
```
|
|
68
43
|
|
|
69
|
-
###
|
|
44
|
+
### Environment Variables
|
|
70
45
|
|
|
71
|
-
|
|
46
|
+
Name | Description
|
|
47
|
+
--------------------- | -----------
|
|
48
|
+
`BRICK_FTP_SUBDOMAIN` | Overwrite default subdomain
|
|
49
|
+
`BRICK_FTP_API_KEY` | Overwrite default API key
|
|
72
50
|
|
|
73
51
|
|
|
74
|
-
|
|
52
|
+
Development
|
|
53
|
+
----
|
|
75
54
|
|
|
76
55
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
77
56
|
|
|
78
57
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
79
58
|
|
|
80
|
-
|
|
59
|
+
|
|
60
|
+
Contributing
|
|
61
|
+
----
|
|
81
62
|
|
|
82
63
|
Bug reports and pull requests are welcome on GitHub at https://github.com/koshigoe/brick_ftp.
|
|
83
64
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/brick_ftp.gemspec
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
5
|
require 'brick_ftp/version'
|
|
@@ -18,19 +20,18 @@ Gem::Specification.new do |spec|
|
|
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
19
21
|
spec.require_paths = ['lib']
|
|
20
22
|
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
|
23
|
+
spec.required_ruby_version = '>= 2.3.0'
|
|
22
24
|
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
24
26
|
spec.add_development_dependency 'codecov', '~> 0.1.10'
|
|
25
|
-
spec.add_development_dependency 'pry', '~> 0.
|
|
26
|
-
spec.add_development_dependency 'rake', '~>
|
|
27
|
-
spec.add_development_dependency '
|
|
28
|
-
spec.add_development_dependency '
|
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.11'
|
|
28
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
|
29
|
+
spec.add_development_dependency 'redcarpet', '~> 3.4'
|
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.57.0'
|
|
29
32
|
spec.add_development_dependency 'simplecov', '~> 0.15'
|
|
30
|
-
spec.add_development_dependency 'webmock', '~>
|
|
33
|
+
spec.add_development_dependency 'webmock', '~> 3.4'
|
|
31
34
|
spec.add_development_dependency 'yard', '~> 0.9'
|
|
32
35
|
|
|
33
36
|
spec.add_dependency 'deep_hash_transform', '~> 1.0'
|
|
34
|
-
spec.add_dependency 'inifile', '~> 3.0.0'
|
|
35
|
-
spec.add_dependency 'thor', '~> 0.20'
|
|
36
37
|
end
|
data/exe/brick_ftp
CHANGED
data/lib/brick_ftp.rb
CHANGED
|
@@ -1,49 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'deep_hash_transform'
|
|
2
|
-
require 'thor'
|
|
3
4
|
require 'brick_ftp/version'
|
|
4
|
-
require 'brick_ftp/configuration'
|
|
5
|
-
require 'brick_ftp/log_formatter'
|
|
6
|
-
require 'brick_ftp/http_client'
|
|
7
5
|
require 'brick_ftp/client'
|
|
8
|
-
require 'brick_ftp/
|
|
9
|
-
require 'brick_ftp/api_component'
|
|
10
|
-
require 'brick_ftp/api_definition'
|
|
11
|
-
require 'brick_ftp/api/base'
|
|
12
|
-
require 'brick_ftp/api/authentication'
|
|
13
|
-
require 'brick_ftp/api/authentication/session'
|
|
14
|
-
require 'brick_ftp/api/user'
|
|
15
|
-
require 'brick_ftp/api/public_key'
|
|
16
|
-
require 'brick_ftp/api/group'
|
|
17
|
-
require 'brick_ftp/api/permission'
|
|
18
|
-
require 'brick_ftp/api/notification'
|
|
19
|
-
require 'brick_ftp/api/history'
|
|
20
|
-
require 'brick_ftp/api/history/site'
|
|
21
|
-
require 'brick_ftp/api/history/login'
|
|
22
|
-
require 'brick_ftp/api/history/user'
|
|
23
|
-
require 'brick_ftp/api/history/folder'
|
|
24
|
-
require 'brick_ftp/api/history/file'
|
|
25
|
-
require 'brick_ftp/api/bundle'
|
|
26
|
-
require 'brick_ftp/api/bundle_content'
|
|
27
|
-
require 'brick_ftp/api/bundle_download'
|
|
28
|
-
require 'brick_ftp/api/behavior'
|
|
29
|
-
require 'brick_ftp/api/folder_behavior'
|
|
30
|
-
require 'brick_ftp/api/folder'
|
|
31
|
-
require 'brick_ftp/api/file'
|
|
32
|
-
require 'brick_ftp/api/file_operation'
|
|
33
|
-
require 'brick_ftp/api/file_operation/move'
|
|
34
|
-
require 'brick_ftp/api/file_operation/copy'
|
|
35
|
-
require 'brick_ftp/api/file_operation/upload'
|
|
36
|
-
require 'brick_ftp/api/file_operation/uploading_session'
|
|
37
|
-
require 'brick_ftp/api/file_operation/uploading_result'
|
|
38
|
-
require 'brick_ftp/api/site_usage'
|
|
39
|
-
require 'brick_ftp/webhook'
|
|
40
|
-
require 'brick_ftp/webhook/request'
|
|
41
|
-
require 'brick_ftp/cli'
|
|
42
|
-
require 'brick_ftp/cli/config'
|
|
43
|
-
require 'brick_ftp/cli/site'
|
|
44
|
-
require 'brick_ftp/cli/main'
|
|
6
|
+
require 'brick_ftp/core_ext'
|
|
45
7
|
require 'brick_ftp/utils'
|
|
46
8
|
require 'brick_ftp/utils/chunk_io'
|
|
9
|
+
require 'brick_ftp/types'
|
|
10
|
+
require 'brick_ftp/restful_api'
|
|
47
11
|
|
|
48
12
|
module BrickFTP
|
|
49
13
|
# https://brickftp.com/redundancy/
|
|
@@ -77,41 +41,4 @@ module BrickFTP
|
|
|
77
41
|
54.207.27.239
|
|
78
42
|
52.68.4.44
|
|
79
43
|
].freeze
|
|
80
|
-
|
|
81
|
-
# Return configuration.
|
|
82
|
-
# If it has not been configured yet, initialize configuration.
|
|
83
|
-
# @return [BrickFTP::Configuration] configuration object.
|
|
84
|
-
def self.config
|
|
85
|
-
@config ||= BrickFTP::Configuration.new
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Set configuration.
|
|
89
|
-
#
|
|
90
|
-
# @param config [BrickFTP::Configuration] configuration object.
|
|
91
|
-
# @return [BrickFTP::Configuration] configuration object.
|
|
92
|
-
def self.config=(config)
|
|
93
|
-
raise TypeError unless config.is_a?(BrickFTP::Configuration)
|
|
94
|
-
@config = config
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Configure some settings.
|
|
98
|
-
#
|
|
99
|
-
# @yield [config] Given configuration object.
|
|
100
|
-
# @yieldparam config [BrickFTP::Configuration] configuration object.
|
|
101
|
-
#
|
|
102
|
-
# @example
|
|
103
|
-
# BrickFTP.configure do |c|
|
|
104
|
-
# c.subdomain = 'koshigoe'
|
|
105
|
-
# c.api_key = 'xxxxxxxxxx'
|
|
106
|
-
# end
|
|
107
|
-
#
|
|
108
|
-
def self.configure
|
|
109
|
-
yield(config)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# Return logger object.
|
|
113
|
-
# @return [Logger]
|
|
114
|
-
def self.logger
|
|
115
|
-
config.logger
|
|
116
|
-
end
|
|
117
44
|
end
|
data/lib/brick_ftp/client.rb
CHANGED
|
@@ -1,429 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
class Client
|
|
3
|
-
# Login and store authentication session.
|
|
4
|
-
# @see https://developers.brickftp.com/#authentication-with-a-session
|
|
5
|
-
# @param username [String] username of BrickFTP's user.
|
|
6
|
-
# @param password [String] password of BrickFTP's user.
|
|
7
|
-
def login(username, password)
|
|
8
|
-
BrickFTP::API::Authentication.login(username, password)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Logout and discard authentication session.
|
|
12
|
-
# @see https://developers.brickftp.com/#authentication-with-a-session
|
|
13
|
-
def logout
|
|
14
|
-
BrickFTP::API::Authentication.logout
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# List all users on the current site.
|
|
18
|
-
# @see https://developers.brickftp.com/#users
|
|
19
|
-
# @return [Array] array of BrickFTP::API::User
|
|
20
|
-
def list_users
|
|
21
|
-
BrickFTP::API::User.all
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Show a single user.
|
|
25
|
-
# @see https://developers.brickftp.com/#users
|
|
26
|
-
# @param id user id.
|
|
27
|
-
# @return [BrickFTP::API::User] user object.
|
|
28
|
-
def show_user(id)
|
|
29
|
-
BrickFTP::API::User.find(id)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Create a new user on the current site.
|
|
33
|
-
# @see https://developers.brickftp.com/#users
|
|
34
|
-
# @param attributes [Hash] User's attributes.
|
|
35
|
-
def create_user(attributes)
|
|
36
|
-
BrickFTP::API::User.create(attributes)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Update an existing user.
|
|
40
|
-
# @see https://developers.brickftp.com/#users
|
|
41
|
-
# @param user_or_id [BrickFTP::API::User, Integer] user object or user id.
|
|
42
|
-
# @param attributes [Hash] User's attributes.
|
|
43
|
-
# @return [BrickFTP::API::User] user object.
|
|
44
|
-
def update_user(user_or_id, attributes)
|
|
45
|
-
instantize_user(user_or_id).update(attributes)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Delete a user.
|
|
49
|
-
# @see https://developers.brickftp.com/#users
|
|
50
|
-
# @param user_or_id [BrickFTP::API::User, Integer] user object or user id.
|
|
51
|
-
# @return [Boolean] return true.
|
|
52
|
-
def delete_user(user_or_id)
|
|
53
|
-
instantize_user(user_or_id).destroy
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# List all groups on the current site.
|
|
57
|
-
# @see https://developers.brickftp.com/#groups
|
|
58
|
-
def list_groups
|
|
59
|
-
BrickFTP::API::Group.all
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Show a single group.
|
|
63
|
-
# @see https://developers.brickftp.com/#groups
|
|
64
|
-
# @param id group id.
|
|
65
|
-
# @return [BrickFTP::API::Group] group object.
|
|
66
|
-
def show_group(id)
|
|
67
|
-
BrickFTP::API::Group.find(id)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Create a new group on the current site.
|
|
71
|
-
# @see https://developers.brickftp.com/#groups
|
|
72
|
-
# @param attributes [Hash] Group's attributes.
|
|
73
|
-
def create_group(attributes)
|
|
74
|
-
BrickFTP::API::Group.create(attributes)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Update an existing group.
|
|
78
|
-
# @see https://developers.brickftp.com/#groups
|
|
79
|
-
# @param group_or_id [BrickFTP::API::Group, Integer] group object or group id.
|
|
80
|
-
# @param attributes [Hash] Group's attributes.
|
|
81
|
-
# @return [BrickFTP::API::Group] group object.
|
|
82
|
-
def update_group(group_or_id, attributes)
|
|
83
|
-
instantize_group(group_or_id).update(attributes)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Delete a group.
|
|
87
|
-
# @see https://developers.brickftp.com/#groups
|
|
88
|
-
# @param group_or_id [BrickFTP::API::Group, Integer] group object or group id.
|
|
89
|
-
# @return [Boolean] return true.
|
|
90
|
-
def delete_group(group_or_id)
|
|
91
|
-
instantize_group(group_or_id).destroy
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# List all permissions on the current site.
|
|
95
|
-
# @see https://developers.brickftp.com/#permissions
|
|
96
|
-
def list_permissions
|
|
97
|
-
BrickFTP::API::Permission.all
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Create a new permission on the current site.
|
|
101
|
-
# @see https://developers.brickftp.com/#permissions
|
|
102
|
-
# @param attributes [Hash] Permission's attributes.
|
|
103
|
-
def create_permission(attributes)
|
|
104
|
-
BrickFTP::API::Permission.create(attributes)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Delete a permission.
|
|
108
|
-
# @see https://developers.brickftp.com/#permissions
|
|
109
|
-
# @param permission_or_id [BrickFTP::API::Permission, Integer] permission object or permission id.
|
|
110
|
-
# @return [Boolean] return true.
|
|
111
|
-
def delete_permission(permission_or_id)
|
|
112
|
-
instantize_permission(permission_or_id).destroy
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# List all notifications on the current site.
|
|
116
|
-
# @see https://developers.brickftp.com/#notifications
|
|
117
|
-
def list_notifications
|
|
118
|
-
BrickFTP::API::Notification.all
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Create a new notification on the current site.
|
|
122
|
-
# @see https://developers.brickftp.com/#notifications
|
|
123
|
-
# @param attributes [Hash] Notification's attributes.
|
|
124
|
-
def create_notification(attributes)
|
|
125
|
-
BrickFTP::API::Notification.create(attributes)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Delete a notification.
|
|
129
|
-
# @see https://developers.brickftp.com/#notifications
|
|
130
|
-
# @param notification_or_id [BrickFTP::API::Notification, Integer] notification object or notification id.
|
|
131
|
-
# @return [Boolean] return true.
|
|
132
|
-
def delete_notification(notification_or_id)
|
|
133
|
-
instantize_notification(notification_or_id).destroy
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Show the entire history for the current site.
|
|
137
|
-
# @see https://developers.brickftp.com/#history
|
|
138
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
139
|
-
# @param display [String] Pass in 'full' to receive display summary
|
|
140
|
-
# @param per_page [Integer] Requested number of items returned per request. Default: 1000, maximum: 10000.
|
|
141
|
-
# Leave blank for default (strongly recommended).
|
|
142
|
-
# @param start_at [String] Date and time in the history to start from.
|
|
143
|
-
# @return [Array] array of `BrickFTP::API::History::Site`
|
|
144
|
-
def list_site_history(page: nil, display: nil, per_page: nil, start_at: nil)
|
|
145
|
-
query = { page: page, display: display, per_page: per_page, start_at: start_at }.reject { |_, v| v.nil? }
|
|
146
|
-
BrickFTP::API::History::Site.all(query)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Show login history only.
|
|
150
|
-
# @see https://developers.brickftp.com/#history
|
|
151
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
152
|
-
# @param display [String] Pass in 'full' to receive display summary
|
|
153
|
-
# @param per_page [Integer] Requested number of items returned per request. Default: 1000, maximum: 10000.
|
|
154
|
-
# Leave blank for default (strongly recommended).
|
|
155
|
-
# @param start_at [String] Date and time in the history to start from.
|
|
156
|
-
# @return [Array] array of `BrickFTP::API::History::Login`
|
|
157
|
-
def list_login_history(page: nil, display: nil, per_page: nil, start_at: nil)
|
|
158
|
-
query = { page: page, display: display, per_page: per_page, start_at: start_at }.reject { |_, v| v.nil? }
|
|
159
|
-
BrickFTP::API::History::Login.all(query)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# Show all history for a specific user.
|
|
163
|
-
# @see https://developers.brickftp.com/#history
|
|
164
|
-
# @param user_id [Integer] User ID.
|
|
165
|
-
# @param display [String] Pass in 'full' to receive display summary
|
|
166
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
167
|
-
# @param per_page [Integer] Requested number of items returned per request.
|
|
168
|
-
# Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
|
|
169
|
-
# @param start_at [String] Date and time in the history to start from.
|
|
170
|
-
# @return [Array] array of `BrickFTP::API::History::User`
|
|
171
|
-
def list_user_history(user_id:, display: nil, page: nil, per_page: nil, start_at: nil)
|
|
172
|
-
query = { user_id: user_id, display: display, page: page, per_page: per_page, start_at: start_at }
|
|
173
|
-
.reject { |_, v| v.nil? }
|
|
174
|
-
BrickFTP::API::History::User.all(query)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Show all history for a specific folder.
|
|
178
|
-
# @see https://developers.brickftp.com/#history
|
|
179
|
-
# @param path [String] path of folder.
|
|
180
|
-
# @param display [String] Pass in 'full' to receive display summary
|
|
181
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
182
|
-
# @param per_page [Integer] Requested number of items returned per request.
|
|
183
|
-
# Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
|
|
184
|
-
# @param start_at [String] Date and time in the history to start from.
|
|
185
|
-
# @return [Array] array of `BrickFTP::API::History::Folder`
|
|
186
|
-
def list_folder_history(path:, display: nil, page: nil, per_page: nil, start_at: nil)
|
|
187
|
-
query = { path: path, display: display, page: page, per_page: per_page, start_at: start_at }.reject { |_, v| v.nil? }
|
|
188
|
-
BrickFTP::API::History::Folder.all(query)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# Show all history for a specific file.
|
|
192
|
-
# @see https://developers.brickftp.com/#history
|
|
193
|
-
# @param path [String] path of file.
|
|
194
|
-
# @param display [String] Pass in 'full' to receive display summary
|
|
195
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
196
|
-
# @param per_page [Integer] Requested number of items returned per request.
|
|
197
|
-
# Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
|
|
198
|
-
# @param start_at [String] Date and time in the history to start from.
|
|
199
|
-
# @return [Array] array of `BrickFTP::API::History::File`
|
|
200
|
-
def list_file_history(path:, display: nil, page: nil, per_page: nil, start_at: nil)
|
|
201
|
-
query = { path: path, display: display, page: page, per_page: per_page, start_at: start_at }.reject { |_, v| v.nil? }
|
|
202
|
-
BrickFTP::API::History::File.all(query)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
# List all bundles on the current site.
|
|
206
|
-
# @see https://developers.brickftp.com/#bundles
|
|
207
|
-
# @return [Array] array of BrickFTP::API::Bundle
|
|
208
|
-
def list_bundles
|
|
209
|
-
BrickFTP::API::Bundle.all
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
# Show a single bundle.
|
|
213
|
-
# @see https://developers.brickftp.com/#bundles
|
|
214
|
-
# @param id bundle id.
|
|
215
|
-
# @return [BrickFTP::API::Bundle] bundle object.
|
|
216
|
-
def show_bundle(id)
|
|
217
|
-
BrickFTP::API::Bundle.find(id)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
# Create a new bundle on the current site.
|
|
221
|
-
# @see https://developers.brickftp.com/#bundles
|
|
222
|
-
# @param attributes [Hash] Bundle's attributes.
|
|
223
|
-
def create_bundle(attributes)
|
|
224
|
-
BrickFTP::API::Bundle.create(attributes)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
# Delete a bundle.
|
|
228
|
-
# @see https://developers.brickftp.com/#bundles
|
|
229
|
-
# @param bundle_or_id [BrickFTP::API::Bundle, Integer] bundle object or bundle id.
|
|
230
|
-
# @return [Boolean] return true.
|
|
231
|
-
def delete_bundle(bundle_or_id)
|
|
232
|
-
instantize_bundle(bundle_or_id).destroy
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
# List the contents of a bundle.
|
|
236
|
-
# @see https://developers.brickftp.com/#bundles
|
|
237
|
-
# @param path [String]
|
|
238
|
-
# @param code [String]
|
|
239
|
-
# @param host [String]
|
|
240
|
-
# @return [Array] array of `BrickFTP::API::BundleContent`.
|
|
241
|
-
def list_bundle_contents(path: nil, code:, host:)
|
|
242
|
-
BrickFTP::API::BundleContent.all(path: path, code: code, host: host)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
# Provides download URLs that will enable you to download the files in a bundle.
|
|
246
|
-
# @see https://developers.brickftp.com/#bundles
|
|
247
|
-
# @param code [String]
|
|
248
|
-
# @param host [String]
|
|
249
|
-
# @param paths [Array] array of path string.
|
|
250
|
-
# @return [Array] array of `BrickFTP::API::BundleDownload`.
|
|
251
|
-
def list_bundle_downloads(code:, host:, paths: [])
|
|
252
|
-
BrickFTP::API::BundleDownload.all(code: code, host: host, paths: paths)
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
# List all behaviors on the current site.
|
|
256
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
257
|
-
# @return [Array] array of BrickFTP::API::Behavior
|
|
258
|
-
def list_behaviors
|
|
259
|
-
BrickFTP::API::Behavior.all
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
# Show a single behavior.
|
|
263
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
264
|
-
# @param id behavior id.
|
|
265
|
-
# @return [BrickFTP::API::Behavior] behavior object.
|
|
266
|
-
def show_behavior(id)
|
|
267
|
-
BrickFTP::API::Behavior.find(id)
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
# Create a new behavior on the current site.
|
|
271
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
272
|
-
# @param attributes [Hash] Behavior's attributes.
|
|
273
|
-
def create_behavior(attributes)
|
|
274
|
-
BrickFTP::API::Behavior.create(attributes)
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
# Update an existing behavior.
|
|
278
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
279
|
-
# @param behavior_or_id [BrickFTP::API::Behavior, Integer] behavior object or behavior id.
|
|
280
|
-
# @param attributes [Hash] Behavior's attributes.
|
|
281
|
-
# @return [BrickFTP::API::Behavior] behavior object.
|
|
282
|
-
def update_behavior(behavior_or_id, attributes)
|
|
283
|
-
instantize_behavior(behavior_or_id).update(attributes)
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
# Delete a behavior.
|
|
287
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
288
|
-
# @param behavior_or_id [BrickFTP::API::Behavior, Integer] behavior object or behavior id.
|
|
289
|
-
# @return [Boolean] return true.
|
|
290
|
-
def delete_behavior(behavior_or_id)
|
|
291
|
-
instantize_behavior(behavior_or_id).destroy
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
# shows the behaviors that apply to the given path.
|
|
295
|
-
# @see https://developers.brickftp.com/#behaviors
|
|
296
|
-
# @return [Array] array of BrickFTP::API::FolderBehavior
|
|
297
|
-
def list_folder_behaviors(path:)
|
|
298
|
-
BrickFTP::API::FolderBehavior.all(path: path)
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
# Lists the contents of the folder provided in the URL.
|
|
302
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
303
|
-
# @param path [String]
|
|
304
|
-
# @param page [Integer] Page number of items to return in this request.
|
|
305
|
-
# @param per_page [Integer] Requested number of items returned per request.
|
|
306
|
-
# Maximum: 5000, leave blank for default (strongly recommended).
|
|
307
|
-
# @param search [String] Only return items matching the given search text.
|
|
308
|
-
# @param sort_by_path [String] Sort by file name, and value is either asc or desc to indicate normal or reverse sort.
|
|
309
|
-
# (Note that sort_by[path] = asc is the default.)
|
|
310
|
-
# @param sort_by_size [String] Sort by file size, and value is either asc or desc to indicate smaller files
|
|
311
|
-
# first or larger files first, respectively.
|
|
312
|
-
# @param sort_by_modified_at_datetime [String] Sort by modification time, and value is either asc or desc to
|
|
313
|
-
# indicate older files first or newer files first, respectively.
|
|
314
|
-
# @return [Array] array of BrickFTP::API::Folder.
|
|
315
|
-
def list_folders(path:, page: nil, per_page: nil, search: nil, sort_by_path: nil, sort_by_size: nil, sort_by_modified_at_datetime: nil) # rubocop:disable Metrics/LineLength
|
|
316
|
-
query = { path: path, page: page, per_page: per_page, search: search }.reject { |_, v| v.nil? }
|
|
317
|
-
query[:'sort_by[path]'] = sort_by_path if sort_by_path
|
|
318
|
-
query[:'sort_by[size]'] = sort_by_size if sort_by_size
|
|
319
|
-
query[:'sort_by[modified_at_datetime]'] = sort_by_modified_at_datetime if sort_by_modified_at_datetime
|
|
320
|
-
BrickFTP::API::Folder.all(query)
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
# Create a folder.
|
|
324
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
325
|
-
# @param path [String]
|
|
326
|
-
# @return [BrickFTP::API::Folder]
|
|
327
|
-
def create_folder(path:)
|
|
328
|
-
BrickFTP::API::Folder.create(path: path)
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
# provides a download URL that will enable you to download a file.
|
|
332
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
333
|
-
# @param path [String] path for file.
|
|
334
|
-
# @param omit_download_uri [Boolean] If true, omit download_uri. (Add query `action=stat`)
|
|
335
|
-
# @return [BrickFTP::API::File] file object.
|
|
336
|
-
def show_file(path, omit_download_uri: false)
|
|
337
|
-
params = {}
|
|
338
|
-
params[:action] = 'stat' if omit_download_uri
|
|
339
|
-
BrickFTP::API::File.find(path, params: params)
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
# Move or renames a file or folder to the destination provided in the move_destination parameter.
|
|
343
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
344
|
-
# @param path [String]
|
|
345
|
-
# @param move_destination [String]
|
|
346
|
-
# @return [BrickFTP::API::FileMove]
|
|
347
|
-
def move_file(path:, move_destination:)
|
|
348
|
-
BrickFTP::API::FileOperation::Move.create(path: path, 'move-destination': move_destination)
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
# Copy a file or folder to the destination provided in the copy_destination parameter.
|
|
352
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
353
|
-
# @param path [String]
|
|
354
|
-
# @param copy_destination [String]
|
|
355
|
-
# @return [BrickFTP::API::FileCopy]
|
|
356
|
-
def copy_file(path:, copy_destination:)
|
|
357
|
-
BrickFTP::API::FileOperation::Copy.create(path: path, 'copy-destination': copy_destination)
|
|
358
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
359
2
|
|
|
360
|
-
|
|
361
|
-
# @see https://developers.brickftp.com/#file-and-folder-operations
|
|
362
|
-
# @param file_or_path [BrickFTP::API::File, String] file object or file(folder) path.
|
|
363
|
-
# @param recursive [Boolean]
|
|
364
|
-
# @return [Boolean] return true.
|
|
365
|
-
def delete_file(file_or_path, recursive: false)
|
|
366
|
-
instantize_file(file_or_path).destroy(recursive: recursive)
|
|
367
|
-
end
|
|
3
|
+
require 'brick_ftp/restful_api'
|
|
368
4
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
5
|
+
module BrickFTP
|
|
6
|
+
# To delegate commands.
|
|
7
|
+
#
|
|
8
|
+
# @see BrickFTP::RESTfulAPI
|
|
9
|
+
# @example Call {BrickFTP::RESTfulAPI::ListUser#call}
|
|
10
|
+
# BrickFTP::Client.new.list_users
|
|
11
|
+
#
|
|
12
|
+
class Client
|
|
13
|
+
attr_reader :subdomain, :api_key, :api_client
|
|
378
14
|
|
|
379
|
-
#
|
|
380
|
-
# @
|
|
381
|
-
def
|
|
382
|
-
|
|
15
|
+
# @param [String] subdomain
|
|
16
|
+
# @param [String] api_key
|
|
17
|
+
def initialize(subdomain: nil, api_key: nil)
|
|
18
|
+
@subdomain = subdomain || ENV['BRICK_FTP_SUBDOMAIN']
|
|
19
|
+
@api_key = api_key || ENV['BRICK_FTP_API_KEY']
|
|
20
|
+
@api_client = BrickFTP::RESTfulAPI::Client.new(@subdomain, @api_key)
|
|
383
21
|
end
|
|
384
22
|
|
|
385
23
|
private
|
|
386
24
|
|
|
387
|
-
def
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
BrickFTP::API::User.new(id: user_or_id)
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
def instantize_group(group_or_id)
|
|
394
|
-
return group_or_id if group_or_id.is_a?(BrickFTP::API::Group)
|
|
395
|
-
|
|
396
|
-
BrickFTP::API::Group.new(id: group_or_id)
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
def instantize_permission(permission_or_id)
|
|
400
|
-
return permission_or_id if permission_or_id.is_a?(BrickFTP::API::Permission)
|
|
401
|
-
|
|
402
|
-
BrickFTP::API::Permission.new(id: permission_or_id)
|
|
403
|
-
end
|
|
25
|
+
def command_class(symbol)
|
|
26
|
+
name = symbol.to_s.split('_').map(&:capitalize).join
|
|
27
|
+
return unless BrickFTP::RESTfulAPI.const_defined?(name)
|
|
404
28
|
|
|
405
|
-
|
|
406
|
-
return
|
|
29
|
+
klass = BrickFTP::RESTfulAPI.const_get(name)
|
|
30
|
+
return unless klass < BrickFTP::RESTfulAPI::Command
|
|
407
31
|
|
|
408
|
-
|
|
32
|
+
klass
|
|
409
33
|
end
|
|
410
34
|
|
|
411
|
-
def
|
|
412
|
-
return
|
|
413
|
-
|
|
414
|
-
BrickFTP::API::Bundle.new(id: bundle_or_id)
|
|
35
|
+
def respond_to_missing?(symbol, include_private)
|
|
36
|
+
return true if command_class(symbol)
|
|
37
|
+
super
|
|
415
38
|
end
|
|
416
39
|
|
|
417
|
-
def
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
40
|
+
def method_missing(name, *args)
|
|
41
|
+
klass = command_class(name)
|
|
42
|
+
if klass
|
|
43
|
+
dispatch_command(klass, *args)
|
|
44
|
+
else
|
|
45
|
+
super
|
|
46
|
+
end
|
|
421
47
|
end
|
|
422
48
|
|
|
423
|
-
def
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
BrickFTP::API::File.new(path: file_or_path)
|
|
49
|
+
def dispatch_command(klass, *args)
|
|
50
|
+
klass.new(api_client).call(*args)
|
|
427
51
|
end
|
|
428
52
|
end
|
|
429
53
|
end
|