yandex-disk 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +11 -0
- data/lib/yandex/disk/backup/storage.rb +45 -0
- data/lib/yandex/disk/client.rb +83 -0
- data/lib/yandex/disk/version.rb +7 -0
- data/lib/yandex/disk.rb +13 -0
- data/test/yandex_dist_test.rb +32 -0
- data/yandex-disk.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c71e6ea1679231d1f83ea5afeb8a2eb379f65b18
|
4
|
+
data.tar.gz: 8f92f22ce3ec568e9c5746a71ceb5c3a5d797bdf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dacd55bae8a4d95c9d2bfd77309ae5bf80595567f4cb3cece204a4d67e4ff56b15991fbe02ddcf6245cfbe31c4bbadbda5f9b9d1bb2b2f53a3c49dce670dd6f2
|
7
|
+
data.tar.gz: fbcafcd34a7a00d709ad6661ea0061a5c2bda0be542f0989cc436a70ce815a9fb457f83c94513e1c4004ad4f9e6ba2b3b33bdf5f6c620aeced4a48b93c179c49
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yury Korolev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Yandex::Disk gem
|
2
|
+
|
3
|
+
Dead simple ruby wrapper for [Yandex.Disk API](http://api.yandex.ru/disk/doc/dg/concepts/about.xml)
|
4
|
+
|
5
|
+
To get your `access_token`:
|
6
|
+
|
7
|
+
1. Register your app at [Yandex](https://oauth.yandex.ru/client/new)
|
8
|
+
1. Be sure to check 'Yandex.Disk permits'
|
9
|
+
2. Be sure to check 'Client for development' (it will set https://oauth.yandex.ru/verification_code?dev=True as `Callback URI`)
|
10
|
+
2. Get access token https://oauth.yandex.ru/authorize?response_type=token&client_id=YOUR_APP_ID
|
11
|
+
3. Get your access token from redirect url (right from the browser, it will be one of parameters)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'yandex-disk'
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
disk = Yandex::Disk::Client.new(:access_token => 'YOUR_ACCESS_TOKEN')
|
23
|
+
|
24
|
+
# to upload file to Yandex.Disk
|
25
|
+
disk.put('path/to/local/file', '/path/to/remote/file') # returns `true` if everything is ok
|
26
|
+
|
27
|
+
# to download file to Yandex.Disk
|
28
|
+
res = disk.get('/path/to/remote/file') # => res.body will contain file
|
29
|
+
|
30
|
+
# to make dir (only creates last part of path)
|
31
|
+
disk.mkdir('/path/to/remote/dir') # returns `true` if everything is ok
|
32
|
+
|
33
|
+
# to make full path
|
34
|
+
disk.mkdir_p('/path/to/remote/dir')
|
35
|
+
|
36
|
+
# remote file operations:
|
37
|
+
|
38
|
+
# copy file/dir
|
39
|
+
disk.copy('/path/to/remote/file/or/dir', '/path/to/new/remote/file/or/dir')
|
40
|
+
# move file/dir
|
41
|
+
disk.move('/path/to/remote/file/or/dir', '/path/to/new/remote/file/or/dir')
|
42
|
+
# delete file/dir
|
43
|
+
disk.delete('/path/to/remote/file/or/dir') # returns `true` if everything is ok
|
44
|
+
```
|
45
|
+
|
46
|
+
## Using it with [backup gem](https://github.com/meskyanichi/backup)
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'yandex/disk/backup/storage'
|
50
|
+
|
51
|
+
Backup::Model.new(:my_backup, 'Description for my_backup') do
|
52
|
+
split_into_chunks_of 250
|
53
|
+
|
54
|
+
database PostgreSQL do |db|
|
55
|
+
db.name = 'pg_db_name'
|
56
|
+
db.username = 'username'
|
57
|
+
db.password = 'password'
|
58
|
+
end
|
59
|
+
|
60
|
+
compress_with Gzip
|
61
|
+
|
62
|
+
store_with Yandex::Disk do |disk|
|
63
|
+
disk.access_token = 'YOUR_ACCESS_TOKEN'
|
64
|
+
disk.path = '/backups/'
|
65
|
+
disk.keep = 5
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
78
|
+
|
79
|
+
To run tests setup env var with your access_token and run `rake`
|
80
|
+
|
81
|
+
export YANDEX_DISK_TOKEN=e5d4aaa4ec2246558b510f7fef25b7b1
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'yandex/disk/client'
|
3
|
+
|
4
|
+
module Backup
|
5
|
+
module Storage
|
6
|
+
module Yandex
|
7
|
+
class Disk < Base
|
8
|
+
|
9
|
+
attr_accessor :access_token
|
10
|
+
|
11
|
+
def initialize(model, storage_id = nil, &block)
|
12
|
+
super
|
13
|
+
instance_eval(&block) if block_given?
|
14
|
+
@path ||= '/backups'
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
::Yandex::Disk::Client.new(:access_token => access_token)
|
19
|
+
end
|
20
|
+
|
21
|
+
def transfer!
|
22
|
+
disk = connection
|
23
|
+
disk.mkdir_p(remote_path)
|
24
|
+
package.filenames.each do |filename|
|
25
|
+
src = File.join(Config.tmp_path, filename)
|
26
|
+
dest = File.join(remote_path, filename)
|
27
|
+
Logger.info "Storing '#{ dest }'..."
|
28
|
+
disk.put(src, dest)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove!(package)
|
33
|
+
Logger.info "Removing backup package dated #{ package.time }..."
|
34
|
+
remote_path = remote_path_for(package)
|
35
|
+
connection.delete(remote_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def storage_name
|
39
|
+
'Yandex::Disk'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
module Yandex
|
7
|
+
module Disk
|
8
|
+
class Client
|
9
|
+
|
10
|
+
def initialize options={}
|
11
|
+
@http = Faraday.new(:url => 'https://webdav.yandex.ru') do |builder|
|
12
|
+
builder.request :authorization, "OAuth", options[:access_token]
|
13
|
+
|
14
|
+
builder.response :follow_redirects
|
15
|
+
|
16
|
+
if faraday_configurator = options[:faraday_configurator]
|
17
|
+
faraday_configurator.call(builder)
|
18
|
+
else
|
19
|
+
builder.adapter :excon
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def put src, dest
|
25
|
+
res = @http.put do |req|
|
26
|
+
req.url dest
|
27
|
+
req.headers['Content-Type'] = 'application/binary'
|
28
|
+
req.body = File.open(src)
|
29
|
+
end
|
30
|
+
res.success?
|
31
|
+
end
|
32
|
+
|
33
|
+
def mkcol path
|
34
|
+
request = @http.build_request('MKCOL') do |req|
|
35
|
+
req.url(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
env = request.to_env(@http)
|
39
|
+
res = @http.app.call(env)
|
40
|
+
res.success?
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :mkdir, :mkcol
|
44
|
+
|
45
|
+
def mkdir_p path
|
46
|
+
path_parts = []
|
47
|
+
path.split('/').each do |part|
|
48
|
+
path_parts << part
|
49
|
+
mkdir(path_parts.join('/'))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def get path
|
54
|
+
@http.get(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
def copy src, dest
|
58
|
+
file_operation 'COPY', src, dest
|
59
|
+
end
|
60
|
+
|
61
|
+
def move src, dest
|
62
|
+
file_operation 'MOVE', src, dest
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete path
|
66
|
+
@http.delete(path).success?
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def file_operation op, src, dest
|
72
|
+
request = @http.build_request(op) do |req|
|
73
|
+
req.url(path)
|
74
|
+
req.headers['Destination'] = dest
|
75
|
+
end
|
76
|
+
|
77
|
+
env = request.to_env(@http)
|
78
|
+
res = @http.app.call(env)
|
79
|
+
res.success?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/yandex/disk.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/yandex/disk')
|
3
|
+
|
4
|
+
class YandexDiskTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@disk = Yandex::Disk::Client.new access_token: ENV['YANDEX_DISK_TOKEN']
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initilize
|
11
|
+
assert @disk
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_put_and_get
|
15
|
+
assert @disk.put('README.md', '/README.md')
|
16
|
+
remote = @disk.get('/README.md')
|
17
|
+
assert_equal File.read('README.md'), remote.body
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_delete_and_mkdir
|
21
|
+
@disk.delete('/a')
|
22
|
+
assert !@disk.mkdir('/a/b')
|
23
|
+
assert @disk.mkdir('/a')
|
24
|
+
assert @disk.mkdir('/a/b')
|
25
|
+
assert @disk.delete('/a')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_put_in_nested_folder
|
29
|
+
assert !@disk.put('README.md', '/new_folder/README.md')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/yandex-disk.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yandex/disk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yandex-disk"
|
8
|
+
spec.version = Yandex::Disk::VERSION
|
9
|
+
spec.authors = ["Yury Korolev"]
|
10
|
+
spec.email = ["yurykorolev@me.com"]
|
11
|
+
spec.description = %q{Ruby client for Yandex.Disk}
|
12
|
+
spec.summary = %q{Ruby client for Yandex.Disk with backup gem support}
|
13
|
+
spec.homepage = "https://github.com/anjlab/yandex-disk"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency('faraday', '~> 0.8')
|
22
|
+
spec.add_dependency('faraday_middleware', '~> 0.9.0')
|
23
|
+
spec.add_dependency('excon', '>= 0.16')
|
24
|
+
|
25
|
+
spec.add_development_dependency('bundler', '~> 1.3')
|
26
|
+
spec.add_development_dependency('rake')
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yandex-disk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yury Korolev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: excon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.16'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby client for Yandex.Disk
|
84
|
+
email:
|
85
|
+
- yurykorolev@me.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/yandex/disk.rb
|
96
|
+
- lib/yandex/disk/backup/storage.rb
|
97
|
+
- lib/yandex/disk/client.rb
|
98
|
+
- lib/yandex/disk/version.rb
|
99
|
+
- test/yandex_dist_test.rb
|
100
|
+
- yandex-disk.gemspec
|
101
|
+
homepage: https://github.com/anjlab/yandex-disk
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.3
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby client for Yandex.Disk with backup gem support
|
125
|
+
test_files:
|
126
|
+
- test/yandex_dist_test.rb
|