embulk-input-google_spreadsheets 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0298679088554e589d5fcf35d28052321996397b'
4
- data.tar.gz: 437d4de2a144529e3a12c734bf2742c475632c4b
3
+ metadata.gz: 9f7dd9c3e53a70bcc237da3b46ea67f2ac70c207
4
+ data.tar.gz: 8cf701fd4cfe2dbef37ea6246517382b6b01f4ec
5
5
  SHA512:
6
- metadata.gz: f92a35388a40ac64fe15dde0eab169db9471884b4e27742ee5bb98ed94f994a528f6ad57c0d7400095953ac8864ba7907c600297b5a2d3f2df27096bbbab530e
7
- data.tar.gz: 0c391fa5d167d32471d3881a77cc64012fe42a6aafa76f8a13250ef734a87d32d8aab24320db72b6b423ee2056deffc606ce2ad5f8aa9300fd591619b19f64ab
6
+ metadata.gz: 5d2ea9909f5c8f62362715916d7a2fe7096a4f2e51738b52a4573737dfa372bcb7d71dff41b15286618cfea45eee798fb08301178cc83709ca1a421d464e3d4a
7
+ data.tar.gz: 961a7934ee7b3acf93be1c9ac17265789378a54ff10fe155a07cacf0069b3ca8be9ebb35ea899b17ae60afc2323d823cef12a7af6ef6e9dd33b3cc7bb2f2034d
@@ -1,3 +1,8 @@
1
+ 1.1.0 (2017-04-18)
2
+ ==================
3
+ - New Feature: Support `value_render_option` option.
4
+ - https://github.com/medjed/embulk-input-google_spreadsheets/pull/9
5
+
1
6
  1.0.0 (2017-03-27)
2
7
  ==================
3
8
 
data/README.md CHANGED
@@ -21,6 +21,7 @@ Embulk input plugin to load records from Google Spreadsheets.
21
21
  | end_row | integer | optional | `-1` | `-1` means loading records until an empty record appears. |
22
22
  | max_fetch_rows | integer | optional | `10000` | Load data from a worksheet for each numerical value specified by this option. |
23
23
  | null_string | string | optional | `''` | Replace this value to `NULL` |
24
+ | value_render_option| string | optional | `'FORMATTED_VALUE'`| `'FORMATTED_VALUE'`, `'UNFORMATTED_VALUE'`, `'FORMULA'` are available. See [the `value_render_option` document](https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption).|
24
25
  | stop_on_invalid_record | boolean | optional | `true` | |
25
26
  | default_timestamp_format | string | optional | `'%Y-%m-%d %H:%M:%S.%N %z'` | |
26
27
  | default_timezone | string | optional | `'UTC'` | |
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'embulk-input-google_spreadsheets'
3
- spec.version = '1.0.0'
3
+ spec.version = '1.1.0'
4
4
  spec.authors = %w(Civitaspo yang-xu)
5
5
  spec.summary = 'Google Spreadsheets input plugin for Embulk'
6
6
  spec.description = 'Load records from Google Spreadsheets.'
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency 'test-unit'
20
20
  spec.add_development_dependency 'test-unit-rr'
21
21
 
22
- spec.add_dependency 'google-api-client', '>= 0.9.15'
22
+ spec.add_dependency 'google-api-client', '>= 0.11'
23
23
  spec.add_dependency 'time_with_zone'
24
24
  end
