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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ff2e1ef6c319dbb6dfe2443e6d30eaeb3c8d4151898464909e91b30d1b00590
4
- data.tar.gz: b3d1e8182e4bd59b491304b3a8d43ff135f4af1cf6245d2af8c2e926d787f738
3
+ metadata.gz: 6bb3f0eb258b31efd0147df7db347df6d9bef47a24fcde9d84d44fdc4e033adb
4
+ data.tar.gz: 6ec4eb7101152d430ba1dd1ba73863b48a8e5ecd727fd1a9d28f9bcc6dd5975a
5
5
  SHA512:
6
- metadata.gz: 2095d85ea6b36bc5151ead67fac45420bcf18763d1e342294475dee157e3ce9e2fb71c8bf33ffbe50a7df9dc80dc2e7dde564a6dc658d37d2787455f91f69c51
7
- data.tar.gz: 915b9297b9bb13d2d32c80f6a33faec3354b5d296dba643693c90fc021598fa09def3dbb0f844d58d29afd02e3dec7b544c388a2dab5cdadac2a73b2ef75829b
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.
@@ -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.0.2' rubocop
11
+ RUN gem install 'bundler:2.1.4' rubocop
12
12
 
13
13
  WORKDIR /app
data/lib/yandex_client.rb CHANGED
@@ -21,6 +21,10 @@ module YandexClient
21
21
  autoload :Client, 'yandex_client/auth/client'
22
22
  end
23
23
 
24
+ module Disk
25
+ autoload :Client, 'yandex_client/disk/client'
26
+ end
27
+
24
28
  module Passport
25
29
  autoload :Client, 'yandex_client/passport/client'
26
30
  end
@@ -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&.fetch(:error) : result,
81
- error_description: result.is_a?(Hash) ? result&.fetch(:error_description) : nil,
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YandexClient
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  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.1.2
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: 2019-12-23 00:00:00.000000000 Z
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