yadisk-client 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +3 -0
- data/.rubocop.yml +142 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +110 -0
- data/LICENSE +7 -0
- data/README.md +61 -0
- data/Rakefile +16 -0
- data/lib/yadisk/client.rb +44 -0
- data/lib/yadisk/collection.rb +26 -0
- data/lib/yadisk/error.rb +6 -0
- data/lib/yadisk/object.rb +25 -0
- data/lib/yadisk/objects/disk.rb +6 -0
- data/lib/yadisk/objects/link.rb +5 -0
- data/lib/yadisk/objects/operation.rb +5 -0
- data/lib/yadisk/objects/public.rb +6 -0
- data/lib/yadisk/objects/resource.rb +11 -0
- data/lib/yadisk/objects/trash.rb +6 -0
- data/lib/yadisk/resources/disk.rb +88 -0
- data/lib/yadisk/resources/operation.rb +10 -0
- data/lib/yadisk/resources/public.rb +17 -0
- data/lib/yadisk/resources/trash.rb +20 -0
- data/lib/yadisk/rest.rb +58 -0
- data/lib/yadisk/version.rb +9 -0
- data/lib/yadisk.rb +35 -0
- data/spec/lib/yadisk/client_spec.rb +19 -0
- data/spec/lib/yadisk/disk_spec.rb +226 -0
- data/spec/lib/yadisk/errors_spec.rb +16 -0
- data/spec/lib/yadisk/operations_spec.rb +23 -0
- data/spec/lib/yadisk/public_spec.rb +51 -0
- data/spec/lib/yadisk/trash_spec.rb +72 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/cassette_helpers.rb +23 -0
- data/spec/test_data/test_file.txt +1 -0
- data/spec/vcr/disk/DELETE_delete.yml +50 -0
- data/spec/vcr/disk/ERROR_info.yml +48 -0
- data/spec/vcr/disk/GET_download.yml +52 -0
- data/spec/vcr/disk/GET_get_meta.yml +52 -0
- data/spec/vcr/disk/GET_info.yml +52 -0
- data/spec/vcr/disk/GET_list_public.yml +52 -0
- data/spec/vcr/disk/GET_upload.yml +48 -0
- data/spec/vcr/disk/PATCH_update_meta.yml +54 -0
- data/spec/vcr/disk/POST_copy.yml +50 -0
- data/spec/vcr/disk/POST_move.yml +50 -0
- data/spec/vcr/disk/POST_upload_by_url.yml +52 -0
- data/spec/vcr/disk/PUT_create_dir.yml +50 -0
- data/spec/vcr/disk/PUT_publish.yml +54 -0
- data/spec/vcr/disk/PUT_unpublish.yml +54 -0
- data/spec/vcr/operations/GET_status.yml +52 -0
- data/spec/vcr/trash/DELETE_delete.yml +50 -0
- data/spec/vcr/trash/DELETE_delete_error.yml +49 -0
- data/spec/vcr/trash/GET_list.yml +51 -0
- data/spec/vcr/trash/PUT_restore.yml +51 -0
- data/spec/vcr_setup.rb +35 -0
- data/yadisk.gemspec +26 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 773e6386c0a726ce03bab8d09c68fde2d11aaad6ba41fa68d6088724ca47f9de
|
4
|
+
data.tar.gz: cf5fb42c245ba1649b3327f576003511852ac21f272c7b0d83e24fda8de988d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11149f7f6bcab071cf404c12606617c3a2e6421103ad92b2629e9c737be9a3d67d5b118cfeb968b2cde0766fc97a2187bd6c9b60e044dd8824656efbd5012cd1
|
7
|
+
data.tar.gz: 01526162c291d8ad551288e0a81a71ec5d137e475b5b44548060495d4003eb2be7187b1935a17b4e9c77ca8851bcf9fe86dc80170fa677be2197354aa7800de3
|
data/.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
## macos
|
37
|
+
.DS_Store
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
NewCops: disable # TODO: change to enable after refactoring
|
4
|
+
|
5
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
6
|
+
Layout/LineLength:
|
7
|
+
Max: 120
|
8
|
+
|
9
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
10
|
+
# the code easier to read (by naming things), but can also clutter the class
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 20
|
13
|
+
|
14
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 1500
|
17
|
+
|
18
|
+
# No space makes the method definition shorter and differentiates
|
19
|
+
# from a regular assignment.
|
20
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
21
|
+
EnforcedStyle: no_space
|
22
|
+
|
23
|
+
# Single quotes being faster is hardly measurable and only affects parse time.
|
24
|
+
# Enforcing double quotes reduces the times where you need to change them
|
25
|
+
# when introducing an interpolation. Use single quotes only if their semantics
|
26
|
+
# are needed.
|
27
|
+
Style/StringLiterals:
|
28
|
+
EnforcedStyle: double_quotes
|
29
|
+
|
30
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
31
|
+
Style/SymbolArray:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
# Most readable form.
|
35
|
+
Style/OptionHash:
|
36
|
+
# A list of parameter names that will be flagged by this cop.
|
37
|
+
SuspiciousParamNames:
|
38
|
+
- options
|
39
|
+
- opts
|
40
|
+
- args
|
41
|
+
- paramsgit sttus
|
42
|
+
- parameters
|
43
|
+
|
44
|
+
# Mixing the styles looks just silly.
|
45
|
+
Style/HashSyntax:
|
46
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
47
|
+
|
48
|
+
# has_key? and has_value? are far more readable than key? and value?
|
49
|
+
Style/PreferredHashMethods:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
# String#% is by far the least verbose and only object oriented variant.
|
53
|
+
Style/FormatString:
|
54
|
+
EnforcedStyle: percent
|
55
|
+
|
56
|
+
Style/CollectionMethods:
|
57
|
+
Enabled: true
|
58
|
+
PreferredMethods:
|
59
|
+
# inject seems more common in the community.
|
60
|
+
reduce: "inject"
|
61
|
+
|
62
|
+
|
63
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
64
|
+
# is silly. Let's try to live without them for now.
|
65
|
+
Style/ParenthesesAroundCondition:
|
66
|
+
AllowSafeAssignment: false
|
67
|
+
Lint/AssignmentInCondition:
|
68
|
+
AllowSafeAssignment: false
|
69
|
+
|
70
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
71
|
+
# So both variants make sense.
|
72
|
+
Style/RaiseArgs:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
76
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
77
|
+
Layout/MultilineOperationIndentation:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
81
|
+
# The argument that fail should be used to abort the program is wrong too,
|
82
|
+
# there's Kernel#abort for that.
|
83
|
+
Style/SignalException:
|
84
|
+
EnforcedStyle: only_raise
|
85
|
+
|
86
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
87
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
88
|
+
# or suppressing LoadError for optional dependencies
|
89
|
+
Lint/SuppressedException:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Layout/SpaceInsideBlockBraces:
|
93
|
+
# The space here provides no real gain in readability while consuming
|
94
|
+
# horizontal space that could be used for a better parameter name.
|
95
|
+
# Also {| differentiates better from a hash than { | does.
|
96
|
+
SpaceBeforeBlockParameters: false
|
97
|
+
|
98
|
+
# No trailing space differentiates better from the block:
|
99
|
+
# foo} means hash, foo } means block.
|
100
|
+
Layout/SpaceInsideHashLiteralBraces:
|
101
|
+
EnforcedStyle: no_space
|
102
|
+
|
103
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
104
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
105
|
+
Style/BlockDelimiters:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
# do / end blocks should be used for side effects,
|
109
|
+
# methods that run a block for side effects and have
|
110
|
+
# a useful return value are rare, assign the return
|
111
|
+
# value to a local variable for those cases.
|
112
|
+
Style/MethodCalledOnDoEndBlock:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
116
|
+
Style/SingleLineBlockParams:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
# Shadowing outer local variables with block parameters is often useful
|
120
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
121
|
+
# between the outer variable and the parameter. The cases where it's actually
|
122
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
123
|
+
# because the method is too long.
|
124
|
+
Lint/ShadowingOuterLocalVariable:
|
125
|
+
Enabled: false
|
126
|
+
|
127
|
+
# Check with yard instead.
|
128
|
+
Style/Documentation:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
# This is just silly. Calling the argument `other` in all cases makes no sense.
|
132
|
+
Naming/BinaryOperatorParameterName:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
# There are valid cases, for example debugging Cucumber steps,
|
136
|
+
# also they'll fail CI anyway
|
137
|
+
Lint/Debugger:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
# Style preference
|
141
|
+
Style/MethodDefParentheses:
|
142
|
+
Enabled: false
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# gem "yadisk-client", path: "./" # dev mode
|
6
|
+
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
gem "addressable", "~> 2.3", ">= 2.3.7"
|
10
|
+
gem "minitest", ">= 5.0.5"
|
11
|
+
gem "rake"
|
12
|
+
gem "standard"
|
13
|
+
|
14
|
+
gem "rspec"
|
15
|
+
gem "vcr"
|
16
|
+
gem "webmock"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yadisk-client (1.10.2)
|
5
|
+
addressable (~> 2.3, >= 2.3.7)
|
6
|
+
faraday (~> 1.7)
|
7
|
+
faraday_middleware (~> 1.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.8.1)
|
13
|
+
public_suffix (>= 2.0.2, < 6.0)
|
14
|
+
ast (2.4.2)
|
15
|
+
crack (0.4.5)
|
16
|
+
rexml
|
17
|
+
diff-lcs (1.5.0)
|
18
|
+
faraday (1.10.2)
|
19
|
+
faraday-em_http (~> 1.0)
|
20
|
+
faraday-em_synchrony (~> 1.0)
|
21
|
+
faraday-excon (~> 1.1)
|
22
|
+
faraday-httpclient (~> 1.0)
|
23
|
+
faraday-multipart (~> 1.0)
|
24
|
+
faraday-net_http (~> 1.0)
|
25
|
+
faraday-net_http_persistent (~> 1.0)
|
26
|
+
faraday-patron (~> 1.0)
|
27
|
+
faraday-rack (~> 1.0)
|
28
|
+
faraday-retry (~> 1.0)
|
29
|
+
ruby2_keywords (>= 0.0.4)
|
30
|
+
faraday-em_http (1.0.0)
|
31
|
+
faraday-em_synchrony (1.0.0)
|
32
|
+
faraday-excon (1.1.0)
|
33
|
+
faraday-httpclient (1.0.1)
|
34
|
+
faraday-multipart (1.0.4)
|
35
|
+
multipart-post (~> 2)
|
36
|
+
faraday-net_http (1.0.1)
|
37
|
+
faraday-net_http_persistent (1.2.0)
|
38
|
+
faraday-patron (1.0.0)
|
39
|
+
faraday-rack (1.0.0)
|
40
|
+
faraday-retry (1.0.3)
|
41
|
+
faraday_middleware (1.2.0)
|
42
|
+
faraday (~> 1.0)
|
43
|
+
hashdiff (1.0.1)
|
44
|
+
json (2.6.2)
|
45
|
+
minitest (5.16.3)
|
46
|
+
multipart-post (2.2.3)
|
47
|
+
parallel (1.22.1)
|
48
|
+
parser (3.1.2.1)
|
49
|
+
ast (~> 2.4.1)
|
50
|
+
public_suffix (5.0.0)
|
51
|
+
rainbow (3.1.1)
|
52
|
+
rake (13.0.6)
|
53
|
+
regexp_parser (2.5.0)
|
54
|
+
rexml (3.2.5)
|
55
|
+
rspec (3.11.0)
|
56
|
+
rspec-core (~> 3.11.0)
|
57
|
+
rspec-expectations (~> 3.11.0)
|
58
|
+
rspec-mocks (~> 3.11.0)
|
59
|
+
rspec-core (3.11.0)
|
60
|
+
rspec-support (~> 3.11.0)
|
61
|
+
rspec-expectations (3.11.1)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.11.0)
|
64
|
+
rspec-mocks (3.11.1)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.11.0)
|
67
|
+
rspec-support (3.11.1)
|
68
|
+
rubocop (1.35.1)
|
69
|
+
json (~> 2.3)
|
70
|
+
parallel (~> 1.10)
|
71
|
+
parser (>= 3.1.2.1)
|
72
|
+
rainbow (>= 2.2.2, < 4.0)
|
73
|
+
regexp_parser (>= 1.8, < 3.0)
|
74
|
+
rexml (>= 3.2.5, < 4.0)
|
75
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
76
|
+
ruby-progressbar (~> 1.7)
|
77
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
78
|
+
rubocop-ast (1.21.0)
|
79
|
+
parser (>= 3.1.1.0)
|
80
|
+
rubocop-performance (1.14.3)
|
81
|
+
rubocop (>= 1.7.0, < 2.0)
|
82
|
+
rubocop-ast (>= 0.4.0)
|
83
|
+
ruby-progressbar (1.11.0)
|
84
|
+
ruby2_keywords (0.0.5)
|
85
|
+
standard (1.16.1)
|
86
|
+
rubocop (= 1.35.1)
|
87
|
+
rubocop-performance (= 1.14.3)
|
88
|
+
unicode-display_width (2.3.0)
|
89
|
+
vcr (6.1.0)
|
90
|
+
webmock (3.18.1)
|
91
|
+
addressable (>= 2.8.0)
|
92
|
+
crack (>= 0.3.2)
|
93
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
universal-darwin-21
|
97
|
+
x86_64-darwin-17
|
98
|
+
|
99
|
+
DEPENDENCIES
|
100
|
+
addressable (~> 2.3, >= 2.3.7)
|
101
|
+
minitest (>= 5.0.5)
|
102
|
+
rake
|
103
|
+
rspec
|
104
|
+
standard
|
105
|
+
vcr
|
106
|
+
webmock
|
107
|
+
yadisk-client!
|
108
|
+
|
109
|
+
BUNDLED WITH
|
110
|
+
2.3.22
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2022 Ilya Brin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Yadisk - Yandex.Disk API client (ruby gem)
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yadisk-client.svg)](https://badge.fury.io/rb/yadisk-client)
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install yadisk-client
|
9
|
+
```
|
10
|
+
|
11
|
+
## Development
|
12
|
+
|
13
|
+
```sh
|
14
|
+
gem build yadisk.gemspec && gem install yadisk-client && bundle exec rake console
|
15
|
+
```
|
16
|
+
|
17
|
+
## Available methods
|
18
|
+
|
19
|
+
> **Note**
|
20
|
+
> `**params` not included in requests, but will be later
|
21
|
+
> `**attributes` used in `update_meta` method only
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
|
25
|
+
client = Yadisk::Client.new(token: 'paste your token here')
|
26
|
+
|
27
|
+
client.disk.info
|
28
|
+
client.disk.upload(path:)
|
29
|
+
client.disk.upload_from_file(upload_link:, src:)
|
30
|
+
client.disk.upload_by_url(path:, url:)
|
31
|
+
client.disk.delete(path:)
|
32
|
+
client.disk.get_meta(path:, **params)
|
33
|
+
|
34
|
+
# client.disk.update_meta(path: "dir_or_file_path", any_key_name: "value", other_key_name: "any_value")
|
35
|
+
client.disk.update_meta(path:, **attributes)
|
36
|
+
client.disk.create_dir(path:)
|
37
|
+
client.disk.copy(from:, to:)
|
38
|
+
client.disk.download(path:, **params)
|
39
|
+
client.disk.list_files(**params)
|
40
|
+
client.disk.last_uploaded(**params)
|
41
|
+
client.disk.move(from:, to:)
|
42
|
+
client.disk.list_public(**params)
|
43
|
+
client.disk.publish(path:)
|
44
|
+
client.disk.unpublish(path:)
|
45
|
+
|
46
|
+
client.public_resource.meta(public_key:, **params)
|
47
|
+
client.public_resource.link(public_key:, **params)
|
48
|
+
client.public_resource.save(public_key:, **params)
|
49
|
+
|
50
|
+
client.operation.status(operation_id:)
|
51
|
+
|
52
|
+
client.trash.delete(path:, **params)
|
53
|
+
client.trash.list(path:, **params)
|
54
|
+
client.trash.restore(path:)
|
55
|
+
```
|
56
|
+
|
57
|
+
## TODOs
|
58
|
+
|
59
|
+
- tests
|
60
|
+
- examples
|
61
|
+
- readme
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
13
|
+
|
14
|
+
task :console do
|
15
|
+
exec "irb -I lib -r yadisk.rb"
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yadisk
|
4
|
+
class Client
|
5
|
+
BASE_URL = "https://cloud-api.yandex.net/v1"
|
6
|
+
attr_reader :token, :adapter
|
7
|
+
|
8
|
+
# new client
|
9
|
+
def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
|
10
|
+
@token = token
|
11
|
+
@adapter = adapter
|
12
|
+
@stubs = stubs # Test stubs for requests
|
13
|
+
end
|
14
|
+
|
15
|
+
def disk
|
16
|
+
DiskRest.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def operation
|
20
|
+
OperationRest.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def trash
|
24
|
+
TrashRest.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def public_resource
|
28
|
+
PublicRest.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def connection
|
32
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
33
|
+
conn.request :authorization, :OAuth, token
|
34
|
+
conn.request :json
|
35
|
+
conn.request :url_encoded
|
36
|
+
|
37
|
+
conn.response :dates
|
38
|
+
conn.response :json, content_type: "application/json"
|
39
|
+
|
40
|
+
conn.adapter adapter, @stubs
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yadisk
|
4
|
+
class Collection
|
5
|
+
attr_reader :data, :items, :total, :limit, :offset
|
6
|
+
|
7
|
+
def self.from_response(response, key:, type:)
|
8
|
+
body = response.body
|
9
|
+
new(
|
10
|
+
data: body[key].map {|attrs| type.new(attrs) },
|
11
|
+
items: body["items"],
|
12
|
+
total: body["total"]
|
13
|
+
# limit: body.dig("limit"),
|
14
|
+
# offset: body.dig("offset")
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(data:, total:, items:)
|
19
|
+
@data = data
|
20
|
+
@items = items
|
21
|
+
@total = total
|
22
|
+
# @limit = limit.empty? ? nil : limit
|
23
|
+
# @offset = offset.empty? ? nil : offset
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/yadisk/error.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module Yadisk
|
6
|
+
class Object < OpenStruct
|
7
|
+
def initialize(attributes)
|
8
|
+
super to_ostruct(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Convert Array or Hash to OpenStruct
|
12
|
+
def to_ostruct(obj)
|
13
|
+
case obj
|
14
|
+
when Hash
|
15
|
+
# rubocop:disable Style/HashTransformValues
|
16
|
+
OpenStruct.new(obj.map {|key, val| [key, to_ostruct(val)] }.to_h)
|
17
|
+
# rubocop:enable Style/HashTransformValues
|
18
|
+
when Array
|
19
|
+
obj.map {|o| to_ostruct(o) }
|
20
|
+
else
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yadisk
|
4
|
+
class Resource < Object; end
|
5
|
+
class ResourceList < Object; end
|
6
|
+
class PublicResource < Object; end
|
7
|
+
class FilesResourceList < Object; end
|
8
|
+
class PublicResourceList < Object; end
|
9
|
+
class ResourceUploadLink < Object; end
|
10
|
+
class LastUploadedResourceList < Object; end
|
11
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yadisk
|
4
|
+
class DiskRest < Rest
|
5
|
+
def info
|
6
|
+
Disk.new get_request("disk").body
|
7
|
+
end
|
8
|
+
|
9
|
+
# TOOO: more test cases
|
10
|
+
def upload(path:)
|
11
|
+
path = Addressable::URI.parse(path).normalize
|
12
|
+
ResourceUploadLink.new get_request("disk/resources/upload?path=#{path}").body
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload_from_file(upload_link:, src:)
|
16
|
+
put_request(upload_link, body: File.open(src).read).success?
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload_by_url(path:, url:)
|
20
|
+
path = Addressable::URI.parse(path).normalize
|
21
|
+
url = Addressable::URI.parse(url).normalize
|
22
|
+
Link.new post_request("disk/resources/upload?path=#{path}&url=#{url}", body: "").body
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(path:)
|
26
|
+
path = Addressable::URI.parse(path).normalize
|
27
|
+
delete_request("disk/resources?path=#{path}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_meta(path:, **params)
|
31
|
+
path = Addressable::URI.parse(path).normalize
|
32
|
+
Resource.new get_request("disk/resources?path=#{path}", params: params).body
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_meta(path:, **attributes)
|
36
|
+
path = Addressable::URI.parse(path).normalize
|
37
|
+
payload = {custom_properties: attributes}
|
38
|
+
Resource.new patch_request("disk/resources?path=#{path}", body: payload).body
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_dir(path:)
|
42
|
+
path = Addressable::URI.parse(path).normalize
|
43
|
+
Link.new put_request("disk/resources?path=#{path}", body: "").body
|
44
|
+
end
|
45
|
+
|
46
|
+
def copy(from:, to:)
|
47
|
+
from = Addressable::URI.parse(from).normalize
|
48
|
+
to = Addressable::URI.parse(to).normalize
|
49
|
+
Link.new post_request("disk/resources/copy?from=#{from}&path=#{to}", body: "").body
|
50
|
+
end
|
51
|
+
|
52
|
+
def download(path:, **params)
|
53
|
+
path = Addressable::URI.parse(path).normalize
|
54
|
+
Link.new get_request("disk/resources/download?path=#{path}", params: params).body
|
55
|
+
end
|
56
|
+
|
57
|
+
def list_files(**params)
|
58
|
+
resp = get_request("disk/resources/files", params: params).body
|
59
|
+
Collection.from_response(resp, key: "items", type: FilesResourceList)
|
60
|
+
end
|
61
|
+
|
62
|
+
def last_uploaded(**params)
|
63
|
+
resp = get_request("disk/resources/last-uploaded", params: params)
|
64
|
+
Collection.from_response(resp, key: "items", type: LastUploadedResourceList)
|
65
|
+
end
|
66
|
+
|
67
|
+
def move(from:, to:)
|
68
|
+
from = Addressable::URI.parse(from).normalize
|
69
|
+
to = Addressable::URI.parse(to).normalize
|
70
|
+
Link.new post_request("disk/resources/move?from=#{from}&path=#{to}", body: "").body
|
71
|
+
end
|
72
|
+
|
73
|
+
def list_public(**params)
|
74
|
+
resp = get_request("disk/resources/public", params: params)
|
75
|
+
Collection.from_response(resp, key: "items", type: PublicResourcesList)
|
76
|
+
end
|
77
|
+
|
78
|
+
def publish(path:)
|
79
|
+
path = Addressable::URI.parse(path).normalize
|
80
|
+
Link.new put_request("disk/resources/publish?path=#{path}", body: "").body
|
81
|
+
end
|
82
|
+
|
83
|
+
def unpublish(path:)
|
84
|
+
path = Addressable::URI.parse(path).normalize
|
85
|
+
Link.new put_request("disk/resources/unpublish?path=#{path}", body: "").body
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yadisk
|
4
|
+
class PublicRest < Rest
|
5
|
+
def meta(public_url:, **params)
|
6
|
+
PublicResource.new get_request("disk/public/resources?public_key=#{public_url}", params: params).body
|
7
|
+
end
|
8
|
+
|
9
|
+
def link(public_url:, **params)
|
10
|
+
Link.new get_request("disk/public/resources/download?public_key=#{public_url}", params: params).body
|
11
|
+
end
|
12
|
+
|
13
|
+
def save(public_url:)
|
14
|
+
Link.new post_request("disk/public/resources/save-to-disk?public_key=#{public_url}", body: "").body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|