yandex-disk 0.0.4 → 0.0.5
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/README.md +11 -2
- data/lib/yandex/disk/client.rb +20 -1
- data/lib/yandex/disk/client/request.rb +4 -0
- data/lib/yandex/disk/client/request/list.rb +89 -0
- data/lib/yandex/disk/client/request/space.rb +56 -0
- data/lib/yandex/disk/version.rb +1 -1
- data/yandex-disk.gemspec +3 -2
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23dcd981d7eb0cc5b888019fd9807d936b7dfe3c
|
4
|
+
data.tar.gz: 1a39ad88ca3b303cdc1c9e8f13958a79bc0d5ee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2539167f83cb414f64e790a923f39dd2a024266e3efe7e753cb22e55678b0a885ec75329a260bd1290fa95b18a8e01cb9bc1b96835947275c9fbbd03dd0731a
|
7
|
+
data.tar.gz: 86d90585dc811a40d49f333076fcade0bd9c9a92b3044ec9fed4228ebdb15508a4954a6754bcb0632b9ad191bc2b2f93460cff7a2daa80d6c3bcccd9eb1b6c60
|
data/README.md
CHANGED
@@ -19,8 +19,12 @@ Add this line to your application's Gemfile:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
```ruby
|
22
|
+
# authorize via oauth access token...
|
22
23
|
disk = Yandex::Disk::Client.new(:access_token => 'YOUR_ACCESS_TOKEN')
|
23
24
|
|
25
|
+
# ...or use login password for authorization
|
26
|
+
disk = Yandex::Disk::Client.new(:login => 'me', :password => 'secret')
|
27
|
+
|
24
28
|
# to upload file to Yandex.Disk
|
25
29
|
disk.put('path/to/local/file', '/path/to/remote/file') # returns `true` if everything is ok
|
26
30
|
|
@@ -41,6 +45,12 @@ disk.copy('/path/to/remote/file/or/dir', '/path/to/new/remote/file/or/dir')
|
|
41
45
|
disk.move('/path/to/remote/file/or/dir', '/path/to/new/remote/file/or/dir')
|
42
46
|
# delete file/dir
|
43
47
|
disk.delete('/path/to/remote/file/or/dir') # returns `true` if everything is ok
|
48
|
+
|
49
|
+
# to get quotas
|
50
|
+
disk.space # returns hash like { :quota_available_bytes => 2488943615, :quota_used_bytes => 2488943615 }
|
51
|
+
|
52
|
+
# to get dir contents
|
53
|
+
disk.list('/') # returns array with hashes like [{:href=>"/",:resourcetype=>:collection,:getlastmodified=><DateTime>,:getcontentlength=>0,:displayname=>"disk",:creationdate=><DateTime>},{:href=>"/readme.pdf",:getlastmodified=><DateTime>,:getcontentlength=>455833,:displayname=>"readme.pdf",:creationdate=><DateTime>}]
|
44
54
|
```
|
45
55
|
|
46
56
|
## Using it with [backup gem](https://github.com/meskyanichi/backup)
|
@@ -49,7 +59,7 @@ disk.delete('/path/to/remote/file/or/dir') # returns `true` if everything is ok
|
|
49
59
|
require 'yandex/disk/backup/storage'
|
50
60
|
|
51
61
|
Backup::Model.new(:my_backup, 'Description for my_backup') do
|
52
|
-
split_into_chunks_of
|
62
|
+
split_into_chunks_of 50
|
53
63
|
|
54
64
|
database PostgreSQL do |db|
|
55
65
|
db.name = 'pg_db_name'
|
@@ -64,7 +74,6 @@ Backup::Model.new(:my_backup, 'Description for my_backup') do
|
|
64
74
|
disk.path = '/backups/'
|
65
75
|
disk.keep = 5
|
66
76
|
end
|
67
|
-
|
68
77
|
end
|
69
78
|
```
|
70
79
|
|
data/lib/yandex/disk/client.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require 'base64'
|
3
4
|
require 'faraday'
|
4
5
|
require 'faraday_middleware'
|
5
6
|
|
7
|
+
Faraday::Connection::METHODS << :propfind
|
8
|
+
|
6
9
|
module Yandex
|
7
10
|
module Disk
|
8
11
|
class Client
|
12
|
+
autoload :Request, 'yandex/disk/client/request'
|
9
13
|
|
10
14
|
def initialize options={}
|
11
15
|
@timeout = options[:timeout] || 300
|
12
16
|
@http = Faraday.new(:url => 'https://webdav.yandex.ru') do |builder|
|
13
|
-
|
17
|
+
if options[:access_token].present?
|
18
|
+
builder.request :authorization, "OAuth", options[:access_token]
|
19
|
+
else
|
20
|
+
basic_token = Base64.encode64("#{options[:login]}:#{options[:password]}")
|
21
|
+
builder.request :authorization, "Basic", basic_token
|
22
|
+
end
|
14
23
|
|
15
24
|
builder.response :follow_redirects
|
16
25
|
|
@@ -44,6 +53,16 @@ module Yandex
|
|
44
53
|
@http.get(path)
|
45
54
|
end
|
46
55
|
|
56
|
+
def space
|
57
|
+
request = Request::Space.new(@http)
|
58
|
+
request.perform
|
59
|
+
end
|
60
|
+
|
61
|
+
def list path
|
62
|
+
request = Request::List.new(@http, path)
|
63
|
+
request.perform
|
64
|
+
end
|
65
|
+
|
47
66
|
alias_method :mkdir, :mkcol
|
48
67
|
|
49
68
|
def mkdir_p path
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class Yandex::Disk::Client::Request::List
|
4
|
+
HEADERS = {
|
5
|
+
:Depth => 1
|
6
|
+
}
|
7
|
+
|
8
|
+
def initialize http, path
|
9
|
+
@http = http
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform
|
14
|
+
response = @http.run_request :propfind, @path, nil, HEADERS
|
15
|
+
parse_result = parse(response.body)
|
16
|
+
parse_result.list
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
class ListParser < Nokogiri::XML::SAX::Document
|
23
|
+
attr_reader :list
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@list = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_element name, attributes = []
|
30
|
+
case name
|
31
|
+
when 'd:href'
|
32
|
+
@current = {}
|
33
|
+
@is_href = true
|
34
|
+
|
35
|
+
when 'd:displayname'
|
36
|
+
@is_displayname = true
|
37
|
+
|
38
|
+
when 'd:getcontentlength'
|
39
|
+
@is_getcontentlength = true
|
40
|
+
|
41
|
+
when 'd:creationdate'
|
42
|
+
@is_creationdate = true
|
43
|
+
|
44
|
+
when 'd:getlastmodified'
|
45
|
+
@is_getlastmodified = true
|
46
|
+
|
47
|
+
when 'd:collection'
|
48
|
+
@current[:resourcetype] = :collection
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def end_element name, attributes = []
|
53
|
+
case name
|
54
|
+
when 'd:href'
|
55
|
+
@list << @current if @current
|
56
|
+
@is_href = false
|
57
|
+
|
58
|
+
when 'd:displayname'
|
59
|
+
@is_displayname = false
|
60
|
+
|
61
|
+
when 'd:getcontentlength'
|
62
|
+
@is_getcontentlength = false
|
63
|
+
|
64
|
+
when 'd:creationdate'
|
65
|
+
@is_creationdate = false
|
66
|
+
|
67
|
+
when 'd:getlastmodified'
|
68
|
+
@is_getlastmodified = false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def characters string
|
73
|
+
@current[:href] = string if @is_href
|
74
|
+
@current[:displayname] = string if @is_displayname
|
75
|
+
@current[:getcontentlength] = string.to_i if @is_getcontentlength
|
76
|
+
@current[:creationdate] = DateTime.parse(string) if @is_creationdate
|
77
|
+
@current[:getlastmodified] = DateTime.parse(string) if @is_getlastmodified
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse body
|
82
|
+
list_parser = ListParser.new
|
83
|
+
|
84
|
+
parser = Nokogiri::XML::SAX::Parser.new(list_parser)
|
85
|
+
parser.parse(body)
|
86
|
+
|
87
|
+
list_parser
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class Yandex::Disk::Client::Request::Space
|
4
|
+
BODY = '<D:propfind xmlns:D="DAV:">
|
5
|
+
<D:prop>
|
6
|
+
<D:quota-available-bytes/>
|
7
|
+
<D:quota-used-bytes/>
|
8
|
+
</D:prop>
|
9
|
+
</D:propfind>'
|
10
|
+
HEADERS = {
|
11
|
+
:Depth => 0
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize http
|
15
|
+
@http = http
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform
|
19
|
+
response = @http.run_request :propfind, '/', BODY, HEADERS
|
20
|
+
parse_result = parse(response.body)
|
21
|
+
{
|
22
|
+
:quota_available_bytes => parse_result.quota_available_bytes,
|
23
|
+
:quota_used_bytes => parse_result.quota_used_bytes
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
class AttriutesParser < Nokogiri::XML::SAX::Document
|
31
|
+
attr_reader :quota_available_bytes, :quota_used_bytes
|
32
|
+
|
33
|
+
def start_element name, attributes = []
|
34
|
+
case name
|
35
|
+
when 'd:quota-used-bytes'
|
36
|
+
@is_quota_used_bytes = true
|
37
|
+
when 'd:quota-available-bytes'
|
38
|
+
@is_quota_available_bytes = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def characters string
|
43
|
+
@quota_used_bytes = string.to_i if @is_quota_used_bytes
|
44
|
+
@quota_available_bytes = string.to_i if @is_quota_available_bytes
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse body
|
49
|
+
attributes_parser = AttriutesParser.new
|
50
|
+
|
51
|
+
parser = Nokogiri::XML::SAX::Parser.new(attributes_parser)
|
52
|
+
parser.parse(body)
|
53
|
+
|
54
|
+
attributes_parser
|
55
|
+
end
|
56
|
+
end
|
data/lib/yandex/disk/version.rb
CHANGED
data/yandex-disk.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'yandex/disk/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "yandex-disk"
|
8
8
|
spec.version = Yandex::Disk::VERSION
|
9
|
-
spec.authors = ["Yury Korolev"]
|
10
|
-
spec.email = ["yurykorolev@me.com"]
|
9
|
+
spec.authors = ["Yury Korolev", "Alexandr Borisov"]
|
10
|
+
spec.email = ["yurykorolev@me.com", "aishek@gmail.com"]
|
11
11
|
spec.description = %q{Ruby client for Yandex.Disk}
|
12
12
|
spec.summary = %q{Ruby client for Yandex.Disk with backup gem support}
|
13
13
|
spec.homepage = "https://github.com/anjlab/yandex-disk"
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency('faraday', '~> 0.8')
|
22
|
+
spec.add_dependency('nokogiri', '~> 1.6.0')
|
22
23
|
spec.add_dependency('faraday_middleware', '~> 0.9.0')
|
23
24
|
spec.add_dependency('excon', '>= 0.16')
|
24
25
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex-disk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Korolev
|
8
|
+
- Alexandr Borisov
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: faraday
|
@@ -24,6 +25,20 @@ dependencies:
|
|
24
25
|
- - ~>
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0.8'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.6.0
|
27
42
|
- !ruby/object:Gem::Dependency
|
28
43
|
name: faraday_middleware
|
29
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +98,7 @@ dependencies:
|
|
83
98
|
description: Ruby client for Yandex.Disk
|
84
99
|
email:
|
85
100
|
- yurykorolev@me.com
|
101
|
+
- aishek@gmail.com
|
86
102
|
executables: []
|
87
103
|
extensions: []
|
88
104
|
extra_rdoc_files: []
|
@@ -95,6 +111,9 @@ files:
|
|
95
111
|
- lib/yandex/disk.rb
|
96
112
|
- lib/yandex/disk/backup/storage.rb
|
97
113
|
- lib/yandex/disk/client.rb
|
114
|
+
- lib/yandex/disk/client/request.rb
|
115
|
+
- lib/yandex/disk/client/request/list.rb
|
116
|
+
- lib/yandex/disk/client/request/space.rb
|
98
117
|
- lib/yandex/disk/version.rb
|
99
118
|
- test/yandex_dist_test.rb
|
100
119
|
- yandex-disk.gemspec
|