spreadsheet_to_json 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spreadsheet_to_json.rb +17 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20579b86b447e68124afe0d5c2b155565022174d
|
4
|
+
data.tar.gz: 0d8a1b0c58519ddf3c0ed77b97fe168932e8d622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bab23c043dfa357b2f6a58367cd44fc0745377e4f9af7774a32c8682aa2d2e89fcac49d0c87d7d753b56cd63f3d151cff0ff3d87e8584543a319b7996572da7
|
7
|
+
data.tar.gz: 3692f977b977f922b24aea7ffe5d5796d62841c8a22b14eb2dd2f6e2ad1079f3574c443af1934e18a0bcbb613fa4531c2ba11ca873b2d6372390f4d705fafd33
|
data/lib/spreadsheet_to_json.rb
CHANGED
@@ -5,19 +5,27 @@ require 'json'
|
|
5
5
|
|
6
6
|
module SpreadsheetToJson
|
7
7
|
class << self
|
8
|
-
def convert_to_json(worksheet_id=0, rows=[*2..get_spreadsheet.num_rows-2], keys_row_num)
|
9
|
-
spreadsheet = get_spreadsheet(worksheet_id)
|
8
|
+
def convert_to_json(config_path, worksheet_id=0, rows=[*2..get_spreadsheet.num_rows-2], keys_row_num)
|
9
|
+
spreadsheet = get_spreadsheet(worksheet_id, config_path)
|
10
10
|
rows.collect {|row_num| construct_hash(spreadsheet, keys_row_num-2, row_num-2)}.to_json
|
11
11
|
end
|
12
12
|
|
13
|
+
def output_json_file(content, output_path)
|
14
|
+
unless File.exist?(output_path)
|
15
|
+
File.new(output_path, 'w+')
|
16
|
+
end
|
17
|
+
File.open(output_path, 'w+') {|file| file.write(content) }
|
18
|
+
end
|
19
|
+
|
13
20
|
private
|
14
|
-
def get_spreadsheet(worksheet_id=0)
|
15
|
-
session = GoogleDrive.login_with_oauth(init_auth_token)
|
16
|
-
session.spreadsheet_by_key(get_settings_from_yml['spreadsheet_key']).
|
21
|
+
def get_spreadsheet(worksheet_id=0, config_path)
|
22
|
+
session = GoogleDrive.login_with_oauth(init_auth_token(config_path))
|
23
|
+
session.spreadsheet_by_key(get_settings_from_yml(config_path)['spreadsheet_key']).
|
24
|
+
worksheets[worksheet_id]
|
17
25
|
end
|
18
26
|
|
19
|
-
def init_auth_token
|
20
|
-
config = get_settings_from_yml
|
27
|
+
def init_auth_token(config_path)
|
28
|
+
config = get_settings_from_yml(config_path)
|
21
29
|
client = OAuth2::Client.new(
|
22
30
|
config['auth']['client_id'],
|
23
31
|
config['auth']['client_secret'],
|
@@ -35,8 +43,8 @@ module SpreadsheetToJson
|
|
35
43
|
auth_token.refresh!.token
|
36
44
|
end
|
37
45
|
|
38
|
-
def get_settings_from_yml
|
39
|
-
File.open(
|
46
|
+
def get_settings_from_yml(path)
|
47
|
+
File.open(path) { |file| YAML.load(file) }
|
40
48
|
end
|
41
49
|
|
42
50
|
def construct_hash(spreadsheet, keys_row_num, row=1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreadsheet_to_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xu Jianyong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
A gem to help you convert your google spreadsheet data to json format. With this gem, you can
|