drive_env 0.1.0 → 0.2.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/README.md +2 -2
- data/drive_env.gemspec +3 -2
- data/lib/drive_env/cli/auth.rb +8 -19
- data/lib/drive_env/cli/spreadsheet.rb +11 -18
- data/lib/drive_env/config.rb +12 -3
- data/lib/drive_env/version.rb +1 -1
- data/lib/drive_env.rb +13 -3
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9d35322807cdaf7024bd6d465374fc082453ca
|
4
|
+
data.tar.gz: 13b1b82d99ba7cfdccd92ec859a688a256d8069e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a0d27c5e673c0e1ef7e8ca21455087f78d48ce894337cc03e733516b7c1d31b412a5dbc88a3e0b2efc37a66b4e99efea4ddfa54d4be58c391239776fda9bdcb
|
7
|
+
data.tar.gz: c02b9decf2b9cb6d04724a8e435e9f07765e4b01fb2ae1ad29997fef074461043aed23caca42483eb786b93ab88ea607863fb6d0c0d8d8fcd380cfe56265707f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ SMTP_PASSWORD=appuser
|
|
23
23
|
Add this line to your application's Gemfile:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
gem 'drive_env'
|
26
|
+
gem 'drive_env', '~> 0.2.pre1'
|
27
27
|
```
|
28
28
|
|
29
29
|
And then execute:
|
@@ -32,7 +32,7 @@ And then execute:
|
|
32
32
|
|
33
33
|
Or install it yourself as:
|
34
34
|
|
35
|
-
$ gem install drive_env
|
35
|
+
$ gem install drive_env --pre
|
36
36
|
|
37
37
|
## Usage
|
38
38
|
|
data/drive_env.gemspec
CHANGED
@@ -27,8 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency "google_drive", "~>
|
31
|
-
spec.add_dependency "google-api-client", "~> 0.
|
30
|
+
spec.add_dependency "google_drive", "~> 2.0.0.pre1"
|
31
|
+
spec.add_dependency "google-api-client", "~> 0.9.6"
|
32
|
+
spec.add_dependency "googleauth", "~> 0.5.1"
|
32
33
|
spec.add_dependency "thor", "~> 0.19.1"
|
33
34
|
spec.add_dependency "text-table", "~> 1.2.4"
|
34
35
|
|
data/lib/drive_env/cli/auth.rb
CHANGED
@@ -4,6 +4,8 @@ require 'drive_env'
|
|
4
4
|
module DriveEnv
|
5
5
|
module Cli
|
6
6
|
class Auth < Thor
|
7
|
+
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
8
|
+
|
7
9
|
desc 'login', ''
|
8
10
|
def login
|
9
11
|
if !config.client_id
|
@@ -12,14 +14,11 @@ module DriveEnv
|
|
12
14
|
if !config.client_secret
|
13
15
|
abort "please set client_secret: #{$0} config set client_secret YOUR_CLIENT_SECRET"
|
14
16
|
end
|
15
|
-
print("1. Open this page:\n%s\n\n" %
|
17
|
+
print("1. Open this page:\n%s\n\n" % authorizer.get_authorization_url(base_url: OOB_URI))
|
16
18
|
print("2. Enter the authorization code shown in the page: ")
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
config.refresh_token = auth.refresh_token
|
21
|
-
config.expires_at = auth.issued_at + auth.expires_in
|
22
|
-
config.save
|
19
|
+
|
20
|
+
code = $stdin.gets.chomp
|
21
|
+
authorizer.get_and_store_credentials_from_code(user_id: DriveEnv::Config::DEFAULT_TOKEN_USER_ID, code: code, base_url: OOB_URI)
|
23
22
|
end
|
24
23
|
|
25
24
|
no_commands do
|
@@ -27,18 +26,8 @@ module DriveEnv
|
|
27
26
|
@config ||= DriveEnv::Config.load(options[:config])
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
31
|
-
|
32
|
-
@auth = ::DriveEnv.client.authorization
|
33
|
-
@auth.client_id = config.client_id
|
34
|
-
@auth.client_secret = config.client_secret
|
35
|
-
@auth.scope = %w[
|
36
|
-
https://www.googleapis.com/auth/drive
|
37
|
-
https://spreadsheets.google.com/feeds/
|
38
|
-
].join(' ')
|
39
|
-
@auth.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
|
40
|
-
end
|
41
|
-
@auth
|
29
|
+
def authorizer
|
30
|
+
DriveEnv.authorizer(config.client_id, config.client_secret, DriveEnv::Config::DEFAULT_TOKENS_STORE_FILE)
|
42
31
|
end
|
43
32
|
end
|
44
33
|
end
|
@@ -69,34 +69,27 @@ module DriveEnv
|
|
69
69
|
@config ||= DriveEnv::Config.load(options[:config])
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
73
|
-
|
74
|
-
@auth = ::DriveEnv.client.authorization
|
75
|
-
@auth.client_id = config.client_id
|
76
|
-
@auth.client_secret = config.client_secret
|
77
|
-
end
|
78
|
-
@auth
|
72
|
+
def authorizer
|
73
|
+
DriveEnv.authorizer(config.client_id, config.client_secret, DriveEnv::Config::DEFAULT_TOKENS_STORE_FILE)
|
79
74
|
end
|
80
75
|
|
81
76
|
def access_token
|
82
77
|
unless @access_token
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
auth
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
|
79
|
+
case
|
80
|
+
when credential.nil?
|
81
|
+
abort "please set access_token: #{$0} auth login"
|
82
|
+
when credential.expired?
|
83
|
+
credential.fetch_access_token!
|
84
|
+
credential.expires_at = credential.issued_at + credential.expires_in
|
85
|
+
authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, credential)
|
90
86
|
end
|
91
|
-
@access_token =
|
87
|
+
@access_token = credential.access_token
|
92
88
|
end
|
93
89
|
@access_token
|
94
90
|
end
|
95
91
|
|
96
92
|
def session
|
97
|
-
if !config.access_token
|
98
|
-
abort "please set access_token: #{$0} auth login"
|
99
|
-
end
|
100
93
|
@session ||= GoogleDrive.login_with_oauth(access_token)
|
101
94
|
end
|
102
95
|
|
data/lib/drive_env/config.rb
CHANGED
@@ -4,12 +4,11 @@ require 'yaml'
|
|
4
4
|
module DriveEnv
|
5
5
|
class Config
|
6
6
|
DEFAULT_CONFIG_FILE = File.expand_path('~/.config/drive_env/config')
|
7
|
+
DEFAULT_TOKENS_STORE_FILE = File.expand_path('~/.config/drive_env/tokens.yml')
|
8
|
+
DEFAULT_TOKEN_USER_ID = 'default'
|
7
9
|
|
8
10
|
attr_accessor :client_id
|
9
11
|
attr_accessor :client_secret
|
10
|
-
attr_accessor :access_token
|
11
|
-
attr_accessor :refresh_token
|
12
|
-
attr_accessor :expires_at
|
13
12
|
|
14
13
|
def initialize
|
15
14
|
@spreadsheet_aliases = {}
|
@@ -39,10 +38,20 @@ module DriveEnv
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
41
|
+
def migrate
|
42
|
+
## dropped variables in 0.2.pre1
|
43
|
+
%W[access_token refresh_token expires_at].each do |v|
|
44
|
+
if instance_variable_get("@#{v}")
|
45
|
+
remove_instance_variable("@#{v}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
42
50
|
class << self
|
43
51
|
def load(file)
|
44
52
|
obj = File.exist?(file) ? YAML.load(File.read(file)) : self.new
|
45
53
|
obj.instance_variable_set("@config_file", file)
|
54
|
+
obj.migrate
|
46
55
|
obj
|
47
56
|
end
|
48
57
|
end
|
data/lib/drive_env/version.rb
CHANGED
data/lib/drive_env.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'drive_env/version'
|
2
|
-
require '
|
2
|
+
require 'googleauth'
|
3
|
+
require 'googleauth/stores/file_token_store'
|
3
4
|
|
4
5
|
module DriveEnv
|
5
6
|
autoload :Cli, 'drive_env/cli'
|
6
7
|
autoload :Config, 'drive_env/config'
|
7
8
|
|
8
9
|
class << self
|
9
|
-
def
|
10
|
-
@
|
10
|
+
def authorizer(client_id, client_secret, token_store_file)
|
11
|
+
unless @authorizer
|
12
|
+
client_id = Google::Auth::ClientId.new(client_id, client_secret)
|
13
|
+
scope = %w[
|
14
|
+
https://www.googleapis.com/auth/drive
|
15
|
+
https://spreadsheets.google.com/feeds/
|
16
|
+
]
|
17
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: token_store_file)
|
18
|
+
@authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
19
|
+
end
|
20
|
+
@authorizer
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drive_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YAMADA Tsuyoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0.pre1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0.pre1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: google-api-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.9.6
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.9.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: googleauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: thor
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,12 +179,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
179
|
version: '0'
|
166
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
181
|
requirements:
|
168
|
-
- - "
|
182
|
+
- - ">"
|
169
183
|
- !ruby/object:Gem::Version
|
170
|
-
version:
|
184
|
+
version: 1.3.1
|
171
185
|
requirements: []
|
172
186
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.5.1
|
174
188
|
signing_key:
|
175
189
|
specification_version: 4
|
176
190
|
summary: Generate `.env` file from Spreadsheet in Google Drive
|