@@ -0,0 +1,15 @@
1
+ in:
2
+ type: google_spreadsheets
3
+ auth_method: authorized_user
4
+ json_keyfile: example/authorized_user_credentials.json
5
+ spreadsheets_url: https://docs.google.com/spreadsheets/d/1Cxz-LudQuhRAGZL8mBoHs6mRnpjODpyF4Rwc5UYoV1E/edit#gid=0
6
+ worksheet_title: UNFORMATTED VALUE
7
+ start_row: 2
8
+ default_timezone: Asia/Tokyo
9
+ null_string: '\N'
10
+ default_typecast: strict
11
+ value_render_option: UNFORMATTED_VALUE
12
+ columns:
13
+ - {name: _c1, type: long}
14
+ out:
15
+ type: stdout
@@ -0,0 +1,15 @@
1
+ in:
2
+ type: google_spreadsheets
3
+ auth_method: service_account
4
+ json_keyfile: example/service_account_credentials.json
5
+ spreadsheets_url: https://docs.google.com/spreadsheets/d/1Cxz-LudQuhRAGZL8mBoHs6mRnpjODpyF4Rwc5UYoV1E/edit#gid=0
6
+ worksheet_title: UNFORMATTED VALUE
7
+ start_row: 2
8
+ default_timezone: Asia/Tokyo
9
+ null_string: '\N'
10
+ default_typecast: strict
11
+ value_render_option: UNFORMATTED_VALUE
12
+ columns:
13
+ - {name: _c1, type: long}
14
+ out:
15
+ type: stdout
@@ -108,6 +108,9 @@ module Embulk
108
108
  task['start_row'] = config.param('start_row', :integer, default: 1)
109
109
  task['end_row'] = config.param('end_row', :integer, default: -1)
110
110
  task['max_fetch_rows'] = config.param('max_fetch_rows', :integer, default: 10000)
111
+ # FORMATTED_VALUE, UNFORMATTED_VALUE, FORMULA are available.
112
+ # ref. https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption
113
+ task['value_render_option'] = config.param('value_render_option', :string, default: 'FORMATTED_VALUE')
111
114
  task['null_string'] = config.param('null_string', :string, default: '')
112
115
  task['stop_on_invalid_record'] = config.param('stop_on_invalid_record', :bool, default: true)
113
116
  # columns: this option supposes an array of hash has the below structure.
@@ -79,7 +79,11 @@ module Embulk
79
79
  def empty_record?(record)
80
80
  return true unless record
81
81
  return true if record.empty?
82
- record.all?{|v| v.nil? or v.empty?}
82
+ record.all? do |v|
83
+ next true if v.nil?
84
+ next true if v.is_a?(String) and v.empty?
85
+ false
86
+ end
83
87
  end
84
88
 
85
89
  def no_limit?
@@ -7,11 +7,12 @@ module Embulk
7
7
 
8
8
  class SpreadsheetsClient
9
9
 
10
- attr_accessor :spreadsheets_url, :worksheet_title, :auth, :pager
10
+ attr_accessor :spreadsheets_url, :worksheet_title, :value_render_option, :auth, :pager
11
11
 
12
12
  def initialize(task, auth:, pager:)
13
13
  @spreadsheets_url = task['spreadsheets_url']
14
14
  @worksheet_title = task['worksheet_title']
15
+ @value_render_option = task['value_render_option']
15
16
  @auth = auth
16
17
  @pager = pager
17
18
  end
@@ -54,8 +55,11 @@ module Embulk
54
55
 
55
56
  def worksheet_values(range)
56
57
  range = "#{worksheet_title}!#{range}"
57
- logger.info { "`embulk-input-google_spreadsheets`: load data from spreadsheet: '#{spreadsheets_url}', range: '#{range}'" }
58
- service.get_spreadsheet_values(spreadsheets_id, range).values
58
+ logger.info {
59
+ "`embulk-input-google_spreadsheets`: load data from spreadsheet: '#{spreadsheets_url}'," \
60
+ " range: '#{range}', value_render_option: '#{value_render_option}'"
61
+ }
62
+ service.get_spreadsheet_values(spreadsheets_id, range, value_render_option: value_render_option).values
59
63
  end
60
64
 
61
65
  def worksheet_each_record(&block)
@@ -54,6 +54,7 @@ module Embulk
54
54
  assert_equal(-1, task['end_row'])
55
55
  assert_equal(10000, task['max_fetch_rows'])
56
56
  assert_equal('', task['null_string'])
57
+ assert_equal('FORMATTED_VALUE', task['value_render_option'])
57
58
  assert_equal(true, task['stop_on_invalid_record'])
58
59
  assert_equal('%Y-%m-%d %H:%M:%S.%N %z', task['default_timestamp_format'])
59
60
  assert_equal('UTC', task['default_timezone'])
