embulk-output-google_sheets_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -1
- data/Gemfile +2 -0
- data/README.md +49 -6
- data/embulk-output-google_sheets_ruby.gemspec +1 -1
- data/example/setup_authorized_user_credentials.rb +34 -0
- data/lib/embulk/output/google_sheets_ruby.rb +17 -8
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 500291acae92860089b343c2e66eb086486618f7
|
4
|
+
data.tar.gz: 13410dd78807a8c274077e8bdb08993617d2c657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19e4bc6ffcf5d5a9f0e7d2e36361eb94a207242bd54338c9508ab293160b4832f1453dd8a7f2fc68438e795789c469eed8e3aa5659ed49a66914bd30a2a2278
|
7
|
+
data.tar.gz: 1b1944d8bec7627980219198bb36d8ceea9aabb96e32b6200edce8fb3d96017d2cb079711a77310c7580c6d1368583292b8fd7378a4ebf27abe66907cd0b0c15
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,15 +4,46 @@ Dumps records to Google Sheets.
|
|
4
4
|
|
5
5
|
## Overview
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
- **Plugin type**: output
|
8
|
+
- **Load all or nothing**: yes
|
9
|
+
- **Resume supported**: no
|
10
|
+
- **Cleanup supported**: no
|
11
11
|
|
12
12
|
## Configuration
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
| name | type | requirement | default | description |
|
15
|
+
| :--------------- | :----- | :---------- | :------------------- | :------------------------------------- |
|
16
|
+
| spreadsheet_id | string | required | | |
|
17
|
+
| credentials_path | string | optional | `"credentials.json"` | keyfile path |
|
18
|
+
| range | string | optional | `"A1"` | |
|
19
|
+
| auth_method | string | optional | `service_account` | `service_account` or `authorized_user` |
|
20
|
+
|
21
|
+
##### about credentials_path
|
22
|
+
|
23
|
+
- if `auth_method` is `service_account`, set the service account credential json file path.
|
24
|
+
- if `auth_method` is `authorized_user`, this plugin supposes the format is the below.
|
25
|
+
https://github.com/medjed/embulk-input-google_spreadsheets#prepare-json-file-for-auth_method-authorized_user
|
26
|
+
|
27
|
+
```json
|
28
|
+
{
|
29
|
+
"client_id": "xxxxxxxxxxx.apps.googleusercontent.com",
|
30
|
+
"client_secret": "xxxxxxxxxxx",
|
31
|
+
"refresh_token": "xxxxxxxxxxx"
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
## Prepare JSON file for auth_method: authorized_user
|
36
|
+
|
37
|
+
You may use [example/setup_authorized_user_credentials.rb](example/setup_authorized_user_credentials.rb) to prepare OAuth token.
|
38
|
+
|
39
|
+
Go to GCP console > API Manager > Credentials > Create 'OAuth Client ID'. Get the client id and client secret.
|
40
|
+
|
41
|
+
Run `setup_authorized_user_credentials.rb` to get `refresh_token`.
|
42
|
+
|
43
|
+
```
|
44
|
+
bundle --path vendor/bundle
|
45
|
+
bundle exec ruby example/setup_authorized_user_credentials.rb
|
46
|
+
```
|
16
47
|
|
17
48
|
## Example
|
18
49
|
|
@@ -24,6 +55,18 @@ out:
|
|
24
55
|
range: A1
|
25
56
|
```
|
26
57
|
|
58
|
+
## Prepare JSON file for auth_method: authorized_user
|
59
|
+
|
60
|
+
You may use [example/setup_authorized_user_credentials.rb](example/setup_authorized_user_credentials.rb) to prepare OAuth token.
|
61
|
+
|
62
|
+
Go to GCP console > API Manager > Credentials > Create 'OAuth Client ID'. Get the client id and client secret.
|
63
|
+
|
64
|
+
Run `setup_authorized_user_credentials.rb` to get `refresh_token`.
|
65
|
+
|
66
|
+
```
|
67
|
+
bundle --path vendor/bundle
|
68
|
+
bundle exec ruby example/setup_authorized_user_credentials.rb
|
69
|
+
```
|
27
70
|
|
28
71
|
## Build
|
29
72
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = 'embulk-output-google_sheets_ruby'
|
4
|
-
spec.version = '0.1.
|
4
|
+
spec.version = '0.1.1'
|
5
5
|
spec.authors = ['ariarijp']
|
6
6
|
spec.summary = 'Google Sheets Ruby output plugin for Embulk'
|
7
7
|
spec.description = 'Dumps records to Google Sheets.'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'googleauth'
|
2
|
+
require 'google/apis/sheets_v4'
|
3
|
+
require 'highline/import'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
puts 'Before setup, open this page https://developers.google.com/identity/protocols/OAuth2'
|
7
|
+
puts 'then get OAuth 2.0 credentials such as a client ID and client secret according to the above page.'
|
8
|
+
puts
|
9
|
+
|
10
|
+
credentials = Google::Auth::UserRefreshCredentials.new(
|
11
|
+
client_id: ask('Enter client_id: '),
|
12
|
+
client_secret: ask('Enter client_secret: '),
|
13
|
+
scope: Google::Apis::SheetsV4::AUTH_SPREADSHEETS,
|
14
|
+
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob'
|
15
|
+
)
|
16
|
+
|
17
|
+
credentials.code = ask(
|
18
|
+
"1. Open this page '#{credentials.authorization_uri.to_s}'.\n" \
|
19
|
+
'2. Enter the authorization code shown in the page: '
|
20
|
+
) {|q| q.echo = false}
|
21
|
+
|
22
|
+
credentials.fetch_access_token!
|
23
|
+
|
24
|
+
data = {
|
25
|
+
client_id: credentials.client_id,
|
26
|
+
client_secret: credentials.client_secret,
|
27
|
+
refresh_token: credentials.refresh_token,
|
28
|
+
}.to_json
|
29
|
+
file = File.expand_path('authorized_user_credentials.json', __dir__)
|
30
|
+
File.open(file, 'w') do |f|
|
31
|
+
f.write(data)
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "Success. See '#{file}'."
|
@@ -17,7 +17,8 @@ module Embulk
|
|
17
17
|
'range' => config.param('range', :string, default: 'A1'),
|
18
18
|
'credentials_path' => config.param('credentials_path',
|
19
19
|
:string,
|
20
|
-
default: 'credentials.json')
|
20
|
+
default: 'credentials.json'),
|
21
|
+
'auth_method' => config.param('auth_method', :string, default: 'service_account')
|
21
22
|
}
|
22
23
|
|
23
24
|
yield(task)
|
@@ -29,6 +30,7 @@ module Embulk
|
|
29
30
|
@spreadsheet_id = task['spreadsheet_id']
|
30
31
|
@credentials_path = task['credentials_path']
|
31
32
|
@range = task['range']
|
33
|
+
@auth_method = task['auth_method']
|
32
34
|
@rows = []
|
33
35
|
@rows << schema.map(&:name)
|
34
36
|
|
@@ -55,13 +57,20 @@ module Embulk
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def authorize
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
case @auth_method
|
61
|
+
when 'service_account'
|
62
|
+
return Google::Auth::ServiceAccountCredentials.make_creds(
|
63
|
+
json_key_io: File.open(@credentials_path),
|
64
|
+
scope: SCOPE
|
65
|
+
)
|
66
|
+
when 'authorized_user'
|
67
|
+
return Google::Auth::UserRefreshCredentials.make_creds(
|
68
|
+
json_key_io: File.open(@credentials_path),
|
69
|
+
scope: SCOPE
|
70
|
+
)
|
71
|
+
else
|
72
|
+
raise ConfigError.new("Unknown auth method: #{auth_method}")
|
73
|
+
end
|
65
74
|
end
|
66
75
|
|
67
76
|
def update_sheet(value_range)
|
metadata
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-google_sheets_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ariarijp
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: google-api-client
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0.8'
|
20
|
-
|
19
|
+
name: google-api-client
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: 1.10.6
|
34
|
-
|
33
|
+
name: bundler
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.10.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: embulk
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: 0.8.39
|
48
|
-
|
47
|
+
name: embulk
|
49
48
|
prerelease: false
|
49
|
+
type: :development
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.8.39
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '10.0'
|
62
|
-
|
61
|
+
name: rake
|
63
62
|
prerelease: false
|
63
|
+
type: :development
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
@@ -80,12 +80,13 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- embulk-output-google_sheets_ruby.gemspec
|
83
|
+
- example/setup_authorized_user_credentials.rb
|
83
84
|
- lib/embulk/output/google_sheets_ruby.rb
|
84
85
|
homepage: https://github.com/ariarijp/embulk-output-google_sheets_ruby
|
85
86
|
licenses:
|
86
87
|
- MIT
|
87
88
|
metadata: {}
|
88
|
-
post_install_message:
|
89
|
+
post_install_message:
|
89
90
|
rdoc_options: []
|
90
91
|
require_paths:
|
91
92
|
- lib
|
@@ -100,9 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
|
-
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
105
|
-
signing_key:
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.6.14
|
106
|
+
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Google Sheets Ruby output plugin for Embulk
|
108
109
|
test_files: []
|