simple_gdrive 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +9 -1
- data/lib/simple_gdrive.rb +11 -2
- data/lib/simple_gdrive/authorizer.rb +1 -0
- data/lib/simple_gdrive/base.rb +0 -6
- data/lib/simple_gdrive/cleaner.rb +15 -3
- data/lib/simple_gdrive/trash_cleaner.rb +8 -0
- data/lib/simple_gdrive/uploader.rb +7 -0
- data/lib/simple_gdrive/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 830b1e3136947e662d8f01f0e6dd16a6c8d7e71f1b7826736b36723480f04e88
|
4
|
+
data.tar.gz: 5550817d094e9889c7d0e556549db3406966935d525fd883541c2f446cff1048
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74231e22e7fa5b71f2f5e7e2bd968919375423abd6213933901ec77501e32eb790b7c91ce13ac17e3fda0f74277cac34c19507340391299b3298c81e2632dbd7
|
7
|
+
data.tar.gz: f939245fd8c67e23ba1168317d94ca5cd378c83a5e7743e152ff69e042cbdb42e7f44d105b02620960267048c948fc4ca1fe19a634ea0f61a9e86c26e4a0e42c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -42,7 +42,7 @@ SimpleGdrive.configure do |config|
|
|
42
42
|
config.credential_file = Rails.root.join('config', 'credentials.yaml') # optional, default ~/.credentials/gdrive-uploader.yaml
|
43
43
|
end
|
44
44
|
```
|
45
|
-
3.
|
45
|
+
3. Call `Authorizer.call` in console and follow instructions to create `credentials.yaml`.
|
46
46
|
|
47
47
|
### File upload
|
48
48
|
```ruby
|
@@ -71,6 +71,14 @@ removes all files and folders in
|
|
71
71
|
SimpleGdrive.clear
|
72
72
|
```
|
73
73
|
|
74
|
+
option `move_to_trash`, default: `false`
|
75
|
+
|
76
|
+
### Trash clear
|
77
|
+
clears the user's trash bin
|
78
|
+
```ruby
|
79
|
+
SimpleGdrive.clear_trash
|
80
|
+
```
|
81
|
+
|
74
82
|
## Known issues
|
75
83
|
|
76
84
|
* incorrect behaviour with cyrillic symbols in filenames:
|
data/lib/simple_gdrive.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'simple_gdrive/version'
|
2
|
+
|
2
3
|
require 'simple_gdrive/authorizer'
|
3
4
|
require 'simple_gdrive/base'
|
4
5
|
require 'simple_gdrive/uploader'
|
5
6
|
require 'simple_gdrive/cleaner'
|
7
|
+
require 'simple_gdrive/trash_cleaner'
|
6
8
|
|
7
9
|
module SimpleGdrive
|
8
10
|
Config = Struct.new(
|
@@ -35,7 +37,14 @@ module SimpleGdrive
|
|
35
37
|
.call(full_filename, upload_source, content_type: content_type, mime_type: mime_type)
|
36
38
|
end
|
37
39
|
|
38
|
-
def self.clear
|
39
|
-
Cleaner.new(
|
40
|
+
def self.clear(move_to_trash: false)
|
41
|
+
Cleaner.new(
|
42
|
+
base_folder_id: config.base_folder_id,
|
43
|
+
move_to_trash: move_to_trash
|
44
|
+
).call
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.clear_trash
|
48
|
+
TrashCleaner.new.call
|
40
49
|
end
|
41
50
|
end
|
@@ -13,6 +13,7 @@ module SimpleGdrive
|
|
13
13
|
FileUtils.mkdir_p File.dirname(::SimpleGdrive.config.credential_file)
|
14
14
|
|
15
15
|
credentials = user_authorizer.get_credentials(DEFAULT_USER_ID)
|
16
|
+
# FIXME: rails?
|
16
17
|
credentials = request_credentials if credentials.nil? && defined?(Rails::Console)
|
17
18
|
|
18
19
|
credentials
|
data/lib/simple_gdrive/base.rb
CHANGED
@@ -2,12 +2,6 @@ require 'google/apis/drive_v3'
|
|
2
2
|
|
3
3
|
module SimpleGdrive
|
4
4
|
class Base
|
5
|
-
FOLDER_MIME_TYPE = 'application/vnd.google-apps.folder'.freeze
|
6
|
-
OPTIONS = {retries: 5}.freeze
|
7
|
-
|
8
|
-
def initialize(base_folder_id:)
|
9
|
-
@base_folder_id = base_folder_id
|
10
|
-
end
|
11
5
|
|
12
6
|
private
|
13
7
|
|
@@ -2,13 +2,19 @@ module SimpleGdrive
|
|
2
2
|
# Cleans the directory
|
3
3
|
# Returns array of removed file names
|
4
4
|
class Cleaner < Base
|
5
|
+
def initialize(base_folder_id:, move_to_trash: false)
|
6
|
+
@base_folder_id = base_folder_id
|
7
|
+
@move_to_trash = move_to_trash
|
8
|
+
end
|
9
|
+
|
5
10
|
def call
|
6
11
|
@page_token = nil
|
7
12
|
@files_to_remove = {}
|
8
13
|
|
9
|
-
|
14
|
+
loop do
|
10
15
|
fetch_batch
|
11
|
-
|
16
|
+
break if @page_token.nil?
|
17
|
+
end
|
12
18
|
|
13
19
|
remove_files
|
14
20
|
|
@@ -30,7 +36,13 @@ module SimpleGdrive
|
|
30
36
|
end
|
31
37
|
|
32
38
|
def remove_files
|
33
|
-
@files_to_remove.keys.each
|
39
|
+
@files_to_remove.keys.each do |id|
|
40
|
+
if @move_to_trash
|
41
|
+
service.update_file(id, {trashed: true}, {})
|
42
|
+
else
|
43
|
+
service.delete_file(id)
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
end
|
36
48
|
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module SimpleGdrive
|
2
2
|
# Uploads file
|
3
3
|
class Uploader < Base
|
4
|
+
FOLDER_MIME_TYPE = 'application/vnd.google-apps.folder'.freeze
|
5
|
+
OPTIONS = {retries: 5}.freeze
|
6
|
+
|
7
|
+
def initialize(base_folder_id:)
|
8
|
+
@base_folder_id = base_folder_id
|
9
|
+
end
|
10
|
+
|
4
11
|
def call(full_filename, upload_source, content_type:, mime_type: nil)
|
5
12
|
names = full_filename.split('/')
|
6
13
|
filename = names.pop
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_gdrive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/simple_gdrive/authorizer.rb
|
157
157
|
- lib/simple_gdrive/base.rb
|
158
158
|
- lib/simple_gdrive/cleaner.rb
|
159
|
+
- lib/simple_gdrive/trash_cleaner.rb
|
159
160
|
- lib/simple_gdrive/uploader.rb
|
160
161
|
- lib/simple_gdrive/version.rb
|
161
162
|
- simple_gdrive.gemspec
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
179
|
- !ruby/object:Gem::Version
|
179
180
|
version: '0'
|
180
181
|
requirements: []
|
181
|
-
rubygems_version: 3.0.
|
182
|
+
rubygems_version: 3.0.3
|
182
183
|
signing_key:
|
183
184
|
specification_version: 4
|
184
185
|
summary: Simple Google Drive file uploader
|