yandex_client 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/docker/Dockerfile.2.6 +1 -1
- data/lib/yandex_client.rb +4 -0
- data/lib/yandex_client/client.rb +3 -2
- data/lib/yandex_client/disk/client.rb +47 -0
- data/lib/yandex_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb3f0eb258b31efd0147df7db347df6d9bef47a24fcde9d84d44fdc4e033adb
|
4
|
+
data.tar.gz: 6ec4eb7101152d430ba1dd1ba73863b48a8e5ecd727fd1a9d28f9bcc6dd5975a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed4e0e3bf4d35c0796421c8ecde6653446628a909bc2a688acdc1f75ceedaa2c47820bfa95ae9b22b40ae52709d722f1dfb44a923e10ec7b82904b2d24d3126a
|
7
|
+
data.tar.gz: c2aa86695f8a5973d0ba86940ea7e916cfe65fe57934d4cdee4db3bb94d9083d2d1595ae8dded4021f253e6451909f308d845ef28fdfec2461c2ca86aab7e121
|
data/README.md
CHANGED
@@ -80,6 +80,21 @@ cli.propfind(name: '/a', depth: 1)
|
|
80
80
|
cli.propfind(name: '/', quota: true)
|
81
81
|
```
|
82
82
|
|
83
|
+
### [Yandex Disk Rest](https://yandex.ru/dev/disk/api/concepts/about-docpage/)
|
84
|
+
```ruby
|
85
|
+
cli = YandexClient::Disk::Client.new(access_token: 'your_token')
|
86
|
+
```
|
87
|
+
|
88
|
+
[info](https://yandex.ru/dev/disk/api/reference/capacity-docpage/)
|
89
|
+
```ruby
|
90
|
+
cli.info
|
91
|
+
```
|
92
|
+
|
93
|
+
[download_url](https://yandex.ru/dev/disk/api/reference/content-docpage/)
|
94
|
+
```ruby
|
95
|
+
cli.download_url(path: '/test')
|
96
|
+
```
|
97
|
+
|
83
98
|
## Development
|
84
99
|
|
85
100
|
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.
|
@@ -102,9 +117,6 @@ dip provision
|
|
102
117
|
dip rspec
|
103
118
|
```
|
104
119
|
|
105
|
-
## TODO
|
106
|
-
* docs...
|
107
|
-
|
108
120
|
## Contributing
|
109
121
|
|
110
122
|
Bug reports and pull requests are welcome on GitHub at https://github.com/yamax2/yandex_client.
|
data/docker/Dockerfile.2.6
CHANGED
@@ -8,6 +8,6 @@ RUN ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts
|
|
8
8
|
ENV BUNDLE_APP_CONFIG /app/.bundle
|
9
9
|
|
10
10
|
RUN echo 'gem: --no-rdoc --no-ri --no-document' > /root/.gemrc
|
11
|
-
RUN gem install 'bundler:2.
|
11
|
+
RUN gem install 'bundler:2.1.4' rubocop
|
12
12
|
|
13
13
|
WORKDIR /app
|
data/lib/yandex_client.rb
CHANGED
data/lib/yandex_client/client.rb
CHANGED
@@ -54,6 +54,7 @@ module YandexClient
|
|
54
54
|
|
55
55
|
def make_request(params)
|
56
56
|
request_uri = request_uri(params)
|
57
|
+
|
57
58
|
@body = request_body(params)
|
58
59
|
|
59
60
|
request = Object.const_get("Net::HTTP::#{http_method_for_action}").new(
|
@@ -77,8 +78,8 @@ module YandexClient
|
|
77
78
|
klass = ERRORS_BY_CODES.fetch(response.code.to_i, ApiRequestError)
|
78
79
|
|
79
80
|
raise klass.new(
|
80
|
-
error: result.is_a?(Hash) ? result
|
81
|
-
error_description: result.is_a?(Hash) ? result
|
81
|
+
error: result.is_a?(Hash) ? result.fetch(:error) : result,
|
82
|
+
error_description: result.is_a?(Hash) ? result[:error_description] || result[:description] : nil,
|
82
83
|
code: response.code.to_i
|
83
84
|
)
|
84
85
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YandexClient
|
4
|
+
module Disk
|
5
|
+
# https://yandex.ru/dev/disk/api/reference/capacity-docpage/
|
6
|
+
# https://yandex.ru/dev/disk/api/reference/content-docpage/
|
7
|
+
#
|
8
|
+
# cli = YandexClient::Dav::Client.new(access_token: access_token)
|
9
|
+
#
|
10
|
+
# cli.info
|
11
|
+
# cli.download_url(path: '/my_dir')
|
12
|
+
class Client < ::YandexClient::Client
|
13
|
+
ACTION_URL = 'https://cloud-api.yandex.net'
|
14
|
+
|
15
|
+
ACTIONS = {
|
16
|
+
info: '/v1/disk/',
|
17
|
+
download_url: '/v1/disk/resources/download'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
REQUIRED_PARAMS = {
|
21
|
+
download_url: %i[path]
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def initialize(access_token:)
|
25
|
+
@access_token = access_token
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def request_headers(_params)
|
31
|
+
{
|
32
|
+
Authorization: "OAuth #{@access_token}"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def request_uri(params)
|
37
|
+
if (required_params = REQUIRED_PARAMS[@action]) && !(missed_params = required_params - params.keys).empty?
|
38
|
+
raise "required params not found: \"#{missed_params.join(',')}\""
|
39
|
+
end
|
40
|
+
|
41
|
+
URI.parse("#{ACTION_URL}#{ACTIONS.fetch(@action)}").tap do |uri|
|
42
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Tretyakov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/yandex_client/client.rb
|
136
136
|
- lib/yandex_client/dav/client.rb
|
137
137
|
- lib/yandex_client/dav/propfind_parser.rb
|
138
|
+
- lib/yandex_client/disk/client.rb
|
138
139
|
- lib/yandex_client/not_found_error.rb
|
139
140
|
- lib/yandex_client/passport/client.rb
|
140
141
|
- lib/yandex_client/version.rb
|