drive_env 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb1bb40e154e2f37788dc647359e7d319d15ef2f
4
- data.tar.gz: a9f72fb90a98aa3f2ce757fa0e6e62dbb553cc5b
2
+ SHA256:
3
+ metadata.gz: bff4a1453c14161faa7baf74042a882fe3f526dd21a574d814c2a34870560d2f
4
+ data.tar.gz: a89a3ccb92efe3453f4ee51e1a0b3b3fbcabc2f9b25c00a56b3f9020d0eec3a1
5
5
  SHA512:
6
- metadata.gz: 2c012be4c993d385da2bccb426efd92458a6960f10b549674ea162b5f42324ebba8f650d93f88148892e9ed06beb84ef55287eabdb83429b439ffee2f562e181
7
- data.tar.gz: aee1c2cc88aeec90c55ae146c978d593830ba7f14c4ae6e69f000294fe5dfefdfccef1c44aa066dbda55f4555321e0ad4721bcf99ea89ed88a0ab77d33839868
6
+ metadata.gz: cf0f097b20c55fe087557b462c20fe41dcb31a6b1e30a75cb0fc110b8f798b2d15dad6cbca5d1fc55dece490fe813ecc7d69ee15fc31c58d23fff35e3317e6eb
7
+ data.tar.gz: e66fff342312c3226d427f3259d100416af648f175e4540db1effba146301d62554a344552a299be89771fbf282c05c40e864173f5c059612c0c1d2b1157187d
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ name: Test
8
+ strategy:
9
+ matrix:
10
+ ruby_version:
11
+ - '3.0'
12
+ - 2.7
13
+ fail-fast: false
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby_version }}
20
+ bundler-cache: true
21
+ - run: bundle exec rake spec
22
+
data/README.md CHANGED
@@ -36,16 +36,17 @@ Or install it yourself as:
36
36
 
37
37
  ## Usage
38
38
 
39
- First, you need to login Google Cloud Platform and enable APIs.
39
+ First, you need to login Google Cloud Platform and enable APIs. We support authentication with `User account` and `Service account`.
40
40
 
