google_drive_handler 0.1.0.pre.rc → 0.1.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 +4 -4
- data/.gitignore +3 -1
- data/.ruby-version +1 -0
- data/Gemfile.lock +86 -0
- data/README.md +11 -2
- data/exe/google_drive_auth +7 -0
- data/lib/google_drive_handler.rb +2 -0
- data/lib/google_drive_handler/auth.rb +130 -0
- data/lib/google_drive_handler/version.rb +1 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eecaad0fc5d9bd5f6a10efadd27a85fc3d1e62c3
|
4
|
+
data.tar.gz: 7b4b1fde6791fe9c31963b80a4fa301db36cd146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28103f06fadd0de45188d85b7f66ee5c9fddd7d4030c66db73dba5e8079f034a522922abff2afccf78fa7cde9f050873851eeab35680cc0787270d244689be64
|
7
|
+
data.tar.gz: 893b55e77e0ee95c78c63cac833abb886934fb9f0eef902983f1e7ca7f0c764381703e5b435ed581b4a0dc431a9e8ec4ccbc32cab951574a89701281de97b492
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
google_drive_handler (0.1.0)
|
5
|
+
dotenv (~> 2.2)
|
6
|
+
google-api-client (~> 0.18)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
byebug (9.1.0)
|
14
|
+
declarative (0.0.10)
|
15
|
+
declarative-option (0.1.0)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
dotenv (2.2.1)
|
18
|
+
faraday (0.13.1)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
google-api-client (0.18.0)
|
21
|
+
addressable (~> 2.5, >= 2.5.1)
|
22
|
+
googleauth (>= 0.5, < 0.7.0)
|
23
|
+
httpclient (>= 2.8.1, < 3.0)
|
24
|
+
mime-types (~> 3.0)
|
25
|
+
representable (~> 3.0)
|
26
|
+
retriable (>= 2.0, < 4.0)
|
27
|
+
googleauth (0.6.2)
|
28
|
+
faraday (~> 0.12)
|
29
|
+
jwt (>= 1.4, < 3.0)
|
30
|
+
logging (~> 2.0)
|
31
|
+
memoist (~> 0.12)
|
32
|
+
multi_json (~> 1.11)
|
33
|
+
os (~> 0.9)
|
34
|
+
signet (~> 0.7)
|
35
|
+
httpclient (2.8.3)
|
36
|
+
jwt (2.1.0)
|
37
|
+
little-plugger (1.1.4)
|
38
|
+
logging (2.2.2)
|
39
|
+
little-plugger (~> 1.1)
|
40
|
+
multi_json (~> 1.10)
|
41
|
+
memoist (0.16.0)
|
42
|
+
mime-types (3.1)
|
43
|
+
mime-types-data (~> 3.2015)
|
44
|
+
mime-types-data (3.2016.0521)
|
45
|
+
multi_json (1.12.2)
|
46
|
+
multipart-post (2.0.0)
|
47
|
+
os (0.9.6)
|
48
|
+
public_suffix (3.0.1)
|
49
|
+
rake (10.5.0)
|
50
|
+
representable (3.0.4)
|
51
|
+
declarative (< 0.1.0)
|
52
|
+
declarative-option (< 0.2.0)
|
53
|
+
uber (< 0.2.0)
|
54
|
+
retriable (3.1.1)
|
55
|
+
rspec (3.7.0)
|
56
|
+
rspec-core (~> 3.7.0)
|
57
|
+
rspec-expectations (~> 3.7.0)
|
58
|
+
rspec-mocks (~> 3.7.0)
|
59
|
+
rspec-core (3.7.0)
|
60
|
+
rspec-support (~> 3.7.0)
|
61
|
+
rspec-expectations (3.7.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.7.0)
|
64
|
+
rspec-mocks (3.7.0)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.7.0)
|
67
|
+
rspec-support (3.7.0)
|
68
|
+
signet (0.8.1)
|
69
|
+
addressable (~> 2.3)
|
70
|
+
faraday (~> 0.9)
|
71
|
+
jwt (>= 1.5, < 3.0)
|
72
|
+
multi_json (~> 1.10)
|
73
|
+
uber (0.1.0)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 1.16)
|
80
|
+
byebug (~> 9.1)
|
81
|
+
google_drive_handler!
|
82
|
+
rake (~> 10.0)
|
83
|
+
rspec (~> 3.0)
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.16.0
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/google_drive_handler`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
|
5
|
+
This gem helps you to create and save different credentials and scope setup using dot environment to setup the scopes and the credentials folders.
|
6
|
+
By default is ~/.credentials/
|
7
|
+
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,7 +24,14 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
To create the credentials the first time, you need to save in the credetital directory the client_secret.json. You have to create a project and enable apis Google Drive, Sheets, Google+ and then create a credentials and download the client_secret.json
|
28
|
+
By default the value is ~/.credentials/client_secret.json
|
29
|
+
But you could overwrite using the envirnoment variable CLIENT_SECRET_PATH in the .env file.
|
30
|
+
|
31
|
+
The command google_drive_auth is to help you to save the credentials. You can generate the credential for your scopes, running the command.
|
32
|
+
You will get a url to authorize and get the autorization code. Paste in the terminal to save the credentials for the selected scopes.
|
33
|
+
|
34
|
+
|
26
35
|
|
27
36
|
## Development
|
28
37
|
|
data/lib/google_drive_handler.rb
CHANGED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'googleauth'
|
2
|
+
require 'googleauth/stores/file_token_store'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module GoogleDriveHandler
|
6
|
+
|
7
|
+
class Auth
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def default_credential_path
|
12
|
+
File.join(Dir.home,'.credentials')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
18
|
+
CLIENT_SECRETS_PATH = ENV['CLIENT_SECRETS_PATH'] || File.join(Auth::default_credential_path,'client_secret.json')
|
19
|
+
INVALID_SCOPE_ERROR = "Sorry, this is an invalid scope"
|
20
|
+
|
21
|
+
attr_accessor :service, :response, :spreadsheet
|
22
|
+
attr_reader :scope, :user_id
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@scope=ENV['SCOPE'].split.map(&:to_i)
|
26
|
+
@user_id='default'
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorize
|
30
|
+
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
|
31
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
32
|
+
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope_url, token_store)
|
33
|
+
authorizer.get_credentials(user_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def choose_scope
|
37
|
+
|
38
|
+
puts "Choose one (typing the number) or more scopes (typing the numbers with one space between them):"
|
39
|
+
scopes.each_pair do |k,v|
|
40
|
+
puts "#{k}.- #{v[:name]}"
|
41
|
+
puts "\t#{v[:desc]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
s=gets(chomp: true)
|
45
|
+
|
46
|
+
s=s.split
|
47
|
+
@scope=s.map do |option|
|
48
|
+
raise INVALID_SCOPE_ERROR if !scopes.keys.include?(option.to_i)
|
49
|
+
option.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_credentials
|
55
|
+
|
56
|
+
choose_scope
|
57
|
+
|
58
|
+
FileUtils.mkdir_p(File.dirname(credentials_path))
|
59
|
+
|
60
|
+
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
|
61
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
62
|
+
authorizer = Google::Auth::UserAuthorizer.new( client_id, scope_url, token_store)
|
63
|
+
url = authorizer.get_authorization_url(base_url: OOB_URI)
|
64
|
+
puts "Visit #{url} to get the code"
|
65
|
+
|
66
|
+
code=gets(chomp: true)
|
67
|
+
|
68
|
+
authorizer.get_and_store_credentials_from_code(user_id: user_id, code: code, base_url: OOB_URI)
|
69
|
+
|
70
|
+
puts "the credentials have been saved in #{credentials_path}"
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def scopes
|
75
|
+
{
|
76
|
+
1 => {
|
77
|
+
name: 'AUTH_DRIVE',
|
78
|
+
desc: 'View and manage the files in your Google Drive',
|
79
|
+
url: 'https://www.googleapis.com/auth/drive'
|
80
|
+
},
|
81
|
+
2 => {
|
82
|
+
name: 'AUTH_DRIVE_FILE',
|
83
|
+
desc: 'View and manage Google Drive files and folders that you have opened or created with this app',
|
84
|
+
url: 'https://www.googleapis.com/auth/drive.file'
|
85
|
+
},
|
86
|
+
3 => {
|
87
|
+
name: 'AUTH_DRIVE_READONLY',
|
88
|
+
desc: 'View the files in your Google Drive',
|
89
|
+
url: 'https://www.googleapis.com/auth/drive.readonly'
|
90
|
+
},
|
91
|
+
4 => {
|
92
|
+
name: 'AUTH_SPREADSHEETS',
|
93
|
+
desc: 'View and manage your spreadsheets in Google Drive',
|
94
|
+
url: 'https://www.googleapis.com/auth/spreadsheets'
|
95
|
+
},
|
96
|
+
5 => {
|
97
|
+
name: 'AUTH_SPREADSHEETS_READONLY',
|
98
|
+
desc: 'View your Google Spreadsheets',
|
99
|
+
url: 'https://www.googleapis.com/auth/spreadsheets.readonly'
|
100
|
+
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def credentials_path
|
105
|
+
path=ENV['CREDENTIALS_PATH'] || Auth::default_credential_path
|
106
|
+
name=scope_url.map { |a| a.split('/').last }.join('.and.')
|
107
|
+
File.join(path, "sheets.googleapis.#{name}.yaml")
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def scope_url
|
113
|
+
if @scope.count<1
|
114
|
+
scopes[@scope.first.to_i][:url]
|
115
|
+
else
|
116
|
+
@scope.map { |option| scopes[option.to_i][:url] }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def save_code code
|
121
|
+
name=@scope.map { |a| scopes[a][:name] }.join('_AND_')
|
122
|
+
name="GOOGLE_#{name}"
|
123
|
+
File.open('.env','a') do |f|
|
124
|
+
f.write "#{name}=#{code}"
|
125
|
+
f.close
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_drive_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego H Piccinini Lagos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,21 +97,26 @@ dependencies:
|
|
97
97
|
description: To set up the scope in a easy way with a dotenv setup
|
98
98
|
email:
|
99
99
|
- dlagos@bookingbug.com
|
100
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- google_drive_auth
|
101
102
|
extensions: []
|
102
103
|
extra_rdoc_files: []
|
103
104
|
files:
|
104
105
|
- ".gitignore"
|
105
106
|
- ".rspec"
|
107
|
+
- ".ruby-version"
|
106
108
|
- ".travis.yml"
|
107
109
|
- CODE_OF_CONDUCT.md
|
108
110
|
- Gemfile
|
111
|
+
- Gemfile.lock
|
109
112
|
- README.md
|
110
113
|
- Rakefile
|
111
114
|
- bin/console
|
112
115
|
- bin/setup
|
116
|
+
- exe/google_drive_auth
|
113
117
|
- google_drive_handler.gemspec
|
114
118
|
- lib/google_drive_handler.rb
|
119
|
+
- lib/google_drive_handler/auth.rb
|
115
120
|
- lib/google_drive_handler/version.rb
|
116
121
|
homepage: https://github.com/diegopiccinini/google_drive_handler
|
117
122
|
licenses: []
|
@@ -128,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
133
|
version: '0'
|
129
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
135
|
requirements:
|
131
|
-
- - "
|
136
|
+
- - ">="
|
132
137
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
138
|
+
version: '0'
|
134
139
|
requirements: []
|
135
140
|
rubyforge_project:
|
136
141
|
rubygems_version: 2.6.13
|