lib/Processors/GoogleSheetProcessor.rb in ZReviewTender-1.3.1 vs lib/Processors/GoogleSheetProcessor.rb in ZReviewTender-1.3.2

- old
+ new

@@ -71,10 +71,11 @@ keywordsInclude.select{ |keywordsInclude| keywordsInclude != "" }.each do |keywordInclude| filterReviews = filterReviews.select{ |review| review.body.include? keywordInclude } end end + values = [] filterReviews.each do |review| cols = [] formatValues.each do |formatValue| formatValue = formatValue.gsub("%TITLE%", review.title || "") formatValue = formatValue.gsub("%BODY%", review.body || "") @@ -87,13 +88,18 @@ formatValue = formatValue.gsub("%APPVERSION%", review.appVersion || "") formatValue = formatValue.gsub("%CREATEDDATE%", review.createdDateTimestamp.nil? ? "" : Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset).to_s) cols.append(formatValue) end - - puts "[GoogleSheetProcessor] insert #{cols} to #{sheetID}-#{sheetName}" + values.append(cols) + end - googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}:append?valueInputOption=RAW", "POST", {:values => [cols]}) + page = 1 + limit = 500 + values.each_slice(limit) do |value| + puts "[GoogleSheetProcessor] Insert rows(#{page}/#{(values.length/limit).ceil + 1}) to #{sheetID}-#{sheetName}" + page += 1 + googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}!A1:append?valueInputOption=RAW", "POST", {:values => value}) end return reviews end end \ No newline at end of file