rb1drv 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.travis.yml +6 -6
- data/Gemfile +3 -3
- data/Gemfile.lock +36 -36
- data/README.md +78 -78
- data/lib/rb1drv/auth.rb +33 -33
- data/lib/rb1drv/onedrive.rb +20 -20
- data/lib/rb1drv/onedrive_404.rb +20 -20
- data/lib/rb1drv/onedrive_dir.rb +228 -225
- data/lib/rb1drv/onedrive_file.rb +79 -79
- data/lib/rb1drv/onedrive_item.rb +67 -68
- data/lib/rb1drv/sliced_io.rb +38 -38
- data/lib/rb1drv/version.rb +3 -3
- data/lib/rb1drv.rb +59 -59
- data/rb1drv.gemspec +28 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c15688834990d2c5aa36ff5c031e113a3260cf83f2a2cd9a02f944ba08058bd
|
4
|
+
data.tar.gz: 62f70bec1309f597448b0354c533f7098d0018e02a7ac5a41055742c28579dd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f9b04494e473825f9e9d82ae802b5861cc56b577d2649b2a6d25361002d096857e81ff5acee54e26306e00bc92d133d09938edf85475c916831753c898604b4
|
7
|
+
data.tar.gz: 0eab0240e2562dc8cfb1b1fc9c320d129b6c5f6ce0b86dbba1ae46281f81e66ea65749a15459eaf5768d6913b88b3256eb88feca1e21f1d392b3fe8dbdd75530
|
data/.gitignore
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.3
|
4
|
-
- 2.4
|
5
|
-
- 2.5
|
6
|
-
script: bundle exec ruby -I lib lib/rb1drv.rb
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3
|
4
|
+
- 2.4
|
5
|
+
- 2.5
|
6
|
+
script: bundle exec ruby -I lib lib/rb1drv.rb
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rb1drv (0.1.
|
5
|
-
excon (~> 0.62)
|
6
|
-
oauth2 (~> 1.4)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
excon (0.62.0)
|
12
|
-
faraday (0.12.2)
|
13
|
-
multipart-post (>= 1.2, < 3)
|
14
|
-
jwt (1.5.6)
|
15
|
-
multi_json (1.13.1)
|
16
|
-
multi_xml (0.6.0)
|
17
|
-
multipart-post (2.0.0)
|
18
|
-
oauth2 (1.4.0)
|
19
|
-
faraday (>= 0.8, < 0.13)
|
20
|
-
jwt (~> 1.0)
|
21
|
-
multi_json (~> 1.3)
|
22
|
-
multi_xml (~> 0.5)
|
23
|
-
rack (>= 1.2, < 3)
|
24
|
-
rack (2.0.5)
|
25
|
-
rake (10.5.0)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
bundler (~> 1.16)
|
32
|
-
rake (~> 10.0)
|
33
|
-
rb1drv!
|
34
|
-
|
35
|
-
BUNDLED WITH
|
36
|
-
1.16.1
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rb1drv (0.1.8)
|
5
|
+
excon (~> 0.62)
|
6
|
+
oauth2 (~> 1.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
excon (0.62.0)
|
12
|
+
faraday (0.12.2)
|
13
|
+
multipart-post (>= 1.2, < 3)
|
14
|
+
jwt (1.5.6)
|
15
|
+
multi_json (1.13.1)
|
16
|
+
multi_xml (0.6.0)
|
17
|
+
multipart-post (2.0.0)
|
18
|
+
oauth2 (1.4.0)
|
19
|
+
faraday (>= 0.8, < 0.13)
|
20
|
+
jwt (~> 1.0)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
multi_xml (~> 0.5)
|
23
|
+
rack (>= 1.2, < 3)
|
24
|
+
rack (2.0.5)
|
25
|
+
rake (10.5.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
rake (~> 10.0)
|
33
|
+
rb1drv!
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.16.1
|
data/README.md
CHANGED
@@ -1,78 +1,78 @@
|
|
1
|
-
# Rb1drv
|
2
|
-
|
3
|
-
[![Build Status](https://travis-ci.org/msg7086/rb1drv.svg?branch=master)](https://travis-ci.org/msg7086/rb1drv)
|
4
|
-
|
5
|
-
Rb1drv is a Ruby SDK for Microsoft OneDrive service, providing a simple interface to access files inside OneDrive.
|
6
|
-
|
7
|
-
Rb1drv allows you to list directories, upload or download files, etc.
|
8
|
-
|
9
|
-
To use the command line application, install [`rb1drv-tools`](https://github.com/msg7086/rb1drv-tools) gem instead.
|
10
|
-
|
11
|
-
Further functionalities can be added to the library upon requests.
|
12
|
-
|
13
|
-
Rb1drv uses the latest Microsoft OAuth2 + Graph API at the time it is written, while there are not many other libraries available for reference (e.g. official OneDrive SDK still uses old OAuth2 API instead of new OAuth2 v2.0 API). Feel free to take this as an unoffical reference implementation and write your own SDK.
|
14
|
-
|
15
|
-
## Installation
|
16
|
-
|
17
|
-
Add this line to your application's Gemfile:
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
gem 'rb1drv'
|
21
|
-
```
|
22
|
-
|
23
|
-
And then execute:
|
24
|
-
|
25
|
-
$ bundle
|
26
|
-
|
27
|
-
Or install it yourself as:
|
28
|
-
|
29
|
-
$ gem install rb1drv
|
30
|
-
|
31
|
-
## Usage
|
32
|
-
|
33
|
-
You will have to register a new application on Microsoft Application Registration Portal before using the API.
|
34
|
-
Read more at [OneDrive API Docs](https://github.com/OneDrive/onedrive-api-docs/blob/live/docs/rest-api/getting-started/graph-oauth.md).
|
35
|
-
|
36
|
-
od = OneDrive.new('a2b3c4d5-your-app-id', 'C8V3{your-app-secret(', 'https://your-callback/url')
|
37
|
-
|
38
|
-
To start using `OneDrive` library, instanciate the class with your application information.
|
39
|
-
|
40
|
-
---
|
41
|
-
|
42
|
-
od.root
|
43
|
-
od.get('/Folder1')
|
44
|
-
od.get('/File1.avi')
|
45
|
-
|
46
|
-
Use `OneDrive#root` or `OneDrive#get` to get a drive item.
|
47
|
-
|
48
|
-
---
|
49
|
-
|
50
|
-
od.root.children
|
51
|
-
od.root.children.grep(OneDriveDir)
|
52
|
-
|
53
|
-
Use `OneDriveDir#children` to get contents of a directory.
|
54
|
-
|
55
|
-
---
|
56
|
-
|
57
|
-
od.get('/File1.avi').save_as('/tmp/test.avi', overwrite: true) do |event, stat|
|
58
|
-
puts "Downloaded #{stat[:progress]} of #{stat[:total]}" if event == :progress
|
59
|
-
end
|
60
|
-
|
61
|
-
Use `OneDriveFile#save_as` to download a file.
|
62
|
-
|
63
|
-
---
|
64
|
-
|
65
|
-
od.get('/Folder1').upload('/tmp/test.avi', overwrite: true, target_name: 'party.avi') do |event, stat|
|
66
|
-
puts "Uploading #{stat[:progress]} of #{stat[:total]} for segment #{stat[:from]}-#{stat[:to]}" if event == :progress
|
67
|
-
puts "Uploaded segment #{stat[:from]}-#{stat[:to]}" if event == :finish_segment
|
68
|
-
end
|
69
|
-
|
70
|
-
Use `OneDriveDir#upload` to upload a file to target directory.
|
71
|
-
|
72
|
-
## Contributing
|
73
|
-
|
74
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/msg7086/rb1drv.
|
75
|
-
|
76
|
-
## License
|
77
|
-
|
78
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1
|
+
# Rb1drv
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/msg7086/rb1drv.svg?branch=master)](https://travis-ci.org/msg7086/rb1drv)
|
4
|
+
|
5
|
+
Rb1drv is a Ruby SDK for Microsoft OneDrive service, providing a simple interface to access files inside OneDrive.
|
6
|
+
|
7
|
+
Rb1drv allows you to list directories, upload or download files, etc.
|
8
|
+
|
9
|
+
To use the command line application, install [`rb1drv-tools`](https://github.com/msg7086/rb1drv-tools) gem instead.
|
10
|
+
|
11
|
+
Further functionalities can be added to the library upon requests.
|
12
|
+
|
13
|
+
Rb1drv uses the latest Microsoft OAuth2 + Graph API at the time it is written, while there are not many other libraries available for reference (e.g. official OneDrive SDK still uses old OAuth2 API instead of new OAuth2 v2.0 API). Feel free to take this as an unoffical reference implementation and write your own SDK.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'rb1drv'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install rb1drv
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
You will have to register a new application on Microsoft Application Registration Portal before using the API.
|
34
|
+
Read more at [OneDrive API Docs](https://github.com/OneDrive/onedrive-api-docs/blob/live/docs/rest-api/getting-started/graph-oauth.md).
|
35
|
+
|
36
|
+
od = OneDrive.new('a2b3c4d5-your-app-id', 'C8V3{your-app-secret(', 'https://your-callback/url')
|
37
|
+
|
38
|
+
To start using `OneDrive` library, instanciate the class with your application information.
|
39
|
+
|
40
|
+
---
|
41
|
+
|
42
|
+
od.root
|
43
|
+
od.get('/Folder1')
|
44
|
+
od.get('/File1.avi')
|
45
|
+
|
46
|
+
Use `OneDrive#root` or `OneDrive#get` to get a drive item.
|
47
|
+
|
48
|
+
---
|
49
|
+
|
50
|
+
od.root.children
|
51
|
+
od.root.children.grep(OneDriveDir)
|
52
|
+
|
53
|
+
Use `OneDriveDir#children` to get contents of a directory.
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
od.get('/File1.avi').save_as('/tmp/test.avi', overwrite: true) do |event, stat|
|
58
|
+
puts "Downloaded #{stat[:progress]} of #{stat[:total]}" if event == :progress
|
59
|
+
end
|
60
|
+
|
61
|
+
Use `OneDriveFile#save_as` to download a file.
|
62
|
+
|
63
|
+
---
|
64
|
+
|
65
|
+
od.get('/Folder1').upload('/tmp/test.avi', overwrite: true, target_name: 'party.avi') do |event, stat|
|
66
|
+
puts "Uploading #{stat[:progress]} of #{stat[:total]} for segment #{stat[:from]}-#{stat[:to]}" if event == :progress
|
67
|
+
puts "Uploaded segment #{stat[:from]}-#{stat[:to]}" if event == :finish_segment
|
68
|
+
end
|
69
|
+
|
70
|
+
Use `OneDriveDir#upload` to upload a file to target directory.
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/msg7086/rb1drv.
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/rb1drv/auth.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
module Rb1drv
|
2
|
-
class OneDrive
|
3
|
-
# Gets authorize URL to start authentication process
|
4
|
-
#
|
5
|
-
# @return [String] the authorize URL
|
6
|
-
def auth_url
|
7
|
-
@oauth2_client.auth_code.authorize_url(
|
8
|
-
redirect_uri: @callback_url,
|
9
|
-
scope: 'openid offline_access https://graph.microsoft.com/Files.ReadWrite.All'
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Gets access token from authorize code
|
14
|
-
#
|
15
|
-
# @return [OAuth2::AccessToken] the access token
|
16
|
-
def auth_access(auth_code)
|
17
|
-
@access_token = @oauth2_client.auth_code.get_token(auth_code, redirect_uri: @callback_url)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Loads previously retrieved access token from Hash
|
21
|
-
#
|
22
|
-
# @return [OAuth2::AccessToken] the access token
|
23
|
-
def auth_load(access_token)
|
24
|
-
@access_token = OAuth2::AccessToken.from_hash(@oauth2_client, access_token)
|
25
|
-
@access_token = @access_token.refresh! if @access_token.expired?
|
26
|
-
@access_token
|
27
|
-
end
|
28
|
-
|
29
|
-
def auth_check
|
30
|
-
@access_token = @access_token.refresh! if @access_token.expired?
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
module Rb1drv
|
2
|
+
class OneDrive
|
3
|
+
# Gets authorize URL to start authentication process
|
4
|
+
#
|
5
|
+
# @return [String] the authorize URL
|
6
|
+
def auth_url
|
7
|
+
@oauth2_client.auth_code.authorize_url(
|
8
|
+
redirect_uri: @callback_url,
|
9
|
+
scope: 'openid offline_access https://graph.microsoft.com/Files.ReadWrite.All'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets access token from authorize code
|
14
|
+
#
|
15
|
+
# @return [OAuth2::AccessToken] the access token
|
16
|
+
def auth_access(auth_code)
|
17
|
+
@access_token = @oauth2_client.auth_code.get_token(auth_code, redirect_uri: @callback_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Loads previously retrieved access token from Hash
|
21
|
+
#
|
22
|
+
# @return [OAuth2::AccessToken] the access token
|
23
|
+
def auth_load(access_token)
|
24
|
+
@access_token = OAuth2::AccessToken.from_hash(@oauth2_client, access_token)
|
25
|
+
@access_token = @access_token.refresh! if @access_token.expired?
|
26
|
+
@access_token
|
27
|
+
end
|
28
|
+
|
29
|
+
def auth_check
|
30
|
+
@access_token = @access_token.refresh! if @access_token.expired?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/rb1drv/onedrive.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
module Rb1drv
|
2
|
-
class OneDrive
|
3
|
-
# Get root directory object.
|
4
|
-
#
|
5
|
-
# @return [OneDriveDir] your root
|
6
|
-
def root
|
7
|
-
@_root_dir ||= OneDriveDir.new(self, request('drive/root'))
|
8
|
-
end
|
9
|
-
|
10
|
-
# Get an object by an arbitary path.
|
11
|
-
#
|
12
|
-
# TODO: API endpoint does not play well with remote files
|
13
|
-
#
|
14
|
-
# @return [OneDriveDir,OneDriveFile] the drive item you asked
|
15
|
-
def get(path)
|
16
|
-
path = "/#{path}" unless path[0] == '/'
|
17
|
-
OneDriveItem.smart_new(self, request("drive/root:#{path}"))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Rb1drv
|
2
|
+
class OneDrive
|
3
|
+
# Get root directory object.
|
4
|
+
#
|
5
|
+
# @return [OneDriveDir] your root
|
6
|
+
def root
|
7
|
+
@_root_dir ||= OneDriveDir.new(self, request('drive/root'))
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get an object by an arbitary path.
|
11
|
+
#
|
12
|
+
# TODO: API endpoint does not play well with remote files
|
13
|
+
#
|
14
|
+
# @return [OneDriveDir,OneDriveFile] the drive item you asked
|
15
|
+
def get(path)
|
16
|
+
path = "/#{path}" unless path[0] == '/'
|
17
|
+
OneDriveItem.smart_new(self, request("drive/root:#{path}"))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rb1drv/onedrive_404.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
module Rb1drv
|
2
|
-
class OneDrive404 < OneDriveItem
|
3
|
-
def initialize(*_)
|
4
|
-
end
|
5
|
-
|
6
|
-
def id
|
7
|
-
'_FILE_NOT_FOUND_'
|
8
|
-
end
|
9
|
-
|
10
|
-
# No
|
11
|
-
def dir?
|
12
|
-
false
|
13
|
-
end
|
14
|
-
|
15
|
-
# No
|
16
|
-
def file?
|
17
|
-
false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Rb1drv
|
2
|
+
class OneDrive404 < OneDriveItem
|
3
|
+
def initialize(*_)
|
4
|
+
end
|
5
|
+
|
6
|
+
def id
|
7
|
+
'_FILE_NOT_FOUND_'
|
8
|
+
end
|
9
|
+
|
10
|
+
# No
|
11
|
+
def dir?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
# No
|
16
|
+
def file?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|