simple_gdrive 0.4.0 → 0.5.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: 2deb1b8f04443033e24dca718a8fda59d4a5121b5d5e1b48ac1cc7bf54c64bbf
4
- data.tar.gz: edf2eb26eb05a6e6f150759a5e83fa8b6bf3a688f6d1fc4c96c7ba189b33e118
3
+ metadata.gz: 2879e311aa9ed8e6532eaf6867f854fd9de9874953d79a97ff74689954b3722f
4
+ data.tar.gz: 4e387fef89aec0a4ee20cf8af1d56d39f341bf1753ac749a18cd4b422ff739c4
5
5
  SHA512:
6
- metadata.gz: 927522cd800319aecbebbe3e22569a77faff86512e0d5720265cd8e584a9846a4d3432750951ed2023a90e31dd3617131674b32c425f38e3d7b5de2395fc0b9a
7
- data.tar.gz: 69c8528403cbc6c836840c2bcd7982e9c031a5a58e1834246f19be38349a6d125fda8f0d191258cb01bd0346b2ce426586f2b414f126d72a11db0917149cd17b
6
+ metadata.gz: e92c41260ed8515b52954c6ad21e8b9e5ebc41bc5d74fa8ea304ebd267a70ecdd033e91aac7c3281b70847fdcdb32fafa762ef14c1958de3905f099182227ad7
7
+ data.tar.gz: 737f383994b9d474222c889e956b06382cd357add02d04600c9daa6eeb488bd9414713a8e5aeb1bf460fe81ddb3c65c33fd7e77cd88096198d07ab24c74d502b
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.5.3
4
+ - 2.6.1
5
5
  before_install: gem install bundler
6
6
  before_script:
7
7
  - bundle install
data/lib/simple_gdrive.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'simple_gdrive/version'
2
+ require 'simple_gdrive/authorizer'
2
3
  require 'simple_gdrive/base'
3
4
  require 'simple_gdrive/uploader'
4
5
  require 'simple_gdrive/cleaner'
@@ -29,20 +30,12 @@ module SimpleGdrive
29
30
  end
30
31
 
31
32
  def self.upload(full_filename, upload_source, content_type: 'text/plain', mime_type: nil)
32
- Uploader.new(
33
- app_name: config.app_name,
34
- base_folder_id: config.base_folder_id,
35
- credential_file: config.credential_file,
36
- client_secrets_file: config.client_secrets_file
37
- ).call(full_filename, upload_source, content_type: content_type, mime_type: mime_type)
33
+ Uploader
34
+ .new(base_folder_id: config.base_folder_id)
35
+ .call(full_filename, upload_source, content_type: content_type, mime_type: mime_type)
38
36
  end
39
37
 
40
38
  def self.clear
41
- Cleaner.new(
42
- app_name: config.app_name,
43
- base_folder_id: config.base_folder_id,
44
- credential_file: config.credential_file,
45
- client_secrets_file: config.client_secrets_file
46
- ).call
39
+ Cleaner.new(base_folder_id: config.base_folder_id).call
47
40
  end
48
41
  end
@@ -0,0 +1,51 @@
1
+ require 'fileutils'
2
+
3
+ require 'google/apis/drive_v3'
4
+ require 'googleauth/stores/file_token_store'
5
+
6
+ module SimpleGdrive
7
+ class Authorizer
8
+ OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
9
+ DEFAULT_USER_ID = 'default'.freeze
10
+ API_SCOPE = [Google::Apis::DriveV3::AUTH_DRIVE].freeze
11
+
12
+ def call
13
+ FileUtils.mkdir_p File.dirname(::SimpleGdrive.config.credential_file)
14
+
15
+ credentials = user_authorizer.get_credentials(DEFAULT_USER_ID)
16
+ credentials = request_credentials if credentials.nil? && defined?(Rails::Console)
17
+
18
+ credentials
19
+ end
20
+
21
+ def self.call
22
+ new.call
23
+ end
24
+
25
+ private
26
+
27
+ def user_authorizer
28
+ return @user_authorizer if defined?(@user_authorizer)
29
+
30
+ client_id = ::Google::Auth::ClientId.from_file(::SimpleGdrive.config.client_secrets_file)
31
+ token_store = ::Google::Auth::Stores::FileTokenStore.new(file: ::SimpleGdrive.config.credential_file)
32
+
33
+ @user_authorizer = ::Google::Auth::UserAuthorizer.new(
34
+ client_id,
35
+ API_SCOPE,
36
+ token_store,
37
+ OOB_URI
38
+ )
39
+ end
40
+
41
+ def request_credentials
42
+ puts 'Open the following URL in the browser and enter the '\
43
+ "resulting code after authorization:\n#{user_authorizer.get_authorization_url}"
44
+
45
+ user_authorizer.get_and_store_credentials_from_code(
46
+ user_id: DEFAULT_USER_ID,
47
+ code: gets
48
+ )
49
+ end
50
+ end
51
+ end
@@ -1,63 +1,21 @@
1
- require 'fileutils'
2
-
3
1
  require 'google/apis/drive_v3'
