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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d902a5c411c4653ff785e6823688a329bafaa54704ea6cfa4879d1ef4e8b5008
4
- data.tar.gz: e33b580013b636094743b6454d152bb304c899e7a65dd0d90a243a02112cfe69
3
+ metadata.gz: 830b1e3136947e662d8f01f0e6dd16a6c8d7e71f1b7826736b36723480f04e88
4
+ data.tar.gz: 5550817d094e9889c7d0e556549db3406966935d525fd883541c2f446cff1048
5
5
  SHA512:
6
- metadata.gz: 831787d7e1206a592a5d61fc4f0e9d1a953f3808d687a21b626d3ac9a959fafbef8c970d09e8ed4508f037d16277570139dc41a52bd71ceb77aaaebe864e6b8a
7
- data.tar.gz: d9834b0484a72c5ba19e7e5c8441d152eb3a687719201fa7bc4e17b91ad81ee564e0911364535643805310314eb1b0aaff4232377a8f59676214e8e308ee7736
6
+ metadata.gz: 74231e22e7fa5b71f2f5e7e2bd968919375423abd6213933901ec77501e32eb790b7c91ce13ac17e3fda0f74277cac34c19507340391299b3298c81e2632dbd7
7
+ data.tar.gz: f939245fd8c67e23ba1168317d94ca5cd378c83a5e7743e152ff69e042cbdb42e7f44d105b02620960267048c948fc4ca1fe19a634ea0f61a9e86c26e4a0e42c
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.6.1
4
+ - 2.6.2
5
5
  before_install: gem install bundler
6
6
  before_script:
7
7
  - bundle install
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. Start uploading test file from rails console and follow instructions to create `credentials.yaml`.
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:
@@ -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(base_folder_id: config.base_folder_id).call
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
@@ -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
- begin
14
+ loop do
10
15
  fetch_batch
11
- end until @page_token.nil?
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 { |id| service.delete_file(id) }
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
@@ -0,0 +1,8 @@
1
+ module SimpleGdrive
2
+ # cleans then user's trash bin
3
+ class TrashCleaner < Base
4
+ def call
5
+ service.empty_file_trash
6
+ end
7
+ end
8
+ 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
@@ -1,3 +1,3 @@
1
1
  module SimpleGdrive
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
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.5.1
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-02-12 00:00:00.000000000 Z
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.1
182
+ rubygems_version: 3.0.3
182
183
  signing_key:
183
184
  specification_version: 4
184
185
  summary: Simple Google Drive file uploader