google_spreadsheet_fetcher 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google_spreadsheet_fetcher/fetcher.rb +47 -17
- data/lib/google_spreadsheet_fetcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13de044dc3ec95b8296d47bb5374e451cc6b10069b95536c560db70eeafa22d2
|
4
|
+
data.tar.gz: a95098f831784ceb09d2d9b7e36d15cb8f3e1145118a3359124edb660c978582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6155050646d3a53498c7fe12d6f435e59b8e0eff0fc6cccdc8c25ff2eaf38465409a8334ed0b08968ca208a42a46ce4a6965342cf39bc8e2f45face082eb5b5
|
7
|
+
data.tar.gz: fa6eacccacaae8c6d5a3d62dee48271c794cdc68d2470001ad97c0329e8cc642371cb61ae102667a7789bce022003e4f50e894e497af88e3297179c8f22f2ce3
|
@@ -15,34 +15,64 @@ module GoogleSpreadsheetFetcher
|
|
15
15
|
@application_name = application_name
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
#
|
19
|
+
# Fetch all rows
|
20
|
+
#
|
21
|
+
# @param [String] ranges https://developers.google.com/sheets/api/guides/concepts#a1_notation
|
22
|
+
def fetch_all_rows(range, skip: 0)
|
23
|
+
rows = service.batch_get_spreadsheet_values(@sheet_key, ranges: [range])&.value_ranges&.first&.values
|
24
|
+
return if rows.empty?
|
25
|
+
|
26
|
+
rows.slice!(0, skip)
|
27
|
+
rows
|
20
28
|
end
|
21
29
|
|
22
|
-
def
|
23
|
-
|
30
|
+
def fetch_all_rows_by_index(index, skip: 0)
|
31
|
+
sheet = sheet_by_index(index)
|
32
|
+
raise if sheet.nil?
|
33
|
+
|
34
|
+
range = "#{sheet.properties.title}!A:Z"
|
35
|
+
fetch_all_rows(range, skip: skip)
|
24
36
|
end
|
25
37
|
|
26
|
-
def
|
27
|
-
|
38
|
+
def fetch_all_rows_by_gid(gid, skip: 0)
|
39
|
+
sheet = sheet_by_gid(gid)
|
40
|
+
raise if sheet.nil?
|
41
|
+
|
42
|
+
range = "#{sheet.properties.title}!A:Z"
|
43
|
+
fetch_all_rows(range, skip: skip)
|
28
44
|
end
|
29
45
|
|
30
|
-
|
46
|
+
def fetch_all_rows_by_title(title, skip: 0)
|
47
|
+
sheet = sheet_by_title(title)
|
48
|
+
raise if sheet.nil?
|
31
49
|
|
32
|
-
|
33
|
-
|
50
|
+
range = "#{sheet.properties.title}!A:Z"
|
51
|
+
fetch_all_rows(range, skip: skip)
|
52
|
+
end
|
34
53
|
|
35
|
-
|
36
|
-
service
|
37
|
-
|
54
|
+
def service
|
55
|
+
@service ||= begin
|
56
|
+
credentials = fetch_credentials
|
38
57
|
|
39
|
-
|
58
|
+
service = Google::Apis::SheetsV4::SheetsService.new
|
59
|
+
service.authorization = credentials
|
60
|
+
service
|
61
|
+
end
|
62
|
+
end
|
40
63
|
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
private
|
65
|
+
|
66
|
+
def sheet_by_index(index)
|
67
|
+
service.get_spreadsheet(@sheet_key).sheets[index]
|
68
|
+
end
|
69
|
+
|
70
|
+
def sheet_by_gid(gid)
|
71
|
+
service.get_spreadsheet(@sheet_key).sheets.find { |s| s.properties.sheet_id == gid }
|
72
|
+
end
|
44
73
|
|
45
|
-
|
74
|
+
def sheet_by_title(title)
|
75
|
+
service.get_spreadsheet(@sheet_key).sheets.find { |s| s.properties.title == title }
|
46
76
|
end
|
47
77
|
|
48
78
|
def fetch_credentials
|