@@ -46,7 +46,7 @@ module Embulk
46
46
  puts "'#{JSON_KEYFILE_AUTHORIZED_USER}' is not found. Skip case authorized_user"
47
47
  else
48
48
  test 'authorized_user' do
49
- omit 'Skip until closing https://github.com/medjed/embulk-input-google_spreadsheets/issues/6'
49
+ omit 'Skip until closing https://github.com/medjed/embulk-input-google_spreadsheets/issues/7'
50
50
  assert_true embulk_run(File.join(EXAMPLE_ROOT, 'config_authorized_user_emoji_worksheet.yml'))
51
51
  end
52
52
  end
@@ -55,7 +55,7 @@ module Embulk
55
55
  puts "'#{JSON_KEYFILE_SERVICE_ACCOUNT}' is not found. Skip case service_account"
56
56
  else
57
57
  test 'service_account' do
58
- omit 'Skip until closing https://github.com/medjed/embulk-input-google_spreadsheets/issues/6'
58
+ omit 'Skip until closing https://github.com/medjed/embulk-input-google_spreadsheets/issues/7'
59
59
  assert_true embulk_run(File.join(EXAMPLE_ROOT, 'config_service_account_emoji_worksheet.yml'))
60
60
  end
61
61
  end
@@ -120,6 +120,26 @@ module Embulk
120
120
  end
121
121
  end
122
122
  end
123
+
124
+ sub_test_case 'run unformatted value' do
125
+ unless File.exist?(JSON_KEYFILE_AUTHORIZED_USER)
126
+ puts "'#{JSON_KEYFILE_AUTHORIZED_USER}' is not found. Skip case authorized_user"
127
+ else
128
+ test 'authorized_user' do
129
+
130
+ assert_true embulk_run(File.join(EXAMPLE_ROOT, 'config_authorized_user_unformatted_value.yml'))
131
+ end
132
+ end
133
+
134
+ unless File.exist?(JSON_KEYFILE_SERVICE_ACCOUNT)
135
+ puts "'#{JSON_KEYFILE_SERVICE_ACCOUNT}' is not found. Skip case service_account"
136
+ else
137
+ test 'service_account' do
138
+
139
+ assert_true embulk_run(File.join(EXAMPLE_ROOT, 'config_service_account_unformatted_value.yml'))
140
+ end
141
+ end
142
+ end
123
143
  end
124
144
  end
125
145
  end
@@ -75,8 +75,6 @@ else
75
75
  end
76
76
 
77
77
  test 'multi byte worksheet title' do
78
- omit 'Skip until closing this issue https://github.com/medjed/embulk-input-google_spreadsheets/issues/6'
79
-
80
78
  assert_embulk_nothing_raised do
81
79
  client('worksheet_title' => TEST_WORKSHEET_TITLE_MULTI_BYTE).worksheet_values('A1:C1')
82
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-google_spreadsheets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-29 00:00:00.000000000 Z
12
+ date: 2017-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.9.15
103
+ version: '0.11'
104
104
  name: google-api-client
105
105
  prerelease: false
106
106
  type: :runtime
@@ -108,7 +108,7 @@ dependencies:
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 0.9.15
111
+ version: '0.11'
112
112
  - !ruby/object:Gem::Dependency
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
@@ -145,11 +145,13 @@ files:
145
145
  - example/config_authorized_user_empty_rows_appears_at_the_same_as_max_fetch_rows.yml
146
146
  - example/config_authorized_user_large_data.yml
147
147
  - example/config_authorized_user_no_data.yml
148
+ - example/config_authorized_user_unformatted_value.yml
148
149
  - example/config_service_account.yml
149
150
  - example/config_service_account_emoji_worksheet.yml
150
151
  - example/config_service_account_empty_rows_appears_at_the_same_as_max_fetch_rows.yml
151
152
  - example/config_service_account_large_data.yml
152
153
  - example/config_service_account_no_data.yml
154
+ - example/config_service_account_unformatted_value.yml
153
155
  - example/setup_authorized_user_credentials.rb
154
156
  - lib/embulk/input/google_spreadsheets.rb
155
157
  - lib/embulk/input/google_spreadsheets/auth.rb