uptime_reports_spreadsheet 0.1.0.pre.beta → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +37 -0
- data/Guardfile +22 -0
- data/README.md +6 -4
- data/exe/uptime_reports_save_code +6 -0
- data/lib/uptime_reports_spreadsheet.rb +1 -0
- data/lib/uptime_reports_spreadsheet/auth.rb +103 -35
- data/lib/uptime_reports_spreadsheet/spreadsheet.rb +46 -0
- data/lib/uptime_reports_spreadsheet/version.rb +1 -1
- data/uptime_reports_spreadsheet.gemspec +1 -0
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc3d84c24886b60339b48d9fdfc19be03f33312
|
4
|
+
data.tar.gz: 883fcb2736606b0bae9d63225f69c11d2b5b7040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97603bc814a3ca7a6af5c85d0211c6ceb818b2ee6e6909ad5cd7f62f0dd8839f36947976c1bf88b3114aef83a206185822e5d95115588321c04e5f000bedf69f
|
7
|
+
data.tar.gz: d9dd0ad941ac26b44f9027dcd6f5e54a728d621521c3eb6625e96ddfccb900b14af020d65bf02711fd0e605ab4de2927dfb01f890abf6f2f18d9a71a25e2d9ca
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/Gemfile.lock
CHANGED
@@ -12,12 +12,15 @@ GEM
|
|
12
12
|
addressable (2.5.2)
|
13
13
|
public_suffix (>= 2.0.2, < 4.0)
|
14
14
|
byebug (9.1.0)
|
15
|
+
coderay (1.1.2)
|
15
16
|
declarative (0.0.10)
|
16
17
|
declarative-option (0.1.0)
|
17
18
|
diff-lcs (1.3)
|
18
19
|
dotenv (2.2.1)
|
19
20
|
faraday (0.13.1)
|
20
21
|
multipart-post (>= 1.2, < 3)
|
22
|
+
ffi (1.9.18)
|
23
|
+
formatador (0.2.5)
|
21
24
|
google-api-client (0.16.0)
|
22
25
|
addressable (~> 2.5, >= 2.5.1)
|
23
26
|
googleauth (>= 0.5, < 0.7.0)
|
@@ -33,21 +36,51 @@ GEM
|
|
33
36
|
multi_json (~> 1.11)
|
34
37
|
os (~> 0.9)
|
35
38
|
signet (~> 0.7)
|
39
|
+
guard (2.14.1)
|
40
|
+
formatador (>= 0.2.4)
|
41
|
+
listen (>= 2.7, < 4.0)
|
42
|
+
lumberjack (~> 1.0)
|
43
|
+
nenv (~> 0.1)
|
44
|
+
notiffany (~> 0.0)
|
45
|
+
pry (>= 0.9.12)
|
46
|
+
shellany (~> 0.0)
|
47
|
+
thor (>= 0.18.1)
|
48
|
+
guard-compat (1.2.1)
|
49
|
+
guard-rspec (4.7.3)
|
50
|
+
guard (~> 2.1)
|
51
|
+
guard-compat (~> 1.1)
|
52
|
+
rspec (>= 2.99.0, < 4.0)
|
36
53
|
httpclient (2.8.3)
|
37
54
|
jwt (2.1.0)
|
55
|
+
listen (3.1.5)
|
56
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
57
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
58
|
+
ruby_dep (~> 1.2)
|
38
59
|
little-plugger (1.1.4)
|
39
60
|
logging (2.2.2)
|
40
61
|
little-plugger (~> 1.1)
|
41
62
|
multi_json (~> 1.10)
|
63
|
+
lumberjack (1.0.12)
|
42
64
|
memoist (0.16.0)
|
65
|
+
method_source (0.9.0)
|
43
66
|
mime-types (3.1)
|
44
67
|
mime-types-data (~> 3.2015)
|
45
68
|
mime-types-data (3.2016.0521)
|
46
69
|
multi_json (1.12.2)
|
47
70
|
multipart-post (2.0.0)
|
71
|
+
nenv (0.3.0)
|
72
|
+
notiffany (0.1.1)
|
73
|
+
nenv (~> 0.1)
|
74
|
+
shellany (~> 0.0)
|
48
75
|
os (0.9.6)
|
76
|
+
pry (0.11.3)
|
77
|
+
coderay (~> 1.1.0)
|
78
|
+
method_source (~> 0.9.0)
|
49
79
|
public_suffix (3.0.0)
|
50
80
|
rake (10.5.0)
|
81
|
+
rb-fsevent (0.10.2)
|
82
|
+
rb-inotify (0.9.10)
|
83
|
+
ffi (>= 0.5.0, < 2)
|
51
84
|
representable (3.0.4)
|
52
85
|
declarative (< 0.1.0)
|
53
86
|
declarative-option (< 0.2.0)
|
@@ -66,11 +99,14 @@ GEM
|
|
66
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
100
|
rspec-support (~> 3.7.0)
|
68
101
|
rspec-support (3.7.0)
|
102
|
+
ruby_dep (1.5.0)
|
103
|
+
shellany (0.0.1)
|
69
104
|
signet (0.8.1)
|
70
105
|
addressable (~> 2.3)
|
71
106
|
faraday (~> 0.9)
|
72
107
|
jwt (>= 1.5, < 3.0)
|
73
108
|
multi_json (~> 1.10)
|
109
|
+
thor (0.20.0)
|
74
110
|
uber (0.1.0)
|
75
111
|
|
76
112
|
PLATFORMS
|
@@ -78,6 +114,7 @@ PLATFORMS
|
|
78
114
|
|
79
115
|
DEPENDENCIES
|
80
116
|
bundler (~> 1.16.a)
|
117
|
+
guard-rspec (~> 4.7)
|
81
118
|
rake (~> 10.0)
|
82
119
|
rspec (~> 3.0)
|
83
120
|
uptime_reports_spreadsheet!
|
data/Guardfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
#
|
18
|
+
guard :rspec, cmd: 'rspec' do
|
19
|
+
watch(%r{^spec/.+_spec\.rb$})
|
20
|
+
watch(%r{^lib/uptime_reports_spreadsheet/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
21
|
+
watch('spec/spec_helper.rb') { "spec" }
|
22
|
+
end
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
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/uptime_reports_spreadsheet`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
@@ -22,7 +20,11 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
To have a connection you have to create 2 files:
|
24
|
+
|
25
|
+
- .env (to setup the ENV variables like GOOGLE_API_AUTH_CODE)
|
26
|
+
- client_secret.json (with your client secret data of Google console))
|
27
|
+
|
26
28
|
|
27
29
|
## Development
|
28
30
|
|
@@ -32,7 +34,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/diegopiccinini/uptime_reports_spreadsheet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
38
|
|
37
39
|
## Code of Conduct
|
38
40
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'google/apis/sheets_v4'
|
2
2
|
require 'googleauth'
|
3
3
|
require 'googleauth/stores/file_token_store'
|
4
|
-
|
4
|
+
require 'google/apis/drive_v3'
|
5
5
|
require 'fileutils'
|
6
6
|
module UptimeReportsSpreadsheet
|
7
7
|
|
@@ -10,46 +10,114 @@ module UptimeReportsSpreadsheet
|
|
10
10
|
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
11
11
|
APPLICATION_NAME = 'Google Sheets API Ruby Quickstart'
|
12
12
|
CLIENT_SECRETS_PATH = 'client_secret.json'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
|
13
|
+
INVALID_SCOPE_ERROR = "Sorry, this is an invalid scope"
|
14
|
+
|
15
|
+
attr_accessor :service, :response, :spreadsheet
|
16
|
+
attr_reader :scope, :user_id
|
17
|
+
|
18
|
+
def initialize scope=nil
|
19
|
+
@scope=scope || [5]
|
20
|
+
@service = Google::Apis::SheetsV4::SheetsService.new
|
21
|
+
@service.client_options.application_name = APPLICATION_NAME
|
22
|
+
@user_id='default'
|
23
|
+
end
|
25
24
|
|
25
|
+
def authorize
|
26
26
|
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
|
27
|
-
token_store = Google::Auth::Stores::FileTokenStore.new(file:
|
28
|
-
authorizer = Google::Auth::UserAuthorizer.new(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
28
|
+
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope_url, token_store)
|
29
|
+
authorizer.get_credentials(user_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def choose_scope
|
33
|
+
|
34
|
+
puts "Choose one scope:"
|
35
|
+
scopes.each_pair do |k,v|
|
36
|
+
puts "#{k}.- #{v[:name]}"
|
37
|
+
puts "\t#{v[:desc]}"
|
38
|
+
end
|
39
|
+
|
40
|
+
s=gets(chomp: true)
|
41
|
+
|
42
|
+
s=s.split
|
43
|
+
@scope=s.map do |option|
|
44
|
+
raise INVALID_SCOPE_ERROR if !scopes.keys.include?(option.to_i)
|
45
|
+
option.to_i
|
37
46
|
end
|
38
|
-
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def save_credentials
|
51
|
+
|
52
|
+
choose_scope
|
53
|
+
|
54
|
+
FileUtils.mkdir_p(File.dirname(credentials_path))
|
55
|
+
|
56
|
+
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
|
57
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
58
|
+
authorizer = Google::Auth::UserAuthorizer.new( client_id, scope_url, token_store)
|
59
|
+
url = authorizer.get_authorization_url(base_url: OOB_URI)
|
60
|
+
puts "Visit #{url} to get the code"
|
61
|
+
|
62
|
+
code=gets(chomp: true)
|
63
|
+
|
64
|
+
authorizer.get_and_store_credentials_from_code(user_id: user_id, code: code, base_url: OOB_URI)
|
65
|
+
save_code code
|
66
|
+
|
39
67
|
end
|
40
68
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
69
|
+
def scopes
|
70
|
+
{
|
71
|
+
1 => {
|
72
|
+
name: 'AUTH_DRIVE',
|
73
|
+
desc: 'View and manage the files in your Google Drive',
|
74
|
+
url: 'https://www.googleapis.com/auth/drive'
|
75
|
+
},
|
76
|
+
2 => {
|
77
|
+
name: 'AUTH_DRIVE_FILE',
|
78
|
+
desc: 'View and manage Google Drive files and folders that you have opened or created with this app',
|
79
|
+
url: 'https://www.googleapis.com/auth/drive.file'
|
80
|
+
},
|
81
|
+
3 => {
|
82
|
+
name: 'AUTH_DRIVE_READONLY',
|
83
|
+
desc: 'View the files in your Google Drive',
|
84
|
+
url: 'https://www.googleapis.com/auth/drive.readonly'
|
85
|
+
},
|
86
|
+
4 => {
|
87
|
+
name: 'AUTH_SPREADSHEETS',
|
88
|
+
desc: 'View and manage your spreadsheets in Google Drive',
|
89
|
+
url: 'https://www.googleapis.com/auth/spreadsheets'
|
90
|
+
},
|
91
|
+
5 => {
|
92
|
+
name: 'AUTH_SPREADSHEETS_READONLY',
|
93
|
+
desc: 'View your Google Spreadsheets',
|
94
|
+
url: 'https://www.googleapis.com/auth/spreadsheets.readonly'
|
95
|
+
}
|
96
|
+
}
|
97
|
+
end
|
46
98
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
99
|
+
private
|
100
|
+
|
101
|
+
def credentials_path
|
102
|
+
name=scope_url.map { |a| a.split('/').last }.join('.and.')
|
103
|
+
File.join(Dir.home, '.credentials', "sheets.googleapis.#{name}.yaml")
|
104
|
+
end
|
105
|
+
|
106
|
+
def scope_url
|
107
|
+
if @scope.count<1
|
108
|
+
scopes[@scope.first.to_i][:url]
|
109
|
+
else
|
110
|
+
@scope.map { |option| scopes[option.to_i][:url] }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def save_code code
|
115
|
+
name=@scope.map { |a| scopes[a][:name] }.join('_AND_')
|
116
|
+
name="GOOGLE_#{name}"
|
117
|
+
File.open('.env','a') do |f|
|
118
|
+
f.write "#{name}=#{code}"
|
119
|
+
f.close
|
120
|
+
end
|
53
121
|
end
|
54
122
|
end
|
55
123
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'google/apis/drive_v3'
|
2
|
+
require 'uptime_reports_spreadsheet/auth'
|
3
|
+
|
4
|
+
module UptimeReportsSpreadsheet
|
5
|
+
|
6
|
+
class Spreadsheet
|
7
|
+
|
8
|
+
attr_accessor :service, :response, :spreadsheet, :auth
|
9
|
+
|
10
|
+
def initialize scopes=[1,4]
|
11
|
+
@auth=UptimeReportsSpreadsheet::Auth.new scopes
|
12
|
+
@service=auth.service
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def sample
|
17
|
+
service.authorization = auth.authorize
|
18
|
+
|
19
|
+
spreadsheet_id = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'
|
20
|
+
range = 'Class Data!A2:E'
|
21
|
+
response = service.get_spreadsheet_values(spreadsheet_id, range)
|
22
|
+
response.values
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
service.authorization = auth.authorize
|
27
|
+
request_body = Google::Apis::SheetsV4::Spreadsheet.new
|
28
|
+
@spreadsheet = service.create_spreadsheet(request_body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_title title
|
32
|
+
spreadsheet.properties.update!(title: title)
|
33
|
+
end
|
34
|
+
|
35
|
+
def title
|
36
|
+
spreadsheet.properties.title
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete
|
40
|
+
service = Google::Apis::DriveV3::DriveService.new
|
41
|
+
service.authorization = auth.authorize
|
42
|
+
service.delete_file spreadsheet.spreadsheet_id
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "bundler", "~> 1.16.a"
|
35
35
|
spec.add_development_dependency "rake", "~> 10.0"
|
36
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
37
38
|
spec.add_dependency "google-api-client", "~> 0.16"
|
38
39
|
spec.add_dependency "byebug", "~> 9.1"
|
39
40
|
spec.add_dependency "dotenv", "~> 2.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uptime_reports_spreadsheet
|
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-11-
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: google-api-client
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,22 +111,27 @@ dependencies:
|
|
97
111
|
description: " Get a report and write it in a google sheet. "
|
98
112
|
email:
|
99
113
|
- dlagos@bookingbug.com
|
100
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- uptime_reports_save_code
|
101
116
|
extensions: []
|
102
117
|
extra_rdoc_files: []
|
103
118
|
files:
|
104
119
|
- ".gitignore"
|
105
120
|
- ".rspec"
|
121
|
+
- ".ruby-version"
|
106
122
|
- ".travis.yml"
|
107
123
|
- CODE_OF_CONDUCT.md
|
108
124
|
- Gemfile
|
109
125
|
- Gemfile.lock
|
126
|
+
- Guardfile
|
110
127
|
- README.md
|
111
128
|
- Rakefile
|
112
129
|
- bin/console
|
113
130
|
- bin/setup
|
131
|
+
- exe/uptime_reports_save_code
|
114
132
|
- lib/uptime_reports_spreadsheet.rb
|
115
133
|
- lib/uptime_reports_spreadsheet/auth.rb
|
134
|
+
- lib/uptime_reports_spreadsheet/spreadsheet.rb
|
116
135
|
- lib/uptime_reports_spreadsheet/version.rb
|
117
136
|
- uptime_reports_spreadsheet.gemspec
|
118
137
|
homepage: https://rubygems.org/docs/bbeng/index.html
|
@@ -130,14 +149,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
149
|
version: '0'
|
131
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
151
|
requirements:
|
133
|
-
- - "
|
152
|
+
- - ">="
|
134
153
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
154
|
+
version: '0'
|
136
155
|
requirements: []
|
137
156
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.6.11
|
139
158
|
signing_key:
|
140
159
|
specification_version: 4
|
141
160
|
summary: Write spreadsheet in Google.
|
142
161
|
test_files: []
|
143
|
-
has_rdoc:
|