ZReviewTender 1.3.4 → 1.3.6

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
  SHA256:
3
- metadata.gz: 1b3ef6989fc515d9162992d6b84d80c89b435496957df5321c0972b06425878e
4
- data.tar.gz: 58684ea2739c5dc7416f87932285b2004d0d29763ba0a1864a3ca9fe991d4106
3
+ metadata.gz: feb984f506b75958c72f8761516e3a2f2eb7487bebe769cb34749b5ee9b7922e
4
+ data.tar.gz: 6e27d2cf2cb46cef519dec0b5c47504bd8d3db94dc36836b5994bedb41b36a13
5
5
  SHA512:
6
- metadata.gz: 1ae62fdf0c26212d0c3f5d1ed9179fd5203be69cec5c8c4ce2301856dc32f48e66056756dcd858cb5000de1ee844a352d8e8c724cc28960baa285de206d4e6bb
7
- data.tar.gz: a40d9adf22be74e8198ecec348a838664c53703b3cede6cd808d612ae6ac1523e81efd35b33be90d1bce29bf7fe034e43a3ebebb226c9fd7abb6d7a5a4a2305d
6
+ metadata.gz: 1cc47714f9d05221d981fd09439a12ebb053e10233057b09594a1e814a5a9481842a280e613ad14ae650743e470a9d403371b3fba94b75524e1a0073ee2fc3cf
7
+ data.tar.gz: 4e67b7b958027bf74a4c0f870d26b30f77ac12da9e7b4b9cd1cde3e4a94805606bc2d9d8aab2d12194d4b8af94196882869d7ff4cc536a671eb2c3899ad3e5a9
data/.version CHANGED
@@ -1 +1 @@
1
- 1.3.4
1
+ 1.3.6
@@ -29,8 +29,11 @@ processors:
29
29
  enable: false # enable
30
30
  googleSheetAPIKeyFilePath: "" # Google Translate API Service Account Credential .json File Path
31
31
  googleSheetTimeZoneOffset: "+08:00" # Review Created Date TimeZone
32
- googleSheetID: "" # Google Sheet ID, you can get it on google sheet url: e.g. https://docs.google.com/spreadsheets/d/googleSheetID/
33
- googleSheetName: "Sheet1" # Sheet Name
32
+ googleSheetInsertStyle:
33
+ - type: "append" # Google Sheet Insert type, append or insert
34
+ - at: 0 # required if type is insert, where index should insert at
35
+ - sheetID: null # required if type is insert, the sheet ID, you can get it on google sheet url: e.g. https://docs.google.com/spreadsheets/d/googleSpreadsheetID/edit#gid=sheetID
36
+ - sheetName: "Sheet1" # required if type is append, a.k.a google sheet tab name
34
37
  values: ["%RATING%","%TITLE%\n%BODY%","%APPVERSION%","%CREATEDDATE%"] # Columns Data, you can uses magic variable below to compose string.
35
38
  # %TITLE% for review's title
36
39
  # %BODY% for review's content
@@ -29,8 +29,12 @@ processors:
29
29
  enable: false # enable
30
30
  googleSheetAPIKeyFilePath: "" # Google Translate API Service Account Credential .json File Path
31
31
  googleSheetTimeZoneOffset: "+08:00" # Review Created Date TimeZone
32
- googleSheetID: "" # Google Sheet ID, you can get it on google sheet url: e.g. https://docs.google.com/spreadsheets/d/googleSheetID/
33
- googleSheetName: "Sheet1" # Sheet Name
32
+ googleSpreadsheetID: "1_lc82p-epecVKwpUWlXh1yyNWaSrygzDb8I0QH2xkTI" # Google Sheet SpreadSheet ID, you can get it on google sheet url: e.g. https://docs.google.com/spreadsheets/d/googleSpreadsheetID/
33
+ googleSheetInsertStyle:
34
+ - type: "append" # Google Sheet Insert type, append or insert
35
+ - at: 0 # required if type is insert, where index should insert at
36
+ - sheetID: null # required if type is insert, the sheet ID, you can get it on google sheet url: e.g. https://docs.google.com/spreadsheets/d/googleSpreadsheetID/edit#gid=sheetID
37
+ - sheetName: "Sheet1" # required if type is append, a.k.a google sheet tab name
34
38
  values: ["%RATING%","%TITLE%\n%BODY%","%APPVERSION%","%CREATEDDATE%"] # Columns Data, you can uses magic variable below to compose string.