4
- require 'googleauth'
5
- require 'googleauth/stores/file_token_store'
6
2
 
7
3
  module SimpleGdrive
8
4
  class Base
9
- OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
10
- USER_ID = 'default'.freeze
11
5
  FOLDER_MIME_TYPE = 'application/vnd.google-apps.folder'.freeze
12
6
  OPTIONS = {retries: 5}.freeze
13
7
 
14
- def initialize(app_name:, base_folder_id:, credential_file:, client_secrets_file:)
15
- @app_name = app_name
8
+ def initialize(base_folder_id:)
16
9
  @base_folder_id = base_folder_id
17
- @credential_file = credential_file
18
- @client_secrets_file = client_secrets_file
19
10
  end
20
11
 
12
+ private
13
+
21
14
  def service
22
15
  @service ||= Google::Apis::DriveV3::DriveService.new.tap do |service|
23
- service.client_options.application_name = @app_name
24
- service.authorization = credentials
16
+ service.client_options.application_name = SimpleGdrive.config.app_name
17
+ service.authorization = Authorizer.call
25
18
  end
26
19
  end
27
-
28
- private
29
-
30
- def auth_request(authorizer)
31
- url = authorizer.get_authorization_url(base_url: OOB_URI)
32
-
33
- puts 'Open the following URL in the browser and enter the '\
34
- 'resulting code after authorization'
35
-
36
- puts url
37
- code = gets
38
-
39
- authorizer.get_and_store_credentials_from_code(
40
- user_id: USER_ID,
41
- code: code,
42
- base_url: OOB_URI
43
- )
44
- end
45
-
46
- def credentials
47
- return @credentials if defined?(@credentials)
48
-
49
- FileUtils.mkdir_p File.dirname(@credential_file)
50
-
51
- client_id = Google::Auth::ClientId.from_file(@client_secrets_file)
52
- token_store = Google::Auth::Stores::FileTokenStore.new(file: @credential_file)
53
-
54
- authorizer = Google::Auth::UserAuthorizer.new(
55
- client_id,
56
- Google::Apis::DriveV3::AUTH_DRIVE,
57
- token_store
58
- )
59
-
60
- @credentials = authorizer.get_credentials(USER_ID) || auth_request(authorizer)
61
- end
62
20
  end
63
21
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleGdrive
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
31
  spec.add_development_dependency 'shoulda-matchers'
32
+ spec.add_development_dependency 'timecop'
32
33
  spec.add_development_dependency 'vcr'
33
34
  spec.add_development_dependency 'webmock'
34
35
  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.4.0
4
+ version: 0.5.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: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2019-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: vcr
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +153,7 @@ files:
139
153
  - bin/console
140
154
  - bin/setup
141
155
  - lib/simple_gdrive.rb
156
+ - lib/simple_gdrive/authorizer.rb
142
157
  - lib/simple_gdrive/base.rb
143
158
  - lib/simple_gdrive/cleaner.rb
144
159
  - lib/simple_gdrive/uploader.rb
@@ -163,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
178
  - !ruby/object:Gem::Version
164
179
  version: '0'
165
180
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.6
181
+ rubygems_version: 3.0.1
168
182
  signing_key:
169
183
  specification_version: 4
170
184
  summary: Simple Google Drive file uploader