41
- 1. Open https://console.developers.google.com/project
41
+ ### User authentication
42
+
43
+ 1. Open [API library page](https://console.developers.google.com/apis/library)
42
44
  2. Create/Select project
43
- 3. Visit APIs & auth -> APIs
44
- 4. Grant access to `Drive API`
45
- 5. Visit APIs & auth -> Credentials
46
- 6. Oauth -> Create new Client ID
47
- 7. Choose Installed application (Other)
48
- 8. Note CLIENT ID, CLIENT_SECRET
45
+ 3. Enable "Google Drive API" and "Google Sheets API"
46
+ 4. Open [Credentials page](https://console.developers.google.com/apis/credentials) in the same project
47
+ 5. Click "Create credentials" and choose "OAuth client ID"
48
+ 6. Choose "Other" for "Application type", and click "create"
49
+ 7. Note CLIENT ID, CLIENT_SECRET
49
50
 
50
51
  Setup client_id, client_secret, and login.
51
52
 
@@ -57,6 +58,23 @@ $ drive_env auth login
57
58
 
58
59
  Now you have access token and refresh token, you can access to Google APIs.
59
60
 
61
+ ### Service account authentication
62
+
63
+ 1. Open [API library page](https://console.developers.google.com/apis/library)
64
+ 2. Create/Select project
65
+ 3. Enable "Google Drive API" and "Google Sheets API"
66
+ 4. Open [Credentials page](https://console.developers.google.com/apis/credentials) in the same project
67
+ 5. Click "Create credentials" and choose "Service account key"
68
+ 6. Save credentials as JSON file
69
+ 7. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variables with the value of the downloaded JSON file path.
70
+ ```
71
+ $ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account_credential.json"
72
+ ```
73
+
74
+ The application search `GOOGLE_APPLICATION_CREDENTIALS` first and then try to use user credential.
75
+
76
+ ### Access Spreadsheet
77
+
60
78
  Show Spreadsheet in Google Drive:
61
79
 
62
80
  ```
@@ -100,7 +118,7 @@ $ your-ruby-application-with-dotenv-gem
100
118
 
101
119
  ## Development
102
120
 
103
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
122
 
105
123
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
124
 
@@ -112,4 +130,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/groove
112
130
  ## License
113
131
 
114
132
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
115
-
data/drive_env.gemspec CHANGED
@@ -27,14 +27,13 @@ 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", "~> 2.0.1"
31
- spec.add_dependency "google-api-client", "~> 0.9.8"
32
- spec.add_dependency "googleauth", "~> 0.5.1"
33
- spec.add_dependency "thor", "~> 0.19.1"
34
- spec.add_dependency "text-table", "~> 1.2.4"
30
+ spec.add_dependency "google_drive", "~> 3.0"
31
+ spec.add_dependency "googleauth", "~> 0.5"
32
+ spec.add_dependency "thor", "~> 0.19"
33
+ spec.add_dependency "text-table", "~> 1.2"
35
34
 
36
- spec.add_development_dependency "bundler", "~> 1.10"
37
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rake"
38
37
  spec.add_development_dependency "rspec"
39
38
  spec.add_development_dependency "pry"
40
39
  end
@@ -75,21 +75,27 @@ module DriveEnv
75
75
 
76
76
  def credential
77
77
  unless @credential
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?
78
+ case authorizer
79
+ when Google::Auth::UserAuthorizer
80
+ @credential = authorizer.get_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID)
81
+ case
82
+ when @credential.nil?
83
+ abort "please set access_token: #{$0} auth login"
84
+ when @credential.expired?
85
+ @credential.fetch_access_token!
86
+ @credential.expires_at = credential.issued_at + credential.expires_in
87
+ authorizer.store_credentials(DriveEnv::Config::DEFAULT_TOKEN_USER_ID, @credential)
88
+ end
89
+ when Google::Auth::ServiceAccountCredentials
90
+ @credential = authorizer
83
91
  @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)
86
92
  end
87
93
  end
88
94
  @credential
89
95
  end
90
96
 
91
97
  def session
92
- @session ||= GoogleDrive.login_with_oauth(credential)
98
+ @session ||= GoogleDrive::Session.login_with_oauth(credential)
93
99
  end
94
100
 
95
101
  def worksheet(url_or_alias)
@@ -134,4 +140,3 @@ module DriveEnv
134
140
  end
135
141
  end
136
142
  end
137
-
@@ -1,3 +1,3 @@
1
1
  module DriveEnv
2
- VERSION = '0.2.1'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/drive_env.rb CHANGED
@@ -9,13 +9,21 @@ module DriveEnv
9
9
  class << self
10
10
  def authorizer(client_id, client_secret, token_store_file)
11
11
  unless @authorizer
12
- client_id = Google::Auth::ClientId.new(client_id, client_secret)
12
+ cred = ENV['GOOGLE_APPLICATION_CREDENTIALS']
13
13
  scope = %w[
14
14
  https://www.googleapis.com/auth/drive
15
15
  https://spreadsheets.google.com/feeds/
16
16
  ]
17
- token_store = Google::Auth::Stores::FileTokenStore.new(file: token_store_file)
18
- @authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
17
+ if cred.nil?
18
+ client_id = Google::Auth::ClientId.new(client_id, client_secret)
19
+ token_store = Google::Auth::Stores::FileTokenStore.new(file: token_store_file)
20
+ @authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
21
+ else
22
+ @authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
23
+ json_key_io: File.open(cred),
24
+ scope: scope
25
+ )
26
+ end
19
27
  end
20
28
  @authorizer
21
29
  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.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMADA Tsuyoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive
@@ -16,98 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.1
19
+ version: '3.0'
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: 2.0.1
27
- - !ruby/object:Gem::Dependency
28
- name: google-api-client
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.9.8
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.9.8
26
+ version: '3.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: googleauth
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 0.5.1
33
+ version: '0.5'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: 0.5.1
40
+ version: '0.5'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: thor
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 0.19.1
47
+ version: '0.19'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 0.19.1
54
+ version: '0.19'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: text-table
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 1.2.4
61
+ version: '1.2'
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 1.2.4
68
+ version: '1.2'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: bundler
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: '1.10'
75
+ version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: '1.10'
82
+ version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rake
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - "~>"
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: '10.0'
89
+ version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - "~>"
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: '10.0'
96
+ version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rspec
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -144,9 +130,9 @@ executables:
144
130
  extensions: []
145
131
  extra_rdoc_files: []
146
132
  files:
133
+ - ".github/workflows/ci.yml"
147
134
  - ".gitignore"
148
135
  - ".rspec"
149
- - ".travis.yml"
150
136
  - Gemfile
151
137
  - LICENSE.txt
152
138
  - README.md
@@ -183,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
169
  - !ruby/object:Gem::Version
184
170
  version: '0'
185
171
  requirements: []
186
- rubyforge_project:
187
- rubygems_version: 2.5.1
172
+ rubygems_version: 3.2.26
188
173
  signing_key:
189
174
  specification_version: 4
190
175
  summary: Generate `.env` file from Spreadsheet in Google Drive
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.1
4
- - 2.2.5
5
- - 2.1.10