35
39
  # %TITLE% for review's title
36
40
  # %BODY% for review's content
@@ -136,8 +136,9 @@ class AndroidFetcher < ReviewFetcher
136
136
 
137
137
 
138
138
  # init first time, send welcome message
139
- if latestCheckTimestamp == 0
139
+ if latestCheckTimestamp == 0 && isSentWelcomeMessage() == false
140
140
  sendWelcomMessage()
141
+ setSentWelcomeMessage()
141
142
  elsif reviews.length > 0
142
143
  processReviews(reviews, platform)
143
144
  end
data/lib/AppleFetcher.rb CHANGED
@@ -38,8 +38,9 @@ class AppleFetcher < ReviewFetcher
38
38
  end
39
39
 
40
40
  # init first time, send welcome message
41
- if latestCheckTimestamp == 0
41
+ if latestCheckTimestamp == 0 && isSentWelcomeMessage() == false
42
42
  sendWelcomMessage()
43
+ setSentWelcomeMessage()
43
44
  elsif reviews.length > 0
44
45
  reviews = fullfillAppInfo(reviews)
45
46
  processReviews(reviews, platform)
@@ -31,6 +31,17 @@ class ReviewFetcher
31
31
  end
32
32
  end
33
33
 
34
+ def setSentWelcomeMessage()
35
+ basePath = "#{config.baseExecutePath}/latestCheckTimestamp/"
36
+ Helper.createDirIfNotExist(basePath)
37
+ File.open("#{basePath}/#{platform}Welcome", 'w') { |file| file.write("") }
38
+ end
39
+
40
+ def isSentWelcomeMessage()
41
+ filePath = "#{config.baseExecutePath}/latestCheckTimestamp/#{platform}Welcome"
42
+ return File.exists?(filePath)
43
+ end
44
+
34
45
  def setPlatformLatestCheckTimestamp(timestamp)
35
46
  basePath = "#{config.baseExecutePath}/latestCheckTimestamp/"
36
47
  Helper.createDirIfNotExist(basePath)
@@ -8,7 +8,7 @@ require "GoogleAPI"
8
8
 
9
9
  class GoogleSheetProcessor < Processor
10
10
 
11
- attr_accessor :keywordsInclude, :ratingsInclude, :territoriesInclude, :logger, :googleAPI, :sheetID, :sheetName, :formatValues, :timeZoneOffset
11
+ attr_accessor :keywordsInclude, :ratingsInclude, :territoriesInclude, :logger, :googleAPI, :spreadsheetID, :sheetInsertType, :sheetId, :sheetName, :sheetInsertAt, :formatValues, :timeZoneOffset
12
12
 
13
13
  def initialize(config, configFilePath, baseExecutePath)
14
14
  @config = config
@@ -41,8 +41,31 @@ class GoogleSheetProcessor < Processor
41
41
  end
42
42
 
43
43
  @timeZoneOffset = Helper.unwrapRequiredParameter(config, "googleSheetTimeZoneOffset")
44
- @sheetID = Helper.unwrapRequiredParameter(config, "googleSheetID")
45
- @sheetName = Helper.unwrapRequiredParameter(config, "googleSheetName")
44
+ @spreadsheetID = Helper.unwrapRequiredParameter(config, "googleSpreadsheetID")
45
+
46
+ sheetInsertStyle = Helper.unwrapRequiredParameter(config, "googleSheetInsertStyle")
47
+ if !sheetInsertStyle.is_a? Array
48
+ raise "googleSheetInsertStyle must specify as Array in GoogleSheetProcessor."
49
+ end
50
+
51
+ sheetInsertStyles = {}
52
+ sheetInsertStyle.each do |value|
53
+ value.keys.each do |key|
54
+ sheetInsertStyles[key] = value[key]
55
+ end
56
+ end
57
+
58
+ @sheetInsertType = Helper.unwrapRequiredParameter(sheetInsertStyles, "type")
59
+
60
+ if sheetInsertType != "insert" && sheetInsertType != "append"
61
+ raise "googleSheetInsertStyle.type only accept insert or append in GoogleSheetProcessor."
62
+ elsif sheetInsertType == "insert"
63
+ @sheetInsertAt = Helper.unwrapRequiredParameter(sheetInsertStyles, "at").to_i
64
+ @sheetId = Helper.unwrapRequiredParameter(sheetInsertStyles, "sheetID")
65
+ elsif sheetInsertType == "append"
66
+ @sheetName = Helper.unwrapRequiredParameter(sheetInsertStyles, "sheetName")
67
+ end
68
+
46
69
  @formatValues = []
47
70
  if !config["values"].nil?
48
71
  @formatValues = config["values"]
@@ -74,7 +97,12 @@ class GoogleSheetProcessor < Processor
74
97
  end
75
98
 
76
99
  values = []
77
- filterReviews.each do |review|
100
+ sortedFilterReviews = filterReviews
101
+ if sheetInsertType == "insert"
102
+ sortedFilterReviews = sortedFilterReviews.sort! { |a, b| b.createdDateTimestamp <=> a.createdDateTimestamp }
103
+ end
104
+
105
+ sortedFilterReviews.each do |review|
78
106
  cols = []
79
107
  formatValues.each do |formatValue|
80
108
  formatValue = formatValue.gsub("%TITLE%", review.title || "")
@@ -94,13 +122,53 @@ class GoogleSheetProcessor < Processor
94
122
  end
95
123
 
96
124
  page = 1
97
- limit = 500
125
+ limit = 100
98
126
  values.each_slice(limit) do |value|
99
- puts "[GoogleSheetProcessor] Insert rows(#{page}/#{(values.length/limit).ceil + 1}) to #{sheetID}-#{sheetName}"
127
+ puts "[GoogleSheetProcessor] Insert rows page:(#{page}/#{(values.length/limit).ceil + 1}) #{sheetInsertType} to #{spreadsheetID}"
100
128
  page += 1
101
- googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}!A1:append?valueInputOption=RAW", "POST", {:values => value})
129
+ if sheetInsertType == "insert"
130
+ googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{spreadsheetID}:batchUpdate", "POST", {
131
+ "requests": [
132
+ {
133
+ "insertRange": {
134
+ "range": {
135
+ "sheetId": sheetId,
136
+ "startRowIndex": sheetInsertAt,
137
+ "endRowIndex": sheetInsertAt + value.length
138
+ },
139
+ "shiftDimension": "ROWS"
140
+ }
141
+ },
142
+ {
143
+ "pasteData": {
144
+ "data": rowsToString(value),
145
+ "type": "PASTE_NORMAL",
146
+ "delimiter": ",",
147
+ "coordinate": {
148
+ "sheetId": sheetId,
149
+ "rowIndex": sheetInsertAt,
150
+ }
151
+ }
152
+ }
153
+ ]
154
+ })
155
+ elsif sheetInsertType == "append"
156
+ googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{spreadsheetID}/values/#{sheetName}!A1:append?valueInputOption=RAW", "POST", {:values => value})
157
+ end
102
158
  end
103
159
 
104
160
  return reviews
105
161
  end
162
+
163
+ private
164
+ def rowsToString(rows)
165
+ string = ""
166
+ rows.each do |row|
167
+ if string != ""
168
+ string += "\n"
169
+ end
170
+ string += "\"#{row.map{ |v| v.gsub('"','\"') }.join('","')}\""
171
+ end
172
+ return string
173
+ end
106
174
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZReviewTender
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http